Jump to content
  • Advertisement
Sign in to follow this  

[java] Java3D unprojection

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!