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?

  • \$\begingroup\$ 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? \$\endgroup\$
    – House
    Aug 8, 2013 at 23:01
  • \$\begingroup\$ The first one. :D \$\endgroup\$
    – RenX
    Aug 8, 2013 at 23:03
  • 1
    \$\begingroup\$ Are you set on using sine and cosine? Might be easier with matrices: gamedev.stackexchange.com/questions/11594 \$\endgroup\$
    – House
    Aug 8, 2013 at 23:20
  • \$\begingroup\$ Actually I just want the direction the camera is looking at. I wanted to solve that by calculating a kind of a target. \$\endgroup\$
    – RenX
    Aug 8, 2013 at 23:26
  • \$\begingroup\$ Got it working. The camera direction is the negative of the third row of the viewing matrix. \$\endgroup\$
    – RenX
    Aug 8, 2013 at 23:58


You must log in to answer this question.

Browse other questions tagged .