Game Development Community

Camera Rotation T2D / TGB

by Volkan Arman · in Torque Game Builder · 03/19/2011 (6:47 am) · 2 replies

non-existance of camera rotation is unthinkable, I want to make the stuff in 2D engine and everything was just perfect till I hit this wall,

I tried several work arounds in the source code, including turning the "world" relatively to the player pivot which returned inconsistent results.

Now I have the dig deeper in to C++ code, which is far more complex and TIME CONSUMING

Window area is bound to RectF, and as far as I see its irrotatable, and when I set four points instead of RectF, I crash into to newer problems, which are getting far worse without a referance document.

What does (const RectF& cameraWindow) mean? why "&" ? will it work once I change all the RectF referances with four points of the rectangle?

Well it didnt work for me, even re-positioning sprites thru affecting Spatial Updates ended with highly inconsistent results. Some of the objects worked as I wanted, and some did as if I didnt code anything... and they are "ForwardMovementOnly" objects... I cant even get readings from the code, how? should I use Con::Warn??

I'd really appreciate some help on rotating the camera,

and Ive read all the stuff upon this, I tried the one Blikstad proposed earlier,

Thanks in advance,


About the author

Recent Threads


#1
03/20/2011 (3:19 am)
I think I found it.... :) well my appreciation goes to Magnus Blikstad,

my addition will help users on two things,

1st, to use "setCameraAngle" & "getCameraAngle" function,
2nd, to reduce & vanish screen vibration on curves, e.g. if your craft is turning sharply, rotating screen vibrates due to 32ms update intervals,

Just missing one thing, which is loosing objects on corners due to screen area coverage, I will add the solution as soon as I implement it..


t2dSceneWindow.h (find the given comments, and add the code right under it)
/// Camera Accessors.
F32 getCurrentCameraAngle( void ) const						{ return mCameraCurrent.mCameraAngle; };//ARMAN

/// Current Camera,
void setCurrentCameraAngle( F32 CameraAngle ); // ARMAN

/// Target Camera.
void setTargetCameraAngle( F32 CameraAngle ); // ARMAN

t2dSceneWindow.cc[i]
//-----------------------------------------------------------------------------
		// Set Current Camera Angle. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		//-----------------------------------------------------------------------------
		ConsoleMethod(t2dSceneWindow, setCurrentCameraAngle, void, 3, 3, "(CameraAngle) - Set current camera Zoom Factor.n"
					  "@param zoomFactor A float value representing the zoom factorn"
					  "@return No return value.")
		{
			// Set Current Camera Zoom.
			object->setCurrentCameraAngle( dAtof(argv[2]) );
		}
		// Set Current Camera Zoom.
		void t2dSceneWindow::setCurrentCameraAngle( F32 CameraAngle )
		{
			// Stop Camera Move ( if any ).
			if ( mMovingCamera ) stopCameraMove();

			// Set Camera Target.
			mCameraCurrent.mCameraAngle = CameraAngle;

			// Set Camera Target to Current.
			mCameraTarget = mCameraCurrent;
		}


		//-----------------------------------------------------------------------------
		// Get Current Camera Angle.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		//-----------------------------------------------------------------------------
		ConsoleMethod(t2dSceneWindow, getCurrentCameraAngle, F32, 2, 2, "() Get current camera Zoom.n"
					  "@return Returns the camera zoom factor as a 32-bit floating point value.")
		{
			// Get Current Camera Zoom.
			return object->getCurrentCameraAngle();
		}

Next thing is applying Blikstad's patch;
www.garagegames.com/community/forums/viewthread/29015

or in t2dSceneWindow.cc go to line 2915 (after adding previous mentioned lines), right above the // Setup new viewport. add this;

// blikstad: translate to 0,0,0, rotate, translate back.  
		t2dVector camPos = getCurrentCameraPosition();  
		glTranslatef(camPos.mX, camPos.mY, 0);  
		glRotatef (mCameraCurrent.mCameraAngle,0,0,1);  
		glTranslatef(-camPos.mX, -camPos.mY, 0);   
		//

Now we are done with the Source Code, fire up the Torsion or your scripting application,

Define these variables first,
$gfxspeed   = 32;  //32ms for physics updates
   $Renderitt  = 1;   //Blocks within 32ms, initial value so it must be 1,
   $Tick       = 4;   //ms intervals between updates, I use 1 for max effect 
   $TickItt    = $gfxspeed / $Tick; // e.g. 32ms / 4 = 8 blocks between 32ms update cycles

Now all you need to bind it to a schedule loop, here is my example,

function SRP()
{
         sceneWindow2D.mount($PlayerCraft,0,-4, false);
         LoopRelativePositioning();
         LoopArcSmooth();
 }
function LoopRelativePositioning()  
{  
   if($inMatch)  
   {  
   SET(); 
   schedule($gfxspeed, 0, LoopRelativePositioning);
   }  
}
function LoopArcSmooth()  
{  
   if($inMatch)  
   {  
   ARC(); 
   schedule($Tick, 0, LoopArcSmooth); //e.g. per 4ms
   }  
} 
function SET(%Rot)
{
   //AngularVelocity is 1 unit equals to 0,032 degree per 32ms tick interval, so 1/1000 degree per ms
   $AngleVel = $PlayerCraft.getAngularVelocity() / 1000; //e.g. 0,01 degree / ms
   $AngleCur = $PlayerCraft.getRotation(); // e.g. 30 degrees
}
function ARC()
{
   if($Renderitt > $TickItt) {$Renderitt = 1;} // Loop between 1 tru Tickitt(8),
   $Arc = $AngleCur + (($AngleVel * $Tick) * $Renderitt);
   //eg.     30'    + ((0,01' * 4 = 0,04) *  8th )= 30,32 degree 
   //eg.     30'    + ((0,01' * 2 = 0,02) *  16th)= 30,32 degree     
   %Rot = $Arc * -1;
   sceneWindow2D.setCurrentCameraAngle(%Rot);
   $Renderitt++; // for X render intervals
}

now just use SRP() on console to start the show,
#2
10/17/2011 (5:51 pm)
This looks sweet, so doing this actually get's screen rotation into the game? I desperately need this. Any chance that you have a demo video to show the awesomeness? I'm not looking forward to getting into the source but if the results are great then I'm game!
Thanks friend!
-nic