Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3878766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:38:59+00:00 2026-05-19T22:38:59+00:00

I want that when I click on a specific point on the screen, a

  • 0

I want that when I click on a specific point on the screen, a function call that return the point in 3d scene that I click.

For example, when I click on the top left of the screen, it should return x = 0, y = 1, z= 1; please help me create a method to do this.

edit:

Root = new BranchGroup();

setLayout(new BorderLayout());
add(canvas3D,BorderLayout.CENTER);
SimpleUniverse universe = new SimpleUniverse(canvas3D);

Shape();
universe.addBranchGraph(Root);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
OrbitBehavior behavior = new OrbitBehavior(canvas3D);
behavior.setSchedulingBounds(bounds);
viewingPlatform.setViewPlatformBehavior(behavior);
viewingPlatform.setNominalViewingTransform();
}

I’m using SimpleUniverse in NetBeans.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:38:59+00:00Added an answer on May 19, 2026 at 10:38 pm

    I’m afraid the answer isn’t straight forward. Depending on what is in your scene the mouse coordinates should change when you click on the screen. For instance if you have two objects so that the front one occludes the back one then you’d want to get the front objects coordinates. This is called mouse picking and there are several techniques for it. I found a few forums that explain how it’s done and have code examples.

    Basically the idea is that you imagine there being a laser (or something else that casts a ray) between you the user and the screen. This thing then projects a ray through the point on the screen surface where the mouse was clicked “into” the screen. Anything that is on the rays path will then be picked and optionally the occlusion order of objects in the ray’s path is resolved to give you the object closest to the “screen”.

    I am not familiar with J3D, but scraped the following code together from a few tutorials. It should get you started at least. The this you are looking for is this line Point3D intercept = ... at the bottom.

    http://www.java3d.org/selection.html

    package j3d_picking;
    
    import java.awt.*;
    import javax.swing.*;
    import javax.media.j3d.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.picking.behaviors.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.picking.PickIntersection;
    import com.sun.j3d.utils.picking.PickResult;
    import com.sun.j3d.utils.picking.PickTool;
    import javax.vecmath.Point3d;
    
    public class HelloJava3D
            extends JFrame
    {
    
        public HelloJava3D()
        {
            GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
            Canvas3D canvas3D = new Canvas3D(config);
    
            BranchGroup scene = createSceneGraph();
    
            // SimpleUniverse is a Convenience Utility class
            SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
    
            // This moves the ViewPlatform back a bit so the
            // objects in the scene can be viewed.
            simpleU.getViewingPlatform().setNominalViewingTransform();
    
            BoundingSphere behaveBounds = new BoundingSphere();
            ExamplePickBehavior behavior = new ExamplePickBehavior(canvas3D, scene, behaveBounds);
            scene.addChild(behavior);
    
            scene.compile();
            simpleU.addBranchGraph(scene);
    
            getContentPane().add(canvas3D, BorderLayout.CENTER);
        } // end of HelloJava3D (constructor)
    
        public BranchGroup createSceneGraph()
        {
            // Create the root of the branch graph
            BranchGroup objRoot = new BranchGroup();
    
            // Create a simple shape leaf node, add it to the scene graph.
            // ColorCube is a Convenience Utility class
            ColorCube cube = new ColorCube(0.4);
            cube.setCapability(Node.ENABLE_PICK_REPORTING);
            PickTool.setCapabilities(cube, PickTool.INTERSECT_FULL);
            objRoot.addChild(cube);
    
            return objRoot;
        } // end of createSceneGraph method of HelloJava3D
    
        public static void main(String[] args)
        {
            JFrame frame = new HelloJava3D();
            frame.setTitle("Hello Java3D");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setBounds(0, 0, 400, 300);
            frame.setVisible(true);
        }
    
        private class ExamplePickBehavior extends PickMouseBehavior
        {
    
            public ExamplePickBehavior(Canvas3D canvas, BranchGroup bg, Bounds bounds)
            {
                super(canvas, bg, bounds);
                setSchedulingBounds(bounds);
    
                pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
                // allows PickIntersection objects to be returned
            }
    
            public void updateScene(int xpos, int ypos)
            {
                pickCanvas.setShapeLocation(xpos, ypos);
                // register mouse pointer location on the screen (canvas)
    
                Point3d eyePos = pickCanvas.getStartPosition();
                // get the viewer's eye location
    
                PickResult pickResult = null;
                pickResult = pickCanvas.pickClosest();
                // get the intersected shape closest to the viewer
    
                if (pickResult != null) {
                    PickIntersection pi = pickResult.getClosestIntersection(eyePos);
                    // get the closest intersect to the eyePos point
                    Point3d intercept = pi.getPointCoordinatesVW();
                    System.out.println(intercept);
                    // extract the intersection pt in scene coords space
                    // use the intersection pt in some way...
                }
            } // end of updateScene(  )
        } // end of ExamplePickBehavior class
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my website to have a checkbox that users can click so that
I have some nested tables that I want to hide/show upon a click on
I want to check when the user double click on applictaion icon that no
my goal i want to translate a left click to a right click my
I want that list, because if something horrible happens, and I'll have to reinstall
SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part:
Web applications that want to force a resource to be downloaded rather than directly
I want something that can check if a string is SELECT , INSERT ,
I have a user that want to be able to select a textbox and
I have a class that has some properties. And I want something that calculates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.