4 Replies - 13102 Views - Last Post: 15 November 2010 - 02:43 PM

#1 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Week #36- Java3D API

Post icon  Posted 07 November 2010 - 01:32 PM

This week's challenge is to work with the Java3D API. This API provides not only wrappers for 3D Graphics, as AWT does with Graphics and Graphics2D, but tools for math and other utilities as well. Some of the features include multithreaded scenes, use for visualization and gaming, virtual reality view-based model, 3d-sound, and support for 3d math, including vector math.

-Make a basic 3D Image or Animation
-Make a basic 3D Game
-Use the API for math and physics modeling

-Sun Website
-Sun Tutorial
-Java3D.org Tutorial

Is This A Good Question/Topic? 1
  • +

Replies To: Week #36- Java3D API

#2 Brewer   User is offline

  • Awesome
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Re: Week #36- Java3D API

Posted 07 November 2010 - 01:55 PM

This looks pretty cool, to be honest I didn't know that this existed. I think I will give this week a go and try out some math or physics modeling, it has always LOOKED interesting to me.
Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Week #36- Java3D API

Posted 10 November 2010 - 09:00 PM

I might try this out eventhough i hate working with graphix
Was This Post Helpful? 0
  • +
  • -

#4 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Week #36- Java3D API

Posted 14 November 2010 - 11:24 AM

Has anyone got Java3d loading on windows? I've tried their installer and their zip files but if I try to import their core classes it always breaks. I haven't used Java anything for 7/8 years but I'm able to compile and run classes that don't use the Java3d libraries.

*Edit* Got it working when I load it through NetBeans. Compiling via command line results in "unable to find main" errors.

Anyone that wants to use it, there are comprehensive tutorials and examples at http://java.sun.com/...raining/java3d/

There is also a tutorial for getting a model loaded and walking around a 3d terrain: http://www.benmoxon....ava3d/index.htm

This post has been edited by mocker: 15 November 2010 - 02:38 PM

Was This Post Helpful? 0
  • +
  • -

#5 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Week #36- Java3D API

Posted 15 November 2010 - 02:43 PM

Figured I'd post what I got. Combined a few tutorials to make a moveable cube on top of a simple 3d map. I have the camera set to update on keypress but couldn't figure out the correct transform to make it move to where the cube is. Most of the code is implemented and commented out for the actual camera movement if you can see what I'm doing wrong.

Posted Image

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
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.keyboard.*;

import java.awt.event.*;
import java.util.Enumeration;

public class SimplebehaviorApp extends Applet {

    private SimpleUniverse u;
    private BoundingSphere bounds;
    private ViewingPlatform ourView;

    public class SimpleViewbehavior extends behavior{

        private TransformGroup targetTG;
        private ViewingPlatform targetVP;
        private Transform3D rotation = new Transform3D();
        private double angle = 0.0;
        private TransformGroup chaseTG;
        private Vector3d camVec;

        // create Simplebehavior
        SimpleViewbehavior(ViewingPlatform targetViewP, TransformGroup chasedTG){
            this.targetVP = targetViewP;
            this.chaseTG = chasedTG;
            this.targetTG = targetViewP.getViewPlatformTransform();
            camVec = new Vector3d();

        // initialize the behavior
        //     set initial wakeup condition
        //     called when behavior beacomes live
        public void initialize(){
            // set initial wakeup condition
            this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));

        // behave
        // called by Java 3D when appropriate stimulus occures
        public void processStimulus(Enumeration criteria){
            // decode event

            // do what is necessary
            angle += 0.1;
            Transform3D newrot = new Transform3D();
           // System.out.println(newrot.toString());
            Vector3d translate = new Vector3d();
            Vector3d up = new Vector3d(0, 1, 0);
            Vector3d camV = new Vector3d();
            camV.y = camV.y + 3d;
            camV.z = camV.z - 3d ;

              //Commented out attempts at making the camera chase the target
              // -------------------------
              // rotation.lookAt(camV, translate, up);

             Vector3d ourVec = new Vector3d();
            Vector3d up = new Vector3d(0, 1, 0);

            Point3d cam = new Point3d();
            Point3d man = new Point3d();

            rotation.lookAt(cam, man, up);
           //rotation.lookAt(Point3d eye, Point3d center, Vector3d up);

            //enable this when chase cam actually transforms correctly
            // targetTG.setTransform(rotation);
            this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));

    } // end of class SimpleViewbehavior

    //create 3d land to travel over
    Shape3D createLand(){
        LineArray landGeom = new LineArray(44, GeometryArray.COORDINATES
                                            | GeometryArray.COLOR_3);
        float l = -50.0f;
        for(int c = 0; c < 44; c+=4){

            landGeom.setCoordinate( c+0, new Point3f( -50.0f, 0.0f,  l ));
            landGeom.setCoordinate( c+1, new Point3f(  50.0f, 0.0f,  l ));
            landGeom.setCoordinate( c+2, new Point3f(   l   , 0.0f, -50.0f ));
            landGeom.setCoordinate( c+3, new Point3f(   l   , 0.0f,  50.0f ));
            l += 10.0f;

        Color3f c = new Color3f(0.1f, 0.8f, 0.1f);
        for(int i = 0; i < 44; i++) landGeom.setColor( i, c);

        return new Shape3D(landGeom);

    public BranchGroup createSceneGraph(SimpleUniverse su) {
	// Create the root of the branch graph
	BranchGroup objRoot = new BranchGroup();


        TransformGroup objRotate = new TransformGroup();

	objRotate.addChild(new ColorCube(0.4));

        //Create a KeyNavigator to move the cube around, and a SimpleViewbehavior for the camera
        KeyNavigatorbehavior myRotationbehavior = new KeyNavigatorbehavior(objRotate);
        SimpleViewbehavior myViewRotationbehavior = new SimpleViewbehavior(this.ourView,objRotate);
        myRotationbehavior.setSchedulingBounds(new BoundingSphere());
        myViewRotationbehavior.setSchedulingBounds(new BoundingSphere());

	// Let Java 3D perform optimizations on this scene graph.

	return objRoot;
    } // end of CreateSceneGraph method of SimplebehaviorApp

    // Create a simple scene and attach it to the virtual universe

    public SimplebehaviorApp() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =

        Canvas3D canvas3D = new Canvas3D(config);
        add("Center", canvas3D);

        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
        this.u = simpleU;
        ourView = u.getViewingPlatform();

	// This will move the ViewPlatform back a bit so the
	// objects in the scene can be viewed.
        Transform3D locator = new Transform3D();
         locator.setTranslation(new Vector3f(0, 3f, -3f));
         locator.lookAt(new Point3d(0d, 3d, -6d), new Point3d(0d, 0d, 5d), new Vector3d(0d, 1d, 0d));
         BranchGroup scene = createSceneGraph(this.u);

    } // end of SimplebehaviorApp (constructor)

    public static void main(String[] args) {
        System.out.print("SimplebehaviorApp.java \n- a demonstration of creating a simple");
        System.out.println("moveable cube on top of a map.");
        System.out.println("Use the arrow keys to rotate and move the orb. The green face is the front\n.");
        System.out.println("This is modified from the tutorials at The Java 3D API Tutorial at ");
        Frame frame = new MainFrame(new SimplebehaviorApp(), 256, 256);
    } // end of main (method of SimplebehaviorApp)

} // end of class SimplebehaviorApp

This post has been edited by mocker: 15 November 2010 - 02:44 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1