Package javax.media.j3d

Examples of javax.media.j3d.TransformGroup


        if (height < 1.0) height = 1.0;
        height += (hex.surface() - hex.floor()) * BoardModel.HEX_HEIGHT;
        Transform3D supert = new Transform3D();
        supert.setScale(new Vector3d(2*BoardModel.HEX_SIDE_LENGTH, BoardModel.HEX_DIAMETER, height));
        supert.setTranslation(new Vector3d(0.0, 0.0, height/2));
        TransformGroup superTrans = new TransformGroup(supert);
        List<Shape3D> supers = tileManager.getModels(hex);
        for (Shape3D sup : supers) {
            superTrans.addChild(sup);
        }
       
        superTrans.setPickable(false);
        addChild(superTrans);

        // wood
        if (Math.max(hex.terrainLevel(Terrains.WOODS), hex.terrainLevel(Terrains.JUNGLE)) > 0) {
            supert = new Transform3D();
            supert.setScale(new Vector3d(2*BoardModel.HEX_SIDE_LENGTH, BoardModel.HEX_DIAMETER, 2*BoardModel.HEX_HEIGHT));
            supert.setTranslation(new Vector3d(0.0, 0.0, BoardModel.HEX_HEIGHT));
            superTrans = new TransformGroup(supert);
            superTrans.addChild(tileManager.getModel(hex));

            superTrans.setPickable(false);
            addChild(superTrans);
        }

        setBounds(new BoundingBox(
            new Point3d(-BoardModel.HEX_SIDE_LENGTH, -BoardModel.HEX_DIAMETER/2, BoardModel.HEX_HEIGHT*hex.floor()),
 
View Full Code Here


    private int ypos = 0;
    private final void addText(String s, Color3f col) {
        Transform3D t = new Transform3D();
        t.setTranslation(new Vector3d(0.0, -BoardModel.HEX_DIAMETER/3-3.5+ypos*2.75, hex.depth()*BoardModel.HEX_HEIGHT));
        TransformGroup tg = new TransformGroup(t);
        tg.addChild(new LabelModel(s, col, null, LabelModel.BIG));
        addChild(tg);
        ypos++;
    }
View Full Code Here

        anim.addChild(arrow);
        anim.addChild(outline);
        String label = null;

        TransformGroup tg = new TransformGroup();
        tg.addChild(anim);
       
        Transform3D trans = new Transform3D();
        double centerOffset = 0.0;

        switch (step.getType()) {
        case MovePath.STEP_CLIMB_MODE_OFF:
            if (step.getParent().getEntity().getMovementMode() == IEntityMovementMode.WIGE) {
                label = Messages.getString("BoardView1.WIGEClimbOff"); //$NON-NLS-1$
            } else {
                label = Messages.getString("BoardView1.ClimbOff"); //$NON-NLS-1$
            }
            if (step.isPastDanger()) {
                label = "(" + label + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            anim.removeChild(arrow);
        case MovePath.STEP_GO_PRONE:
        case MovePath.STEP_HULL_DOWN:
        case MovePath.STEP_DOWN:
        case MovePath.STEP_DIG_IN:
        case MovePath.STEP_FORTIFY:
            trans.rotX(-Math.PI/2);
            break;
        case MovePath.STEP_CLIMB_MODE_ON:
            if (step.getParent().getEntity().getMovementMode() == IEntityMovementMode.WIGE) {
                label = Messages.getString("BoardView1.WIGEClimb"); //$NON-NLS-1$
            } else {
                label = Messages.getString("BoardView1.Climb"); //$NON-NLS-1$
            }
            if (step.isPastDanger()) {
                label = "(" + label + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            anim.removeChild(arrow);
        case MovePath.STEP_GET_UP:
        case MovePath.STEP_UP:
            trans.rotX(Math.PI/2);
            break;

        case MovePath.STEP_LOAD:
            tg.removeChild(anim);
            label = Messages.getString("BoardView1.Load"); //$NON-NLS-1$
            if (step.isPastDanger()) {
                label = "(" + label + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            break;
        case MovePath.STEP_UNLOAD:
            tg.removeChild(anim);
            label = Messages.getString("BoardView1.Unload"); //$NON-NLS-1$
            if (step.isPastDanger()) {
                label = "(" + label + ")"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            break;
       
        case MovePath.STEP_TURN_LEFT:
        case MovePath.STEP_TURN_RIGHT:
            anim.removeChild(arrow);
            centerOffset = BoardModel.HEX_DIAMETER/6;
            trans.rotZ(-Math.PI/3*step.getFacing());
            break;
        default:
            centerOffset = -BoardModel.HEX_DIAMETER/3;
            trans.rotZ(-Math.PI/3*step.getFacing());
        }
        Vector3d translate = new Vector3d(0.0, centerOffset, -BoardModel.HEX_HEIGHT-count*.1);
        trans.transform(translate);
        trans.setTranslation(translate);
       
        if (label == null) {
            StringBuffer costStringBuf = new StringBuffer();
            costStringBuf.append(step.getMpUsed());

            if (step.isOnlyPavement() && step.getParent().getEntity() instanceof Tank) costStringBuf.append("+"); //$NON-NLS-1$

            if (step.isDanger()) costStringBuf.append("*"); //$NON-NLS-1$

            if (step.isPastDanger()) {
                costStringBuf.insert(0, "("); //$NON-NLS-1$
                costStringBuf.append(")"); //$NON-NLS-1$
            }

            if (step.isUsingMASC()) {
                costStringBuf.append("["); //$NON-NLS-1$
                costStringBuf.append(step.getTargetNumberMASC());
                costStringBuf.append("+]"); //$NON-NLS-1$
            }

            if (step.getMovementType() == IEntityMovementType.MOVE_VTOL_WALK
                    || step.getMovementType() == IEntityMovementType.MOVE_VTOL_RUN
                    || step.getMovementType() == IEntityMovementType.MOVE_SUBMARINE_WALK
                    || step.getMovementType() == IEntityMovementType.MOVE_SUBMARINE_RUN
                    || step.getElevation() != 0) {
                costStringBuf.append("{").append(step.getElevation()).append("}");
            }

            label = costStringBuf.toString();
        }

        tg.setTransform(trans);

        Vector3d loc = new Vector3d(BoardModel.getHexLocation(step.getPosition(), step.getElevation()+hex.getElevation()+1));
        loc.z += BoardModel.HEX_HEIGHT + count*.1;

        TransformGroup l = new TransformGroup(new Transform3D(C.nullRot, loc, 1.0));
        l.addChild(currentView.makeViewRelative(new LabelModel(label, C.black, color, LabelModel.BIGBOLD), count*.1));
       
        l.addChild(tg);

        addChild(l);
    }
View Full Code Here

        double angle = target0.angle(new Vector3d(0.0, -1.0, 0.0));
        target0.cross(target0, new Vector3d(0.0, -1.0, 0.0));
        Quat4d rot = new Quat4d();
        rot.set(new AxisAngle4d(target0, angle));

        TransformGroup tg = new TransformGroup(new Transform3D(rot, new Vector3d(source), 1.0));
        tg.addChild(anim);
       
        labelLocation = new Vector3d(target);
        labelLocation.negate();
        labelLocation.add(source);
        labelLocation.normalize();
View Full Code Here

            });
        } else if (aa instanceof SearchlightAttackAction) {
            label = Messages.getString("BoardView1.Searchlight");
        }
       
        TransformGroup l = new TransformGroup(new Transform3D(C.nullRot, labelLocation, 1.0));
        labelLocation.z += 3;
        labelLocation.y += 3;
        l.addChild(currentView.makeViewRelative(new LabelModel(label, C.black, color, LabelModel.BIGBOLD), 0.0));
        l.setUserData(aa);

        addChild(l);
    }
View Full Code Here

    //The transformation group of the tetrahedron.
    //The tetrahedron will be rotated a little bit.
    Transform3D tfTetrahedron = new Transform3D();
    tfTetrahedron.rotX(0.4*Math.PI);
    TransformGroup tgTetrahedron = new TransformGroup(tfTetrahedron);
    tgTetrahedron.addChild(tetrahedron);


//*** The root of the scenegraph. ***
    BranchGroup theScene = new BranchGroup();

View Full Code Here

    Transform3D tfBox = new Transform3D();
    tfBox.rotY(Math.PI/6);
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(-Math.PI/5);
    tfBox.mul(rotationX);
    TransformGroup tgBox = new TransformGroup(tfBox);
    tgBox.addChild(moveBox);


    //These properties are needed to allow the cube to moved around the scene.
    tgBox.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgBox.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tgBox.setCapability(TransformGroup.ENABLE_PICK_REPORTING);



    //Generate a golden Appearance for the cylinder.
    Color3f ambientColourCylinder = new Color3f(0.0f,0.0f,0.0f);
    Color3f emissiveColourCylinder = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourCylinder = new Color3f(0.8f,0.4f,0.0f);
    Color3f specularColourCylinder = new Color3f(0.8f,0.8f,0.0f);
    float shininessCylinder = 100.0f;

    Appearance yellowCylinderApp = new Appearance();

    yellowCylinderApp.setMaterial(new Material(ambientColourCylinder,
                                               emissiveColourCylinder,
                                               diffuseColourCylinder,
                                               specularColourCylinder,
                                               shininessCylinder));


    //Generate the cylinder.
    Cylinder cyli = new Cylinder(0.1f,0.3f,yellowCylinderApp);

    //The CollisionBounds for the cylinder.
    cyli.setCollisionBounds(new BoundingBox(new Point3d(0.0,-0.15,0.0),
                                            new Point3d(0.1,0.15,0.1)));
    cyli.setCollidable(true);

    //Position the cylinder and assign it to a transformation group.
    Transform3D tfCylinder = new Transform3D();
    tfCylinder.mul(rotationX);
    Transform3D positionCyl = new Transform3D();
    positionCyl.setTranslation(new Vector3f(-0.7f,0.0f,0.0f));
    tfCylinder.mul(positionCyl);

    TransformGroup tgCylinder = new TransformGroup(tfCylinder);
    tgCylinder.addChild(cyli);

    //This transformation group is needed for the movement of the cylinder.
    TransformGroup tgmCyl = new TransformGroup();
    tgmCyl.addChild(tgCylinder);

    //The movement from left to right.
    Transform3D escape = new Transform3D();
    Alpha cylAlphaR = new Alpha(1,2000);

    //The starting time is first postponed until "infinity".
    cylAlphaR.setStartTime(Long.MAX_VALUE);

    //The interpolator for the movement.
    float maxRight = 0.5f;
    PositionInterpolator cylMoveR = new PositionInterpolator(cylAlphaR,tgmCyl,
                                                             escape,0.0f,maxRight);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    cylMoveR.setSchedulingBounds(bounds);


    //The same for the movement from right to left.
    Alpha cylAlphaL = new Alpha(1,2000);
    cylAlphaL.setStartTime(Long.MAX_VALUE);

    PositionInterpolator cylMoveL = new PositionInterpolator(cylAlphaL,tgmCyl,
                                                             escape,maxRight,0.0f);

    cylMoveL.setSchedulingBounds(bounds);


    //Add the movements to the transformation group.
    tgmCyl.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgmCyl.addChild(cylMoveR);
    tgmCyl.addChild(cylMoveL);


    //A Switch for the green and the red sphere.
    Switch colourSwitch = new Switch();
    colourSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    //An Appearance for the green sphere.
    Color3f ambientColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    Color3f emissiveColourGSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    Color3f specularColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    float shininessGSphere = 1.0f;

    Appearance greenSphereApp = new Appearance();
    greenSphereApp.setMaterial(new Material(ambientColourGSphere,
                                            emissiveColourGSphere,
                                            diffuseColourGSphere,
                                            specularColourGSphere,
                                            shininessGSphere));

    //Generate the green sphere.
    float radius = 0.1f;
    Sphere greenSphere = new Sphere(radius,greenSphereApp);



    //The same for the red sphere.
    Color3f ambientColourRSphere = new Color3f(0.6f,0.0f,0.0f);
    Color3f emissiveColourRSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourRSphere = new Color3f(0.6f,0.0f,0.0f);
    Color3f specularColourRSphere = new Color3f(0.8f,0.0f,0.0f);
    float shininessRSphere = 20.0f;

    Appearance redSphereApp = new Appearance();

    redSphereApp.setMaterial(new Material(ambientColourRSphere,emissiveColourRSphere,
                             diffuseColourRSphere,specularColourRSphere,shininessRSphere));

    Sphere redSphere = new Sphere(radius,redSphereApp);



    //Add the two spheres to the Switch.
    colourSwitch.addChild(greenSphere);
    colourSwitch.addChild(redSphere);

    //The CollisionBounds for the two spheres.
    colourSwitch.setCollisionBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0),radius));

    //Enable the test for collision.
    colourSwitch.setCollidable(true);

    //The green sphere should be visible in the beginning.
    colourSwitch.setWhichChild(0);

    //A transformation group for the Switch (the spheres).
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(0.7f,0.0f,0.0f));
    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(colourSwitch);



    //Generate the scenegraph.
    BranchGroup theScene = new BranchGroup();


    //In order to allow navigation through the scene with the keyboard,
    //everything must be collected in a separate transformation group to which
    //the KeyNavigatorBehavior is applied.
    TransformGroup tgAll = new TransformGroup();
    tgAll.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tgAll.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgAll.addChild(tgBox);
    tgAll.addChild(tgSphere);
    tgAll.addChild(tgmCyl);
    KeyNavigatorBehavior knb = new KeyNavigatorBehavior(tgAll);
    knb.setSchedulingBounds(bounds);
    tgAll.addChild(knb);
    theScene.addChild(tgAll);

    //The PickTranslateBehavior for moving the blue cube.
    PickTranslateBehavior pickTrans = new PickTranslateBehavior(theScene,myCanvas3D,bounds);
    theScene.addChild(pickTrans);
