Wow 3D Style Cam Need Help!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
digoxy
Posts: 51
Joined: Wed Feb 17, 2010 3:55 pm
Location: Currently Germany.

Wow 3D Style Cam Need Help!

Post by digoxy »

Hello!

I am currently using the wow style cam from the snipits area:

am looking for a way to rotate the toon and cam using the A and D keys. It seems I am missing something here and dont fully understand what this is doing to move. Can someone help understand this or, possibly help me come to a solution?

As it is right now, to move forward, using the W key it looks like this:

Code: Select all

	if(keys[KEY_KEY_W])
								  { 
								 // player movement vector 
								 vector3df playerStep = sphericalXYZ(cameraOrbit,0,playerMoveSpeed * frameDeltaTime); 
								 playerX -= playerStep.X; 
								 playerY -= playerStep.Y; 
								 playerZ -= playerStep.Z; 
								 // player rotation.
							 	 playerTurnTo = cameraOrbit - 90;
								 if(playerTurnTo < 0) playerTurnTo += 360;
								 if(playerTurnTo >= 360) playerTurnTo -= 360;
								 if(playerCompass < 0) playerCompass = playerCompass + 360;
								 if(playerCompass >= 360) playerCompass = playerCompass - 360; 
								 f32 playerTurnDir = 0; 
								 f32 playerTurnDelta = 0; 
								 if(playerCompass > playerTurnTo) 
									 { 
										if(playerCompass - playerTurnTo < 180){ 
										   playerTurnDir = -1; 
										   playerTurnDelta = playerCompass - playerTurnTo; 
										} else { 
										   playerTurnDir = 1; 
										   playerTurnDelta = (360 - playerCompass) + playerTurnTo; 
										} 
									 } 
								 if(playerCompass < playerTurnTo) 
									 { 
										if(playerTurnTo - playerCompass < 180){ 
										   playerTurnDir = 1; 
										   playerTurnDelta = playerTurnTo - playerCompass; 
										} else { 
										   playerTurnDir = -1; 
										   playerTurnDelta = (360 - playerTurnTo) + playerCompass; 
										} 
									 } 
								 f32 playerTurnAmount; 
								 if(playerTurnDelta < playerTurnSpeed)
								 { 
										playerTurnAmount = playerTurnDelta; 
									 } else { 
										playerTurnAmount = playerTurnSpeed; 
								 }

								playerCompass += (playerTurnAmount * playerTurnDir); 
								cPivot1 ->setPosition(vector3df(playerX,playerY,playerZ)); 
								cPivot2->setRotation(vector3df(0,playerCompass-90,0)); 

								vector3df pos = cPivot1->getPosition();
								f32 height = terrain->getHeight(pos);
								pos.Y = height + 12; 
								cPivot1 ->setPosition(vector3df(pos.X, pos.Y, pos.Z)); 
								cam->setTarget(vector3df(pos.X, pos.Y, pos.Z)); 
														}//end if keys W
its using this to rotate the cam:

Code: Select all

vector3df sphericalXYZ(f32 compassAngle, f32 elevationAngle, f32 radius){ 

   compassAngle = compassAngle * -1; 
   elevationAngle = elevationAngle * -1; 

   elevationAngle = elevationAngle + 90; 

   f32 x = radius * cos(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f ); 
   f32 z = radius * sin(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f ); 
   f32 y = radius * cos(elevationAngle * PI/180.0f ); 

   vector3df result; 
   result.X = x; 
   result.Y = y; 
   result.Z = z; 
   return result; 
} 
It may be this is a simple answer, I am not sure. I have not worked on this project in several months and have forgotten more about it than I probably ever knew! :)

I did figure the reverse of this (to move backwards) using the S key I simply modified the player like this.

Code: Select all

playerX += playerStep.X; 
playerY += playerStep.Y; 
playerZ += playerStep.Z; 
The original code snippit thred is located here:
http://irrlicht.sourceforge.net/phpBB2/ ... hericalxyz

Is this 3d cam still one of the best solutions out there or, is there something else that may work better for a wow style world?
Grandma-- / Grandpa --
Post Reply