I have a simple mesh that when you press the up arrow, the velocity is increased and vice versa. To turn the mesh I have a double value that I use as the angle that the mesh is facing. When the left or right arrow is pressed this value is increased/decreased by 5 and I check to make sure it doesn't go below 0 or above 360. To calculate the x and y coords for the turn I use the following:
mypos.Y += (float)(Math.Sin((mydir*Math.PI/180)) * myvelocity);
mypos.X += (float)(Math.Cos((mydir*Math.PI/180)) * myvelocity);
My problem is making the camera always stay behind the ball. I'm not a math wiz but this has me very stumped. Any idea It seems that I would increase/decrease the values of camera position while doing it to the mesh position but I haven't found anything that works.

Camera Following Problem
RaptorTech
Sorry about that, my problem is with turning the camera.
The code for turning the object works great, I just need to have the camera always follow the ball right behind it. For example, if the direction the ball is facing is 135 degrees, the y position is increased by Sin(135) * the velocity and the x is increased by Cos(135) * the velocity. My problem is getting the camera to move its position where it is oriented behind the ball. Using the above example, if I had a velocity of 1, the y would be .707 greater and the x would .707 less. So the coords would (-.707 and .707). I need the camera to be behind it. The camera would need to increase both its x and y values to position itself behind, so I figured if I took the angle of the ball and subtracted 90 degrees it would work, b/c it should be (.707,.707) but it doesn't seem to work.
n8dagr8
If you have the World Matrix to place your man
you can use this local World Referential to get the 3D point behind your man
in the Global World
D3DXVECTOR3 VectorPositionLocal(-5,0,0);
VectorPositionWorld=D3DXMatrixTransform(&MatrixWorldLocal,VectorPositionLocal)
Then use this VectorPositionWorld in the Lookat function
When you place an object with a World Matrix it's a Local Referential
You can place a Vertex in it's local referential, here at -5 in X
So if your man is facing the X positive this position is behind him...
To get this position in World Coordinate you use transform with the MatrixWorld
You will end up with the position behind him in the local referential
But in the World Coordinate to be use by your camera Lookat function
You can place anything you want in the referential of the man who move around
and get it's world coordinate with the function I gave you above
No need for any angle and sin, cos calculus...
The World Local Referential will be rotated and so the position -5 in x will rotate in Global Coordinate
The previous post tell this > Check out Vector3.Transform if I'm not mistaken.
I think it's probably this function in managed...
Ren Yi
Can you be more specific... What is suposed to turn The cam or the mesh And turn how
Hossam Abdel Wahab
I'm still not sure I understand what you are trying to do.
If you are trying a "chace" effect (for example the camera has a constant distance to the object and always looking in the direction of movment and little above.... a 3rd player view) than you need to modify both the camera pposition and the "LookAt" vector as well.
If you are trying to turn the camera around the object, always looking at the object than you have to modify the position.
Good thing about an IDE is that most of the times it gives you the meanings to acomplish what you want without you having to "do the math" in this case. Check out Vector3.Transform if I'm not mistaken.