Java 3d - moveable grid by mouse

Hi, can anyone help?

I am trying to write a program in java that requires a 3D grid to be rotated about all three axes using the mouse - and the ability to scroll and pan.

Would anyone know how to go about this? It just needs to be a simple grid.

Thanks in advance....
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you making the geometry of the 3d grid by yourself( i mean manually drawing lines in a 3d space) or importing contents from a .obj file created by Maya???

Whatever ur method is, I think it will help you a lot if you go through the the tutorial for java3d from

Download 7 chapters from the site and go through's easy and fun....

Chapter 2, (Creating Content)
Chapter 3, (Easier Content Creation)
Chapter 4, (Interaction)
will help u do your job.
Once I tried to navigate through a 3d grid and to rotate it with mouse. I built the 3d grid by drawing lines in the 3d space. I used the KeyNavigatorBehavior class to navigate through that 3d grid.

My code looked something like....
(You may need to modify the following code to meet your needs. But I suggest u first compile & run it.)

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.vecmath.*;

import java.awt.event.*;
import java.awt.AWTEvent;
import java.util.Enumeration;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.behaviors.mouse.*;

public class KeyNav1 extends Applet

  public KeyNav1()
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add("Center", canvas);

    SimpleUniverse su = new SimpleUniverse(canvas);
    BranchGroup scene = createSceneGraph(su);

  public BranchGroup createSceneGraph(SimpleUniverse su)
    BranchGroup objRoot = new BranchGroup();
    Geometry geo = createGeometry();
    Appearance app = new Appearance();
    ColoringAttributes ca = new ColoringAttributes();
    ca.setColor(0.0f, 0.0f, 1.0f);

    Shape3D shape = new Shape3D(geo, app);
    TransformGroup tg1 = new TransformGroup();

    MouseRotate rotate = new MouseRotate();
    rotate.setSchedulingBounds(new BoundingSphere());


    Background bkg = new Background();
    bkg.setApplicationBounds(new BoundingSphere());
    bkg.setColor(1.0f, 1.0f, 1.0f);

    TransformGroup tg = null;
    Transform3D translate = new Transform3D();
    translate.setTranslation(new Vector3f(0.0f, 0.3f, 0.0f));
    tg = su.getViewingPlatform().getViewPlatformTransform();

    KeyNavigatorBehavior knb = new KeyNavigatorBehavior(tg);
    knb.setSchedulingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 1000.0d));

    return objRoot;

  public Geometry createGeometry()
    LineArray line = new LineArray(54,LineArray.COORDINATES);
    line.setCoordinate(0, new Point3f(5.0f, 0.0f, 0.0f));
    line.setCoordinate(1, new Point3f(-5.0f, 0.0f, 0.0f));
    line.setCoordinate(2, new Point3f(0.0f, 5.0f, 0.0f));
    line.setCoordinate(3, new Point3f(0.0f, -5.0f, 0.0f));
    line.setCoordinate(4, new Point3f(0.0f, 0.0f, 5.0f));
    line.setCoordinate(5, new Point3f(0.0f, 0.0f, -5.0f));
    line.setCoordinate(6, new Point3f(0.1f, 0.0f, 5.0f));
    line.setCoordinate(7, new Point3f(0.1f, 0.0f, -5.0f));
    line.setCoordinate(8, new Point3f(0.2f, 0.0f, 5.0f));
    line.setCoordinate(9, new Point3f(0.2f, 0.0f, -5.0f));
    line.setCoordinate(10, new Point3f(0.3f, 0.0f, 5.0f));
    line.setCoordinate(11, new Point3f(0.3f, 0.0f, -5.0f));
    line.setCoordinate(12, new Point3f(0.4f, 0.0f, 5.0f));
    line.setCoordinate(13, new Point3f(0.4f, 0.0f, -5.0f));
    line.setCoordinate(14, new Point3f(0.5f, 0.0f, 5.0f));
    line.setCoordinate(15, new Point3f(0.5f, 0.0f, -5.0f));
    line.setCoordinate(16, new Point3f(0.6f, 0.0f, 5.0f));
    line.setCoordinate(17, new Point3f(0.6f, 0.0f, -5.0f));
    line.setCoordinate(18, new Point3f(-0.1f, 0.0f, 5.0f));
    line.setCoordinate(19, new Point3f(-0.1f, 0.0f, -5.0f));
    line.setCoordinate(20, new Point3f(-0.2f, 0.0f, 5.0f));
    line.setCoordinate(21, new Point3f(-0.2f, 0.0f, -5.0f));
    line.setCoordinate(22, new Point3f(-0.3f, 0.0f, 5.0f));
    line.setCoordinate(23, new Point3f(-0.3f, 0.0f, -5.0f));
    line.setCoordinate(24, new Point3f(-0.4f, 0.0f, 5.0f));
    line.setCoordinate(25, new Point3f(-0.4f, 0.0f, -5.0f));
    line.setCoordinate(26, new Point3f(-0.5f, 0.0f, 5.0f));
    line.setCoordinate(27, new Point3f(-0.5f, 0.0f, -5.0f));
    line.setCoordinate(28, new Point3f(-0.6f, 0.0f, 5.0f));
    line.setCoordinate(29, new Point3f(-0.6f, 0.0f, -5.0f));

    line.setCoordinate(30, new Point3f(5.0f, 0.0f, -0.1f));
    line.setCoordinate(31, new Point3f(-5.0f, 0.0f, -0.1f));
    line.setCoordinate(32, new Point3f(5.0f, 0.0f, -0.2f));
    line.setCoordinate(33, new Point3f(-5.0f, 0.0f, -0.2f));
    line.setCoordinate(34, new Point3f(5.0f, 0.0f, -0.3f));
    line.setCoordinate(35, new Point3f(-5.0f, 0.0f, -0.3f));
    line.setCoordinate(36, new Point3f(5.0f, 0.0f, -0.4f));
    line.setCoordinate(37, new Point3f(-5.0f, 0.0f, -0.4f));
    line.setCoordinate(38, new Point3f(5.0f, 0.0f, -0.5f));
    line.setCoordinate(39, new Point3f(-5.0f, 0.0f, -0.5f));
    line.setCoordinate(40, new Point3f(5.0f, 0.0f, -0.6f));
    line.setCoordinate(41, new Point3f(-5.0f, 0.0f, -0.6f));

    line.setCoordinate(42, new Point3f(5.0f, 0.0f, 0.1f));
    line.setCoordinate(43, new Point3f(-5.0f, 0.0f, 0.1f));
    line.setCoordinate(44, new Point3f(5.0f, 0.0f, 0.2f));
    line.setCoordinate(45, new Point3f(-5.0f, 0.0f, 0.2f));
    line.setCoordinate(46, new Point3f(5.0f, 0.0f, 0.3f));
    line.setCoordinate(47, new Point3f(-5.0f, 0.0f, 0.3f));
    line.setCoordinate(48, new Point3f(5.0f, 0.0f, 0.4f));
    line.setCoordinate(49, new Point3f(-5.0f, 0.0f, 0.4f));
    line.setCoordinate(50, new Point3f(5.0f, 0.0f, 0.5f));
    line.setCoordinate(51, new Point3f(-5.0f, 0.0f, 0.5f));
    line.setCoordinate(52, new Point3f(5.0f, 0.0f, 0.6f));
    line.setCoordinate(53, new Point3f(-5.0f, 0.0f, 0.6f));

    return line;

  public static void main(String args[])
    Frame frame = new MainFrame(new KeyNav1(), 500, 500);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.