List of usage examples for javax.media.j3d TransformGroup setTransform
public void setTransform(Transform3D t1)
From source file:LineTypes.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a TransformGroup to scale the scene down by 3.5x // TODO: move view platform instead of scene using orbit behavior TransformGroup objScale = new TransformGroup(); Transform3D scaleTrans = new Transform3D(); //scaleTrans.set(1 / 3.5f); // scale down by 3.5x objScale.setTransform(scaleTrans); objRoot.addChild(objScale);// ww w . ja va2s .com // Create a TransformGroup and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // the mouse behaviors code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add the primitives to the scene objTrans.addChild(createLineTypes()); BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bg.setApplicationBounds(bounds); objTrans.addChild(bg); // set up the mouse rotation behavior MouseRotate mr = new MouseRotate(); mr.setTransformGroup(objTrans); mr.setSchedulingBounds(bounds); mr.setFactor(0.007); objTrans.addChild(mr); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); 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 w w w . j a v a 2s. c om 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:OrientedPtTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objScale = new TransformGroup(); Transform3D textMat = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view textMat.setScale(1.2 / sl);//from w ww .j a v a2 s . c o m objScale.setTransform(textMat); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Appearance apText = new Appearance(); Material m = new Material(); m.setLightingEnable(true); apText.setMaterial(m); Appearance apEarth = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); apEarth.setMaterial(mm); Appearance apStone = new Appearance(); apStone.setMaterial(mm); // create 3D text Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); Point3f textPt = new Point3f(-sl / 2.0f, 3.0f, 0.0f); Text3D txt = new Text3D(f3d, textString, textPt); OrientedShape3D textShape = new OrientedShape3D(); textShape.setGeometry(txt); textShape.setAppearance(apText); textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT); // text is centered around 0, 3, 0. Make it rotate around 0,5,0 Point3f rotationPt = new Point3f(0.0f, 5.0f, 0.0f); textShape.setRotationPoint(rotationPt); objScale.addChild(textShape); // also add a small Sphere at the rotation point to // show that we are rotating around the right point Sphere sphere = new Sphere(0.2f); TransformGroup sphereGroup = new TransformGroup(); Transform3D sphereXform = new Transform3D(); sphereXform.set(new Vector3f(rotationPt)); sphereGroup.setTransform(sphereXform); sphereGroup.addChild(sphere); objScale.addChild(sphereGroup); // Create a simple shape leaf node, add it to the scene graph. Transform3D cubeMat = new Transform3D(); TransformGroup cubeTrans = new TransformGroup(cubeMat); cubeMat.set(new Vector3d(0.9, 0.0, -1.0)); cubeTrans.setTransform(cubeMat); cubeTrans.addChild(new ColorCube(0.3)); objTrans.addChild(cubeTrans); TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this); if (stoneTex != null) apStone.setTexture(stoneTex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.REPLACE); apStone.setTextureAttributes(texAttr); Transform3D coneMat = new Transform3D(); TransformGroup coneTrans = new TransformGroup(coneMat); coneMat.set(new Vector3d(0.0, 0.0, 0.0)); coneTrans.setTransform(coneMat); coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone)); objTrans.addChild(coneTrans); TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this); if (earthTex != null) apEarth.setTexture(earthTex.getTexture()); apEarth.setTextureAttributes(texAttr); Transform3D cylinderMat = new Transform3D(); TransformGroup cylinderTrans = new TransformGroup(cylinderMat); cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0)); cylinderTrans.setTransform(cylinderMat); cylinderTrans.addChild( new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth)); objTrans.addChild(cylinderTrans); objTrans.addChild(objScale); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); apText.setMaterial(mm); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
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); 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);/*from ww w . j a v a2 s . c o m*/ // 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:cgview.java
public BranchGroup createSceneGraph(CompressedGeometry cg) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.7);/*from w ww. ja va 2 s .co m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add compressed geometry to the scene graph. CompressedGeometryHeader hdr = new CompressedGeometryHeader(); cg.getCompressedGeometryHeader(hdr); // There isn't really enough information in the compressed geometry // header to unamiguously determine the proper rendering attributes. // The bufferDataPresent field specifies whether or not normals are // bundled with vertices, but the compressed buffer can still contain // normals that should be lit. Assume that any surface geometry // should be lit and that lines and points should not unless the // header contains the NORMAL_IN_BUFFER bit. Material m = new Material(); if ((hdr.bufferType == hdr.TRIANGLE_BUFFER) || ((hdr.bufferDataPresent & hdr.NORMAL_IN_BUFFER) == 1)) m.setLightingEnable(true); else m.setLightingEnable(false); Appearance a = new Appearance(); a.setMaterial(m); objTrans.addChild(new Shape3D(cg, a)); // Create mouse behavior scheduling bounds. BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -0.9f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); return objRoot; }
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: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); 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);/*from w w w . j av a 2 s.co m*/ return tg; }
From source file:ScenegraphTest.java
private TransformGroup createArm(double rotX, double rotY, double rotZ) { TransformGroup tgShoulder = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setEuler(new Vector3d(rotX, rotY, rotZ)); tgShoulder.setTransform(t3d); TransformGroup tgParent = null;//from w w w . ja v a 2 s.c o m tgParent = addLimb(tgShoulder, "Upper Arm", 0.05, 0.5, 0.0, 0.0); tgParent = addLimb(tgParent, "Lower Arm", 0.03, 0.4, Math.PI * -0.5, Math.PI * 0.8); TransformGroup tgWrist = addLimb(tgParent, "Wrist", 0.03, 0.07, 0.0, Math.PI * 0.5); addLimb(tgWrist, "Thumb", 0.01, 0.05, 0.0, Math.PI * 0.5); addLimb(tgWrist, "Finger 1", 0.01, 0.08, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 2", 0.01, 0.10, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 3", 0.01, 0.08, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 4", 0.01, 0.05, 0.0, Math.PI * 0.3); return tgShoulder; }
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);//w w w . j a va 2 s. c o m } // 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; }
From source file:SimpleGame.java
/** * This builds the gun geometry. It uses box and cylinder primitives and * sets up a transform group so that we can rotate the gun. *//* w w w . jav a 2 s .c om*/ protected BranchGroup buildGun() { BranchGroup theGun = new BranchGroup(); Appearance gunApp = new Appearance(); Color3f ambientColour = new Color3f(0.5f, 0.5f, 0.5f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(0.5f, 0.5f, 0.5f); float shininess = 20.0f; gunApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); TransformGroup init = new TransformGroup(); TransformGroup barrel = new TransformGroup(); Transform3D gunXfm = new Transform3D(); Transform3D barrelXfm = new Transform3D(); barrelXfm.set(new Vector3d(0.0, -2.0, 0.0)); barrel.setTransform(barrelXfm); Matrix3d gunXfmMat = new Matrix3d(); gunXfmMat.rotX(Math.PI / 2); gunXfm.set(gunXfmMat, new Vector3d(0.0, 0.0, 0.0), 1.0); init.setTransform(gunXfm); gunXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); gunXfmGrp.addChild(new Box(1.0f, 1.0f, 0.5f, gunApp)); barrel.addChild(new Cylinder(0.3f, 4.0f, gunApp)); gunXfmGrp.addChild(barrel); theGun.addChild(init); init.addChild(gunXfmGrp); return theGun; }