0

I'm trying to implement an easy and intuitive way to control the camera direction, in an application I built using JavaFX 8 + 3D. In OpenGL, there is a simple function, named gluLookAt(), which enables to easily define from which point to look and to which destination point to look.

Is there something equivalent in JavaFX-3D?

SomethingSomething
  • 11,491
  • 17
  • 68
  • 126

2 Answers2

0

This answer from the OpenJDK mailing list may be helpfull for you. lookAt

mipa
  • 10,369
  • 2
  • 16
  • 35
0

Found this code snippet here: https://community.oracle.com/thread/3868043

I'm copying the code to here to make sure it's available in the future. Didn't test it, need to make sure it works well:

public void lookAt(Point3D cameraPosition, Point3D lookAtPos) {          
    //Create direction vector  
    Point3D camDirection = lookAtPos.subtract(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());  
    camDirection = camDirection.normalize();  

    double xRotation = Math.toDegrees(Math.asin(-camDirection.getY()));  
    double yRotation =  Math.toDegrees(Math.atan2( camDirection.getX(), camDirection.getZ()));  

    Rotate rx = new Rotate(xRotation, cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ(), Rotate.X_AXIS);  
    Rotate ry = new Rotate(yRotation, cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ(),  Rotate.Y_AXIS);  

    cam.getTransforms().addAll( ry, rx,   
            new Translate(  
                    cameraPosition.getX(),   
                    cameraPosition.getY(),   
                    cameraPosition.getZ()));  
}  
SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
  • Here there is another implementation that takes into account also other parameters: https://github.com/lancelet/orbitnav/blob/master/src/main/java/org/orbitnav/example/LookAt.java – SomethingSomething Aug 30 '16 at 07:43