Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help Me Develop A 3D Camera "LookAt" Method

gcolelloDec 14 2014 — edited Dec 14 2014

I am doing JavaFX 3D programming in Java8...


As a grissled veteran, having lived through innumerable software demises, I am so grateful that Oracle adopted Java and has now integrated 3D into Java's production libraries, rather than 3D just being a public domain "add-on". But being a mere mortal, I depend on certain utilities being in existence, so that I don't have to know so much. One critical utility that appears to be missing from JavaFX 3D is what is generally termed the camera "LookAt" method. When a user moves the perspective camera in JavaFX 3D space, either by continuous mouse actions or by naming an object somewhere to jump to and focus on, the camera needs to automatically rotate, using the JavaFX Rotation object, to get it to point at (LookAt) a program-specified 3D point in the scene. Note here that most camera movements will require both translations and rotations along and around the [x,y,z] axes in order to produce a meaningful viewing experience for the user. Translations are reasonably straightforward to understand, but the corresponding rotation-angles algorithm turns out to be non-trivial.

I have studied what there is on the internet on this problem (Euler angles, Matrices, Quanterions, etc); but my JavaFX context is not quite the same as I see described there, and subtle differences matter with 3D. My goal is to have my scene, which is a simulation of the universe/solarsystem/earth be accessed primarily by moving the camera around to view and then select scene objects. Complex camera movements are not demonstrated in the JavaFX tutorials, which mainly teach simple mouse and keyboard event handling that rotates the entire SCENE, being located at scene center POINT = [0.0, 0.0, 0.0], in front of a static camera parked some fixed distance away down the negative z-axis (for example see MoleculeSampleApp). This approach is useful, once an object has been isolated for closer examination, but not so much for locating and selecting objects in a complex scene space.

In JavaFX 3D, as I am sure most readers are aware, the camera starts out parked at scene center, at coordinate POINT = [0.0, 0.0, 0.0], facing down the scene's z+ axis (looking into the screen) with the initial camera ROTATION-ANGLE-STATUS = [0.0, 0.0, 0.0] (i.e. no rotations as yet).

As a very easy example, if the camera were translated along the Y-axis +1000, then logically a simple +90.0 (counterclockwise) rotation around the X-axis, using the JavaFX Rotation object, should turn the camera to LookAt POINT = [0.0, 0.0, 0.0], which I have proven does in fact work. In my terminology, the resulting ROTATION-ANGLE-STATUS of the camera relative to the scene coordinate system would then be [+90.0, 0.0, 0.0].

If, as a second example, the camera were translated along the the X-axis +500.0, Y-axis +1000.0, and the Z-axis +2000.0; then unfortunately no simple camera rotation will suffice to LookAt POINT = [0.0, 0.0, 0.0]. Some kind of matrix solution is required.

*******************

GENERALLY SPEAKING, the problem I need to solve is this: If the camera has been translated to POINT = [x1, y1, z1] with current ROTATION-ANGLE-STATUS = [theta_x1, theta_y1, theta_z1]; what are the set of rotation angles [theta_x2, theta_y2, theta_z2] to pass to the JavaFX Rotation object to make the camera "LookAt" POINT = [x2, y2, z2]?

*******************

I think this is the correctly stated mathematical problem to solve for JavaFX 3D. Once this foundational method exists, it enables all sorts of useful camera movement utilities to be created around it. I already have good testbed code that I can use to test any solutions that you may help me cook up. And I promise, if you can help me solve this problem, I will publish the final camera "LookAt" method on the internet for others to use.

Greg Colello

Santa Fe, NM

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2015
Added on Dec 14 2014
0 comments
1,122 views