hoarse and buggy
stop screaming at your code

Flex, Papervision3D: Rotating a camera around a sphere

Recently I needed to write some code that would allow me to interactively rotate a camera around a Papervision3D sphere in a Flex app. My first idea was convert the (x,y,z) location of the camera to a spherical coordinate — that is (rho, phi, theta). To actually move the camera around the center of the sphere, I could just change the phi and theta angles, re-convert the spherical coordinate to a cartesian coordinate, and use this cartesian coordinate as the camera’s new position.

I messed around with approach this some, and was getting close to having it work, but then I ran across a post on the Papervision3D forums which greatly simplifies the whole operation by taking advantage of a few built-in methods to the FreeCamera3D class (here is a link to the original post):

1. Determine yAngle, the angle by which you want to rotate the camera up
2. Determine xAngle, the angle by which you want to rotate the camera right
3. Determine cameraDistance, the distance the camera is from the center of the sphere
4. Move the camera to the center of the sphere using the moveForward function: camera.moveForward(cameraDistance)
5. Tilt the camera up: camera.tilt(yAngle)
6. Pan the camera right: camera.pan(xAngle)
7. Move the camera back using the moveBackward function:
camera.moveBackward(cameraDistance)

These operations should successfully position the camera wherever you want around the outside of the sphere, and it has the benefit of being super simple.

One note: I could only get this to work with the FreeCamera3D class, not the Camera3D class.

5 Responses to “Flex, Papervision3D: Rotating a camera around a sphere”

  1. interesting approach, will try soon – project i could use that for is coming very quickly :D

  2. I love your site! :)

    _____________________
    Experiencing a slow PC recently? Fix it now!

  3. У автора очень приятный слог

  4. По моему Вам нужно чаще отдыхать, очень уж Вы заработались.

  5. Не понимаю причину такого ажиотажа. Ничего нового и мнения разные.


Leave a Reply