Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Cube Problem

  • 08-11-2011 08: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, Registered Users 2 Posts: 12,036 ✭✭✭✭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
Advertisement