jimmer24
Community Member

Posts: 2
|
 |
« on: January 23, 2008, 07:47:02 PM » |
|
Hi all. Im just tryin to rotate a mesh centerd on my viewpoint. Is ATan2 the right way to do this? im not that good at math so i guess its basicly a math question. Any help?
// Update the vectors using the angles and positions. sngPositionX = sngPositionX + (float)(System.Math.Cos((double)sngAngleY) * sngWalk / 5 * TV8.TimeElapsed()) + (float)(System.Math.Cos((double)sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV8.TimeElapsed()); sngPositionZ = sngPositionZ + (float)(System.Math.Sin((double)sngAngleY) * sngWalk / 5 * TV8.TimeElapsed()) + (float)(System.Math.Sin((double)sngAngleY + 3.141596 / 2) * sngStrafe / 5 * TV8.TimeElapsed()); // New : because we are using a landscape with up and down, we // can't let the camera at the same height. We want the camera to // follow the height of the map, so we use the "get height". Also, // because we want to have the effect that we are not a mouse, // we will add some height to the height returned... sngPositionY = Land.GetHeight(sngPositionX, sngPositionZ) + 10; // We update the look at position. snglookatX = sngPositionX + (float)System.Math.Cos((double)sngAngleY); snglookatY = sngPositionY + (float)System.Math.Tan((double)sngAngleX); snglookatZ = sngPositionZ + (float)System.Math.Sin((double)sngAngleY);
// With the new values of the camera vectors (position and // look at), we update the scene's camera. Scene.SetCamera (sngPositionX, sngPositionY, sngPositionZ, snglookatX, snglookatY, snglookatZ);
>> //put a mesh where im standing >> mesh.SetPosition(sngPositionX, sngPositionY , sngPositionZ); >> //find angle??? >> xangle = tvmath.ATan2(sngPositionX - snglookatX, snglookatY - sngPositionY) * 180 / tvmath.PI_; >> //rotate >> mesh.SetRotation((float)xangel, 0, 0); }
Jim
|