Stereo Cube : Cube « 3D « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » 3D » CubeScreenshots 
Stereo Cube
Stereo Cube

//Copyright 1999 Resplendent Technology Ltd. greg@resplendent.com

import java.applet.Applet;
import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class StereoCube extends Applet {
    Canvas3D c1 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    Canvas3D c2 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    static MainFrame mf;
    private SimpleUniverse u = null;
    private BranchGroup scene = null;
    public void init() {
        setLayout(new FlowLayout());
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();

        
        c1.setSize(180180);
        c1.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW);
        add(c1);

        
        c2.setSize(180180);
        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.00.0))// default is(-0.033, 0.0, 0.0)
        myBod.setRightEyePosition(new Point3d(+.006,0.00.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);

    }
    public BranchGroup createSceneGraph(int i) {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        Transform3D t = new Transform3D();
      TransformGroup tg = new TransformGroup(t);
      tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
      tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
      objTrans.addChild(tg);
        tg.addChild(new ColorCube(0.4));
        MouseRotate behavior = new MouseRotate();
      BoundingSphere bounds =
          new BoundingSphere(new Point3d(0.0,0.0,0.0)100.0);
            
      behavior.setTransformGroup(tg);
      objTrans.addChild(behavior);
        // Create the translate behavior node
      MouseTranslate behavior3 = new MouseTranslate();
      behavior3.setTransformGroup(tg);
      objTrans.addChild(behavior3);
      behavior3.setSchedulingBounds(bounds);
      
      KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(
      new Point3d(),1000.0));
    objTrans.addChild(keyNavBeh);
    
      behavior.setSchedulingBounds(bounds);
        objRoot.addChild(objTrans);
        return objRoot;
    }     
    public StereoCube() {
    }
    public void destroy() {
        u.removeAllLocales();
    }
    public void setSize(int width, int height) {
        System.out.println("setsize " + width +"," +height);
        super.setSize(width, height);
        int minDimension = Math.min(width/2, height);
        c1.setSize((minDimension - 20),(minDimension - 20))
        c2.setSize((minDimension - 20),(minDimension - 20))
        if (mf != null) {
            mf.appletResize(width, height);
        }
        validate();
    }
    public static void main(String[] args) {
        mf = new MainFrame(new StereoCube()400200);
    }
}



           
       
Related examples in the same category
1. Pyramid 2 CubePyramid 2 Cube
2. RubiksCube
3. HelloJava3Dbalt renders a single, rotated cubeHelloJava3Dbalt renders a single, rotated cube
4. This uses the Box utility class to build a simple cubeThis uses the Box utility class to build a simple cube
5. Creates 1000 same-sized cubes and compiles the sceneCreates 1000 same-sized cubes and compiles the scene
w___ww___.j___a__v___a__2s___.__c_o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.