Example usage for javax.media.j3d Transform3D setTranslation

List of usage examples for javax.media.j3d Transform3D setTranslation

Introduction

In this page you can find the example usage for javax.media.j3d Transform3D setTranslation.

Prototype

public final void setTranslation(Vector3d trans) 

Source Link

Document

Replaces the translational components of this transform to the values in the Vector3d argument; the other values of this transform are not modified.

Usage

From source file:BackgroundApp.java

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

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();

    translate.set(0.0f, -0.3f, 0.0f);/*from w  ww. java2 s .  c o m*/
    T3D.setTranslation(translate);
    TransformGroup objRoot = new TransformGroup(T3D);
    objRootBG.addChild(objRoot);

    objRoot.addChild(createLand());

    BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere());

    PlatformGeometry platformGeom = new PlatformGeometry();
    platformGeom.addChild(boundingLeaf);
    platformGeom.compile();
    su.getViewingPlatform().setPlatformGeometry(platformGeom);

    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(
            su.getViewingPlatform().getViewPlatformTransform());
    keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf);
    objRootBG.addChild(keyNavBeh);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0));
    background.setGeometry(createBackGraph());
    objRoot.addChild(background);

    AmbientLight ambientLight = new AmbientLight();
    ambientLight.setInfluencingBounds(new BoundingSphere());
    objRootBG.addChild(ambientLight);

    return objRootBG;
}

From source file:LightScopeApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();
    TransformGroup tableTG = new TransformGroup();
    TransformGroup lampTG = new TransformGroup();
    TransformGroup litBoxTG = new TransformGroup();
    TransformGroup unLitBoxTG = new TransformGroup();

    scene.addChild(tableTG);//  www  . j  av a  2 s .c o m
    tableTG.addChild(lampTG);
    tableTG.addChild(litBoxTG);
    tableTG.addChild(unLitBoxTG);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

    Vector3f transVector = new Vector3f();
    Transform3D transTransform = new Transform3D();

    transVector.set(0.0f, -0.4f, 0.5f);
    transTransform.setTranslation(transVector);
    tableTG.setTransform(transTransform);

    transVector.set(-0.4f, 0.001f, 0.1f);
    transTransform.setTranslation(transVector);
    lampTG.setTransform(transTransform);

    transVector.set(-0.2f, 0.1f, 0.2f);
    transTransform.setTranslation(transVector);
    litBoxTG.setTransform(transTransform);

    transVector.set(0.3f, 0.1f, -0.4f);
    transTransform.setTranslation(transVector);
    unLitBoxTG.setTransform(transTransform);

    Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f),
            new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f));
    tablePlane.setAppearance(createMaterialAppearance(white));
    tableTG.addChild(tablePlane);
    litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red)));
    Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f),
            new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f));
    shadowPlane.setAppearance(createMaterialAppearance(black));
    litBoxTG.addChild(shadowPlane);

    Appearance redGlowMat = createMaterialAppearance(red);
    //    redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f);
    unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat));

    Shape3D lamp = createLampShape();
    Appearance lampAppearance = createMaterialAppearance(blue);
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setBackFaceNormalFlip(true);
    lampAppearance.setPolygonAttributes(polyAttrib);
    lamp.setAppearance(lampAppearance);
    lampTG.addChild(lamp);

    PointLight lampLight = new PointLight();
    lampLight.setPosition(0.1f, 0.5f, -0.1f);
    lampLight.setInfluencingBounds(new BoundingSphere());
    lampTG.addChild(lampLight);

    Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f),
            new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f));
    litPlane.setAppearance(createMaterialAppearance(white));
    lampTG.addChild(litPlane);

    lampLight.addScope(lampTG);
    lampLight.addScope(litBoxTG);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f));
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD1.setDirection(lightDir);
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    lightDir.set(1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD2.setDirection(lightDir);
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:PrintFromButton.java

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

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);/*from   w ww  . j  a va2s . com*/
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

    TransformGroup objTrans = new TransformGroup(spin);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objTrans.addChild(new ColorCube(0.4));

    //Create a raster obj
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:OffScreenTest.java

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

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);/*from w  w w  .  java 2s.  com*/
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

    TransformGroup objTrans = new TransformGroup(spin);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objTrans.addChild(new ColorCube(0.4));

    //Create a raster
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:Text2DTest1.java

