Simple Java 3D - Unable to apply Transform3D to rotate object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Simple Java 3D - Unable to apply Transform3D to rotate object

  1. #1
    Join Date
    Jan 2005
    Posts
    2

    Simple Java 3D - Unable to apply Transform3D to rotate object

    Hello experts!

    I have a project that has been quite frustrating to me. Please help me get the rotation work...

    Below is a function that is called by clicking on a JButton. This code works:

    Code:
    private void zoom(boolean in) {
           Transform3D zoom = world3d.zoom;
           zoom.set(zoom.getScale()+(in ? -0.2 : 0.2));
           world3d.zoomg.setTransform(zoom);                       // access member variable
      }
    However, the procedure doesn't work for rotation as follows:

    Code:
    private void rotateX(boolean cw) {
           Transform3D rot = world3d.rotateX;
           xrot = xrot + (cw ? 0.1 : -0.1);
           rot.rotX (xrot);
           world3d.tgRotateX.setTransform(rot);                    // access member variable
      }
    The constructor for the World3D class is as follows:

    Code:
    public World3D (Canvas3D canvas3d) {
    
        mainShuttle = new Shuttle ();     // returns BranchGroup with 3D object
    
        Transform3D translate = new Transform3D ();
        translate.set (new Vector3f (0.15f, 0.0f, 0.7f));     // Translate to fit on screen
        TransformGroup tg = new TransformGroup (translate);
    
        zoom.set (0.5);
        zoomg = new TransformGroup (zoom); // Allow for dynamic zoom
        zoomg.setCapability (TransformGroup.ALLOW_TRANSFORM_READ);
        zoomg.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);
        
        tgRotateX = new TransformGroup (rotateX); // Allow for dynamic x-rotation 
        tgRotateX.setCapability (TransformGroup.ALLOW_TRANSFORM_READ);
        tgRotateX.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);
      
        zoomg.addChild (mainShuttle.getBG ());
        tg.addChild (zoomg);
        BranchGroup mainScene = new BranchGroup ();
        tgRotateX.addChild (tg);
        mainScene.addChild (tgRotateX);
        mainScene.compile ();
    
        SimpleUniverse simpleU = new SimpleUniverse (canvas3d);
    
        // This moves the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        simpleU.getViewingPlatform ().setNominalViewingTransform ();
    
        simpleU.addBranchGraph (mainScene);
      }

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    Are you trying to rotate the world matrix or an object's?

  3. #3
    Join Date
    Jan 2005
    Posts
    2
    The goal was to be able to move around the object. Anyway, I was able to get the rotation to work. What I did was to simply add the static TransformGroup before the dynamic ones. Therefore the code was like:
    Code:
    zoomg.addChild (mainShuttle.getBG ());
        tgRotateX.addChild (zoomg);
        BranchGroup mainScene = new BranchGroup ();
        tg.addChild (tgRotateX);
        mainScene.addChild (tg);
        mainScene.compile ();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center