View Full Code Here

    Transform3D tfObject = new Transform3D();
    tfObject.rotZ(0.4*Math.PI);
    Transform3D xRotation = new Transform3D();
    xRotation.rotY(0.4*Math.PI);
    tfObject.mul(xRotation);
    TransformGroup tgObject = new TransformGroup(tfObject);

    tgObject.addChild(extractedObject);

    BranchGroup theScene = new BranchGroup();

    //Add the transformation group with the blue part to the scene.
    theScene.addChild(tgObject);
View Full Code Here

    tfBox.rotY(Math.PI/6);
    tfBox.rotX(Math.PI/9);
    Transform3D shift = new Transform3D();
    shift.setTranslation(new Vector3f(-0.6f,-0.2f,0.1f));
    tfBox.mul(shift);
    TransformGroup tgBox = new TransformGroup(tfBox);
    tgBox.addChild(myBox);




//***Generate a sphere ***

    //Generate an Appearance for the sphere.
    Color3f ambientColourSphere = new Color3f(0.2f,0.2f,0.0f);
    Color3f emissiveColourSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourSphere = new Color3f(0.4f,0.4f,0.0f);
    Color3f specularColourSphere = new Color3f(0.8f,0.8f,0.0f);
    float shininessSphere = 120.0f;

    Appearance sphereApp = new Appearance();

    sphereApp.setMaterial(new Material(ambientColourSphere,emissiveColourSphere,
                           diffuseColourSphere,specularColourSphere,shininessSphere));



    Sphere mySphere = new Sphere(0.3f,Sphere.GENERATE_NORMALS,100,sphereApp);
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(0.0f,0.0f,-1.0f));

    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(mySphere);




    //*** Generate (the root of) the scenegraph. ***
 
View Full Code Here

        Transform3D tfObject = new Transform3D();
        tfObject.rotZ(0.4 * Math.PI);
        Transform3D xRotation = new Transform3D();
        xRotation.rotY(0.4 * Math.PI);
        tfObject.mul(xRotation);
        TransformGroup tgObject = new TransformGroup(tfObject);
        tgObject.addChild(s.getSceneGroup());

        // In the following way, the names of the parts of the object can be
        // obtained. The names are printed.
        Hashtable namedObjects = s.getNamedObjects();
        Enumeration enumer = namedObjects.keys();
View Full Code Here

TOP

Related Classes of javax.media.j3d.TransformGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.