TransformGroup createText2D(String szText, Color3f color, int nSize, float scale, float trans) {
    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(scale);/*from ww  w. j  a v  a 2  s . co  m*/
    t3d.setTranslation(new Vector3d(-8.0, trans, 0));

    tg.setTransform(t3d);

    Text2D text2D = new Text2D(szText, color, "SansSerif", nSize, Font.PLAIN);

    tg.addChild(text2D);
    return tg;
}

From source file:SwitchTest.java

TransformGroup createLabel(String szText, double scale) {
    Color3f colorText = new Color3f();
    int nFontSizeText = 10;

    Text2D label3D = new Text2D(szText, colorText, "SansSerif", nFontSizeText, Font.PLAIN);

    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();

    t3d.setTranslation(new Vector3d(-8, 1.5 * (3 - m_nLabelNumber), 0));

    t3d.setScale(scale);//from   w  w  w . j av  a2  s  .c  o  m

    tg.setTransform(t3d);
    tg.addChild(label3D);

    m_nLabelNumber++;

    return tg;
}

From source file:TextureTransformTest.java

private TransformGroup createRotator() {
    // create a ColorCube to illustrate the current rotation
    TransformGroup transTg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(-70, -70, 50));
    transTg.setTransform(t3d);//from w  w w .  j av a2  s  . c  o  m

    TransformGroup subTg = new TransformGroup();
    subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    subTg.addChild(new ColorCube(10.0));

    // attach a MouseRotate behavior so we can
    // rotate the color cube with the left mouse button
    MouseRotate mouseRot = new MouseRotate(subTg);
    subTg.addChild(mouseRot);

    // assign a transformChanged callback as we want to be
    // notified whenever the rotation of the ColorCube
    // changed ("this" implements MouseBehaviorCallback );
    mouseRot.setupCallback(this);
    mouseRot.setSchedulingBounds(getApplicationBounds());

    transTg.addChild(subTg);

    return transTg;
}

From source file:MultiView.java

public TransformGroup[] getViewTransformGroupArray() {
    // increment the view count
    m_nNumViews++;/*from   www .  java 2 s  .c  o  m*/

    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Vector3d vTrans = new Vector3d(0.0, 0.0, -20);

    // move the camera BACK so we can view the scene
    // also set the scale so that the more views we have
    // the smaller the scene will be scaled
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vTrans);
    t3d.setScale(1.0 / m_nNumViews);
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:ScenegraphTest.java

TransformGroup createLimb(double radius, double length) {
    // because the cylinder is centered at 0,0,0
    // we need to shift the cylinder so that the bottom of
    // the cylinder is at 0,0,0 and the top is at 0, length, 0

    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, length / 2, 0));
    tg.setTransform(t3d);/*  w w  w  . j a  v  a 2  s.  c  o m*/

    Appearance app = new Appearance();
    Color3f black = new Color3f(0.4f, 0.2f, 0.1f);
    Color3f objColor = new Color3f(1, 0.8f, 0.6f);
    app.setMaterial(new Material(objColor, black, objColor, black, 90.0f));

    Cylinder cylinder = new Cylinder((float) radius, (float) length, Primitive.GENERATE_NORMALS, app);

    tg.addChild(cylinder);
    return tg;
}

From source file:ScenegraphTest.java

private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin,
        double rotMax) {
    // create the rotator
    TransformGroup tgJoint = new TransformGroup();
    tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // add a rotator if necessary
    if (rotMin != rotMax) {
        Transform3D xAxis = new Transform3D();
        xAxis.rotX(Math.PI / 2.0);
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin,
                (float) rotMax);
        rotator.setSchedulingBounds(createApplicationBounds());
        tgJoint.addChild(rotator);/* ww  w .  ja va 2 s.c  om*/
    }

    // create a cylinder using length and radius
    tgJoint.addChild(createLimb(radius, length));

    // create the joint (the *next* TG should
    // be offset by the length of this limb)
    TransformGroup tgOffset = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, length, 0));
    tgOffset.setTransform(t3d);

    tgJoint.addChild(tgOffset);
    parentGroup.addChild(tgJoint);

    // return the offset TG, so any child TG's will be added
    // in the correct position.
    return tgOffset;
}