Sign in to follow this  

[java] Java3D unprojection

Recommended Posts

Lord_Evil    680
Hi, I have another question on Java3D. For my camera class I want to provide a screenToWorld() method that takes the mouse position and a depth and returns the corresponding world coordinates. The problem is that I can't find any proper methods/functionality in Java3D to do this. There is a getInverseVworldProjection(...) method in Canvas3D but the returned matrix seems very odd. As an example, if I transform (0,0,1) with that matrix I get something like (0, 10000, 10000) with my camera being located at (0,20,20) looking at (0,0,0) and far plane distance = 100). If the camera moves the values for y and z seem to change exponentially. I found a workaround that does the job but I'd like to have a proper calculation. The workaround is as follows:
public Point3d screenToWorld(Point2d pPoint, double pDepth) {
        //get the only canvas
        Canvas3D tCanvas3D = view.getCanvas3D(0);
        //get eye position
        Point3d tEyePos = new Point3d();
        //get the screen coords of the point
        Point3d tMouseCoords = new Point3d();
        tCanvas3D.getPixelLocationInImagePlate(pPoint, tMouseCoords);

        //project eye and screen pos to world
        Transform3D tTransform = new Transform3D();

        //create a direction vector from eye to screen with the desired length (depth * distance of far plane)  
        Vector3d tDir = new Vector3d(tMouseCoords);
        tDir.scale(pDepth * view.getBackClipDistance());
        //world pos is eye + direction vector
        Point3d tWorldCoords = new Point3d(tEyePos);

        return tWorldCoords;

Does anyone know how to correctly and efficiently unproject screen coordinates in Java3D?

Share this post

Link to post
Share on other sites
Momoko_Fan    100
Considering Java3D is pretty much dead (sun stopped supporting it) I think you'll have trouble getting answers for your question.. If you want you could take a look at newer and more supported engines like jMonkeyEngine, jPCT, or Xith3D.

Share this post

Link to post
Share on other sites
Lord_Evil    680
Well, is it really dead? The lates version I downloaded was 1.5.2 which seems to be quite new (didn't find a release date though).

But thanks for the suggestions, I'll have a look at those.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this