# Rotate a point in 3D space with sine and cosine

I got my camera controlled by the mouse. Now I want a sphere to be always in the center of my view(just for testing). I tried that by assigning the sine of the Y rotation of the camera times 10 as the X coordinate and the same for the Y coordinate but with cosine:

SphereX = 10 * math.sin(YRotation)
SphereY = 10 * math.cos(YRotation)


But now I would like to know how to set the Z position. I can set the proper height of the sphere by doing that:

SphereZ = 10 * math.sin(XRotation)


But the problem is, that the sphere is only moving up and down and the moving towards the camera is ignored. How can I fix that?

• You want the sphere to be in front of the camera, at a constant distance no matter where you move the camera? Or you want to do something like orbiting the sphere and being able to zoom in and out on it? Aug 8, 2013 at 23:01
• The first one. :D
– RenX
Aug 8, 2013 at 23:03
• Are you set on using sine and cosine? Might be easier with matrices: gamedev.stackexchange.com/questions/11594 Aug 8, 2013 at 23:20
• Actually I just want the direction the camera is looking at. I wanted to solve that by calculating a kind of a target.
– RenX
Aug 8, 2013 at 23:26
• Got it working. The camera direction is the negative of the third row of the viewing matrix.
– RenX
Aug 8, 2013 at 23:58