Example usage for javax.media.j3d View setPhysicalBody

List of usage examples for javax.media.j3d View setPhysicalBody

Introduction

In this page you can find the example usage for javax.media.j3d View setPhysicalBody.

Prototype

public void setPhysicalBody(PhysicalBody physicalBody) 

Source Link

Document

Sets the view model's physical body to the PhysicalBody object provided.

Usage

From source file:SimpleMouse.java

/**
 * Build the view branch of the scene graph
 * /*w  w w  .j a  v a2  s.co m*/
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:SimpleLOD.java

/**
 * Build the view branch of the scene graph. In this case a key navigation
 * utility object is created and associated with the view transform so that
 * the view can be changed via the keyboard.
 * //from   w  w  w .j av  a2s. c o  m
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds);
    ViewPlatform myViewPlatform = new ViewPlatform();
    viewXfmGroup.addChild(boundLeaf);
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup);
    keyNav.setSchedulingBounds(movingBounds);
    viewBranch.addChild(keyNav);

    return viewBranch;
}

From source file:SimpleWorld.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content./*www  .  j av  a2 s.  c om*/
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    //This is the root of our view branch
    BranchGroup viewBranch = new BranchGroup();

    //The transform that will move our view
    //back 5 units along the z-axis
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));

    //The transform group that will be the parent
    //of our view platform elements
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();

    //Next the physical elements are created
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();

    //Then we put it all together
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    return viewBranch;
}

From source file:SimpleIndexedQuadSmooth.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//from  w w w  .ja  v  a 2  s  .  com
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:StereoCube.java

public void init() {
    setLayout(new FlowLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    c1.setSize(180, 180);/*from   w  w w  .  j  ava 2  s  .  c o  m*/
    c1.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW);
    add(c1);

    c2.setSize(180, 180);
    c2.setMonoscopicViewPolicy(View.RIGHT_EYE_VIEW);
    add(c2);

    // Create a simple scene and attach it to the virtual universe
    scene = createSceneGraph(0);
    u = new SimpleUniverse(c1);

    View view0 = u.getViewer().getView();
    View view = new View();
    PhysicalBody myBod = view0.getPhysicalBody();
    myBod.setLeftEyePosition(new Point3d(-.006, 0.0, 0.0)); // default is(-0.033, 0.0, 0.0)
    myBod.setRightEyePosition(new Point3d(+.006, 0.0, 0.0));
    view.setPhysicalBody(myBod);
    view.setPhysicalEnvironment(view0.getPhysicalEnvironment());
    view.attachViewPlatform(u.getViewingPlatform().getViewPlatform());
    view.addCanvas3D(c2);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);

}

From source file:SimpleCombine.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//from ww w  .j  a va  2s  .c  o m
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 7.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:SimpleSounds.java

/**
 * Build the view branch of the scene graph. In this case a key navigation
 * utility object is created and associated with the view transform so that
 * the view can be changed via the keyboard.
 * //from   w  ww .ja  v a 2  s .  c  o  m
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 30.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    ViewPlatform myViewPlatform = new ViewPlatform();
    BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds);
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup);
    keyNav.setSchedulingBounds(movingBounds);
    viewBranch.addChild(keyNav);
    //Create a sounds mixer to use our sounds with
    //and initialise it
    JavaSoundMixer myMixer = new JavaSoundMixer(myEnvironment);
    myMixer.initialize();
    return viewBranch;
}

From source file:StereoGirl.java

public void init() {
    setLayout(new FlowLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    String v = getParameter("url");
    if (v != null) {
        URLString = v;//w  w w .j  ava 2s .  co m
    }
    c1.setSize(140, 140);
    c1.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW);
    add(c1);

    c2.setSize(140, 140);
    c2.setMonoscopicViewPolicy(View.RIGHT_EYE_VIEW);
    add(c2);

    // Create a simple scene and attach it to the virtual universe
    scene = createSceneGraph(0);
    u = new SimpleUniverse(c1);

    View view0 = u.getViewer().getView();
    View view = new View();
    PhysicalBody myBod = view0.getPhysicalBody();
    myBod.setLeftEyePosition(new Point3d(-.006, 0.0, 0.0)); // default
    // is(-0.033,
    // 0.0, 0.0)
    myBod.setRightEyePosition(new Point3d(+.006, 0.0, 0.0));
    view.setPhysicalBody(myBod);
    view.setPhysicalEnvironment(view0.getPhysicalEnvironment());
    view.attachViewPlatform(u.getViewingPlatform().getViewPlatform());
    view.addCanvas3D(c2);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);

}

From source file:SimpleGame.java

/**
 * This builds the view branch of the scene graph.
 * /*from   ww  w.j  av a  2s.c  o  m*/
 * @return BranchGroup with viewing objects attached.
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    Matrix3d viewTilt = new Matrix3d();
    viewTilt.rotX(Math.PI / -6);
    viewXfm.set(viewTilt, new Vector3d(0.0, 10.0, 10.0), 1.0);
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:SwingTest.java

/**
 * Create a Java 3D View and attach it to a ViewPlatform
 *//*from w  w w.  ja va 2s.c  o  m*/
protected View createView(ViewPlatform vp) {
    View view = new View();

    PhysicalBody pb = createPhysicalBody();
    PhysicalEnvironment pe = createPhysicalEnvironment();

    view.setPhysicalEnvironment(pe);
    view.setPhysicalBody(pb);

    if (vp != null)
        view.attachViewPlatform(vp);

    view.setBackClipDistance(getBackClipDistance());
    view.setFrontClipDistance(getFrontClipDistance());

    // create the visible canvas
    Canvas3D c3d = createCanvas3D(false);
    view.addCanvas3D(c3d);

    // create the off screen canvas
    view.addCanvas3D(createOffscreenCanvas3D());

    // add the visible canvas to a component
    addCanvas3D(c3d);

    return view;
}