This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

setting the view

843799
843799 Member Posts: 49,999
edited Dec 15, 2001 6:57AM in Java 3D
I am using the SimpleUniverse and want to set the view to (0, 2, 2) such that the "eye position" is 2meters up the Y axis and 2 meters up the z axis. However, no matter what values I put in the vector, only the Z axis seems to be changed. Thus, I seem to only be able to move closer or farther away from the origin. Here is my code snipet:

mainScene = createSceneGraph();
u = new SimpleUniverse(c);
ViewingPlatform viewingPlatform = u.getViewingPlatform();
TransformGroup vpTrans = viewingPlatform.getViewPlatformTransform();
Transform3D transform = new Transform3D();
Vector3f translate = new Vector3f(0.0f, 2.0f, 2.0f);
transform.setTranslation(translate);
vpTrans.setTransform(transform);

The object I am viewing is a room, and right now my "eye level" is on the floor. Can anyone tell me what I am doing wrong?

Comments

  • 843799
    843799 Member Posts: 49,999
    Unfortunately you are one of the many people who needs help in understanding how the ViewPlatform works. As far as i can tell your code should work.

    I am having similar problems.

    Anyone know how to do collision detection with the boundary of the viewer?
    Code would be most helpful.
  • 843799
    843799 Member Posts: 49,999
    Three things.

    (1) You HAVE to read the first few chapters of Sun's Java 3D API Tutorial before doing anything else.

    http://java.sun.com/products/java-media/3D/collateral

    (2) Start using VirtualUniverse, not SimpleUniverse, using Sun's simple recipe and first Scene Graph Illustation in the tutorial; it is not that much harder to use.

    (3) Here is a program that uses VirtualUniverse, moves the view back from 0,0,0 along the Z axis so more of a large object can be seen, and enables the scene to be rotated and moved along the Z axis with the mouse (hold the left button to rotate or Alt+Left Mouse Button to zoom.

    HelloVirtualUniverse.java
    -------------------------

    package wrs9jd.java3D;

    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import java.awt.GraphicsConfiguration;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.geometry.ColorCube;
    import com.sun.j3d.utils.universe.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.behaviors.vp.*;
    import com.sun.j3d.utils.behaviors.mouse.*;

    public class HelloVirtualUniverse extends java.applet.Applet {
    VirtualUniverse u = null;

    public HelloVirtualUniverse() {}

    public BranchGroup createSceneGraph() {
    // The transform group will allow the scene to be rotated and zoomed in/out on.
    BranchGroup objRoot = new BranchGroup();
    TransformGroup objTrans = new TransformGroup();

    // Set these capability bits so the behaviors below will work.
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // Add a behavior so the scene can be rotated (hold the left mouse button).
    MouseRotate behavior = new MouseRotate();
    behavior.setTransformGroup(objTrans);
    objTrans.addChild(behavior);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10000.0);
    behavior.setSchedulingBounds(bounds);

    // Add a behavior to zoom in/out (hold down Alt and the left mouse button).
    MouseZoom behavior2 = new MouseZoom();
    behavior2.setTransformGroup(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    // Add the root transform group to the root of the scene.
    objRoot.addChild(objTrans);

    // Now, add any number of TransformGroup-Shape3D pairs.
    objTrans.addChild(new ColorCube(1.2));

    // Return the scene graph.
    return objRoot;
    }

    /**
    * This method follows Sun's basic recipe for writing a Java3D program
    * as given in the Java3D tutorial.
    */
    public BranchGroup createViewBranchGraph(Canvas3D c) {
    // Create a view object.
    View v = new View();

    // Create a ViewPlatform object.
    ViewPlatform vp = new ViewPlatform();

    // Create a PhysicalBody object.
    PhysicalBody pb = new PhysicalBody();

    // Create a PhysicalEnvironment object.
    PhysicalEnvironment pe = new PhysicalEnvironment();

    // Attach ViewPlatform, PhysicalBody, PhysicalEnvironment, and Canvas3D objects to View object.
    v.attachViewPlatform(vp);
    v.setPhysicalBody(pb);
    v.setPhysicalEnvironment(pe);
    v.addCanvas3D(c);

    // Now, construct the view branch graph.
    BranchGroup bg = new BranchGroup();

    Transform3D trans3D = new Transform3D();
    trans3D.lookAt(new Point3d(0,0,30.0), new Point3d(0,0,0), new Vector3d(0,1,0));
    trans3D.invert();
    TransformGroup tg = new TransformGroup(trans3D);

    bg.addChild(tg);
    tg.addChild(vp);

    // Return the BranchGroup.
    return bg;
    }
    public void destroy() {
    u.removeAllLocales();
    }
    /**
    * This method follows Sun's basic recipe for writing a Java3D program
    * as given in the Java3D tutorial.
    */
    public void init() {
    // Create a Canvas3D object.
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a VirtualUniverse object.
    u = new VirtualUniverse();

    // Create a Locale object, attaching it to the VirtualUniverse object.
    Locale locale = new Locale(u);

    // Construct a view branch graph.
    BranchGroup view = createViewBranchGraph(c);

    // Construct content branch graph(s).
    BranchGroup scene = createSceneGraph();

    // Compile branch graph(s).
    scene.compile();
    view.compile();

    // Insert subgraphs into the Locale (also making them live).
    locale.addBranchGraph(scene);
    locale.addBranchGraph(view);
    }
    public static void main(String[] args) {
    new MainFrame(new HelloVirtualUniverse(), 512, 512);
    }
    }
  • 843799
    843799 Member Posts: 49,999
    Using virtual universe isn't nessisary, i've moved the view around as i wanted with a simple universe reasonably easily... but it's been a while so i've forgotten exactly how it's done. I'll have a look around for the code..
This discussion has been closed.