Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Cube Problem

Options
  • 08-11-2011 8:47pm
    #1
    Closed Accounts Posts: 2


    Hi all, I have a problem with my cube below i cant rotate it, I have tried keylistener() but I cant seen to get it to work can anyone help please !!!! :o i just dont no how to get it to rotate.

    public class Cube {

    // private Color3f lightBlue;
    private Color3f white;
    private BranchGroup group;
    private SimpleUniverse universe;


    public Cube() {

    white = new Color3f(1.0f, 1.0f, 1.0f);

    universe = new SimpleUniverse();
    group = new BranchGroup();

    // Method the method below.

    addCube(0.3f, 0.3f, 0.3f, new Vector3f(-1.0f, -1.0f, -1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(1.0f, -1.0f, -1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(1.0f, 1.0f, -1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(-1.0f, 1.0f, -1.0f), white);

    addCube(0.3f, 0.3f, 0.3f, new Vector3f(-1.0f, -1.0f, 1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(1.0f, -1.0f, 1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(1.0f, 1.0f, 1.0f), white);
    addCube(0.3f, 0.3f, 0.3f, new Vector3f(-1.0f, 1.0f, 1.0f), white);

    // addCube(0.3f, 0.3f, 0.3f, new Vector3f(-1.0f, -0.4f, 1.0f), white);
    // addCube(0.3f, 0.4f, 0.3f, new Vector3f(-1.0f, 0.3f, 1.0f), white);


    DirectionalLight light1 = new DirectionalLight(white, new Vector3f(0.0f, 2.0f, -12.0f));

    light1.setInfluencingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));

    group.addChild(light1);


    Transform3D look = new Transform3D();

    look.lookAt(new Point3d(3.0, -7.0, 10.0), new Point3d(0.0, 0.0, 0.0), new Vector3d(4.0, 0.0, 0.0));

    look.invert();

    universe.getViewingPlatform().getViewPlatformTransform().setTransform(look);

    universe.addBranchGraph(group);
    }


    }
    public void addCube(float x, float y, float z, Vector3f position, Color3f color) {

    TransformGroup tg = new TransformGroup(); // a single spatial transformation, can position, orient, and scale all of its children.
    Transform3D trans = new Transform3D(); // used for translations, rotations, and scaling and shear effects.

    Appearance app = new Appearance();

    Material mat = new Material(); // how this cube appears on screen ie. shininess

    mat.setDiffuseColor(color);
    mat.setSpecularColor(color);
    app.setMaterial(mat);

    Box b = new Box(z, y, x, app);

    trans.setTranslation(position);
    tg.setTransform(trans);
    tg.addChild(b);

    group.addChild(tg);


    }

    public static void main(String[] args) {
    new Cube();


    }



    }


Comments

  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    You have a render loop, which renders a cube using the values defined in Position, Rotation and Translation. These need to have methods to alter them, so you can pass values via an interface using a keylistener or whatever, or the update method of the object will read some values that are changed by a keylistener.

    I need to see a render loop of some sort to figure out what the hell is happening above though.


Advertisement