List of usage examples for javax.media.j3d TransformGroup TransformGroup
public TransformGroup()
From source file:GearTest.java
public BranchGroup createGearBox(int toothCount) { Transform3D tempTransform = new Transform3D(); // Create the root of the branch graph BranchGroup branchRoot = createBranchEnvironment(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);/*from w w w . ja va 2s. co m*/ objScale.setTransform(t3d); branchRoot.addChild(objScale); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // 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 gearboxTrans = new TransformGroup(); gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(gearboxTrans); // Create a bounds for the mouse behavior methods BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Define the shaft base information int shaftCount = 4; int secondsPerRevolution = 8000; // Create the Shaft(s) Shaft shafts[] = new Shaft[shaftCount]; TransformGroup shaftTGs[] = new TransformGroup[shaftCount]; Alpha shaftAlphas[] = new Alpha[shaftCount]; RotationInterpolator shaftRotors[] = new RotationInterpolator[shaftCount]; Transform3D shaftAxis[] = new Transform3D[shaftCount]; // Note: the following arrays we're incorporated to make changing // the gearbox easier. float shaftRatios[] = new float[shaftCount]; shaftRatios[0] = 1.0f; shaftRatios[1] = 0.5f; shaftRatios[2] = 0.75f; shaftRatios[3] = 5.0f; float shaftRadius[] = new float[shaftCount]; shaftRadius[0] = 0.2f; shaftRadius[1] = 0.2f; shaftRadius[2] = 0.2f; shaftRadius[3] = 0.2f; float shaftLength[] = new float[shaftCount]; shaftLength[0] = 1.8f; shaftLength[1] = 0.8f; shaftLength[2] = 0.8f; shaftLength[3] = 0.8f; float shaftDirection[] = new float[shaftCount]; shaftDirection[0] = 1.0f; shaftDirection[1] = -1.0f; shaftDirection[2] = 1.0f; shaftDirection[3] = -1.0f; Vector3d shaftPlacement[] = new Vector3d[shaftCount]; shaftPlacement[0] = new Vector3d(-0.75, -0.9, 0.0); shaftPlacement[1] = new Vector3d(0.75, -0.9, 0.0); shaftPlacement[2] = new Vector3d(0.75, 0.35, 0.0); shaftPlacement[3] = new Vector3d(-0.75, 0.60, -0.7); // Create the shafts. for (int i = 0; i < shaftCount; i++) { shafts[i] = new Shaft(shaftRadius[i], shaftLength[i], 25, look); } // Create a transform group node for placing each shaft for (int i = 0; i < shaftCount; i++) { shaftTGs[i] = new TransformGroup(); gearboxTrans.addChild(shaftTGs[i]); shaftTGs[i].getTransform(tempTransform); tempTransform.setTranslation(shaftPlacement[i]); shaftTGs[i].setTransform(tempTransform); shaftTGs[i].addChild(shafts[i]); } // Add rotation interpolators to rotate the shaft in the appropriate // direction and at the appropriate rate for (int i = 0; i < shaftCount; i++) { shaftAlphas[i] = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, (long) (secondsPerRevolution * shaftRatios[i]), 0, 0, 0, 0, 0); shaftAxis[i] = new Transform3D(); shaftAxis[i].rotX(Math.PI / 2.0); shaftRotors[i] = new RotationInterpolator(shaftAlphas[i], shafts[i], shaftAxis[i], 0.0f, shaftDirection[i] * (float) Math.PI * 2.0f); shaftRotors[i].setSchedulingBounds(bounds); shaftTGs[i].addChild(shaftRotors[i]); } // Define the gear base information. Again, these arrays exist to // make the process of changing the GearBox via an editor faster int gearCount = 5; float valleyToCircularPitchRatio = .15f; float pitchCircleRadius = 1.0f; float addendum = 0.05f; float dedendum = 0.05f; float gearThickness = 0.3f; float toothTipThickness = 0.27f; // Create an array of gears and their associated information SpurGear gears[] = new SpurGear[gearCount]; TransformGroup gearTGs[] = new TransformGroup[gearCount]; int gearShaft[] = new int[gearCount]; gearShaft[0] = 0; gearShaft[1] = 1; gearShaft[2] = 2; gearShaft[3] = 0; gearShaft[4] = 3; float ratio[] = new float[gearCount]; ratio[0] = 1.0f; ratio[1] = 0.5f; ratio[2] = 0.75f; ratio[3] = 0.25f; ratio[4] = 1.25f; Vector3d placement[] = new Vector3d[gearCount]; placement[0] = new Vector3d(0.0, 0.0, 0.0); placement[1] = new Vector3d(0.0, 0.0, 0.0); placement[2] = new Vector3d(0.0, 0.0, 0.0); placement[3] = new Vector3d(0.0, 0.0, -0.7); placement[4] = new Vector3d(0.0, 0.0, 0.0); // Create the gears. for (int i = 0; i < gearCount; i++) { gears[i] = new SpurGearThinBody(((int) ((float) toothCount * ratio[i])), pitchCircleRadius * ratio[i], shaftRadius[0], addendum, dedendum, gearThickness, toothTipThickness, valleyToCircularPitchRatio, look); } // Create a transform group node for arranging the gears on a shaft // and attach the gear to its associated shaft for (int i = 0; i < gearCount; i++) { gearTGs[i] = new TransformGroup(); gearTGs[i].getTransform(tempTransform); tempTransform .rotZ((shaftDirection[gearShaft[i]] == -1.0) ? gears[i].getCircularPitchAngle() / -2.0f : 0.0f); tempTransform.setTranslation(placement[i]); gearTGs[i].setTransform(tempTransform); gearTGs[i].addChild(gears[i]); shafts[gearShaft[i]].addChild(gearTGs[i]); } // Have Java 3D perform optimizations on this scene graph. branchRoot.compile(); return branchRoot; }
From source file:ExSpotLight.java
public AnnotationArrow(float x, float y, float z, float x2, float y2, float z2) { super(x, y, z, x2, y2, z2); setLineWidth(lineWidth);/* w w w. ja v a 2 s . c om*/ // Compute the length and direction of the line float deltaX = x2 - x; float deltaY = y2 - y; float deltaZ = z2 - z; float theta = -(float) Math.atan2(deltaZ, deltaX); float phi = (float) Math.atan2(deltaY, deltaX); if (deltaX < 0.0f) { phi = (float) Math.PI - phi; } // Compute a matrix to rotate a cone to point in the line's // direction, then place the cone at the line's endpoint. Matrix4f mat = new Matrix4f(); Matrix4f mat2 = new Matrix4f(); mat.setIdentity(); // Move to the endpoint of the line mat2.setIdentity(); mat2.setTranslation(new Vector3f(x2, y2, z2)); mat.mul(mat2); // Spin around Y mat2.setIdentity(); mat2.rotY(theta); mat.mul(mat2); // Tilt up or down around Z mat2.setIdentity(); mat2.rotZ(phi); mat.mul(mat2); // Tilt cone to point right mat2.setIdentity(); mat2.rotZ(-1.571f); mat.mul(mat2); arrowTrans = new TransformGroup(); arrowTrans.setCapability(Group.ALLOW_CHILDREN_WRITE); Transform3D trans = new Transform3D(mat); arrowTrans.setTransform(trans); // Create an appearance arrowAppearance = new Appearance(); arrowAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE); getLineColor(arrowColor); coloringAttributes = new ColoringAttributes(); coloringAttributes.setColor(arrowColor); coloringAttributes.setShadeModel(ColoringAttributes.SHADE_FLAT); arrowAppearance.setColoringAttributes(coloringAttributes); // Build a cone for the arrow head arrowHead = new Cone(arrowRadius, // base radius arrowLength, // height 0, // don't generate normals radialDivisions, // divisions radially sideDivisions, // divisions vertically arrowAppearance); // appearance arrowTrans.addChild(arrowHead); addChild(arrowTrans); }
From source file:LightTest.java
public Group createGeometry() { m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create appearance and material for the Cone Appearance app = new Appearance(); // create the Primitive and add to the parent BranchGroup m_Cone = new Cone(1, 10, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, app); m_TransformGroup.addChild(m_Cone);//w ww . ja va 2 s . c om Group superGroup = super.createGeometry(); superGroup.addChild(m_TransformGroup); return superGroup; }
From source file:FourByFour.java
/** * Create the scenegraph for the 3D view. *//*ww w .j av a 2s. c om*/ public BranchGroup createScene3D() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambient = new Color3f(0.25f, 0.25f, 0.25f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.9f, 0.9f, 0.9f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = new BranchGroup(); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); branchGroup.addChild(boundingLeaf); // Create the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); branchGroup.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); branchGroup.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); branchGroup.addChild(dirLight); // Create the pole appearance Material poleMaterial = new Material(ambient, black, diffuse, specular, 110.f); poleMaterial.setLightingEnable(true); Appearance poleAppearance = new Appearance(); poleAppearance.setMaterial(poleMaterial); // Create the transform group node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branchGroup.addChild(transformGroup); // Create the poles Poles poles = new Poles(poleAppearance); transformGroup.addChild(poles.getChild()); // Add the position markers to the transform group transformGroup.addChild(positions.getChild()); // Let the positions object know about the transform group positions.setTransformGroup(transformGroup); // Create the mouse pick and drag behavior node PickDragBehavior behavior = new PickDragBehavior(canvas2D, canvas3D, positions, branchGroup, transformGroup); behavior.setSchedulingBounds(bounds); transformGroup.addChild(behavior); return branchGroup; }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/*www . j a va 2 s .com*/ TransformGroup tg = new TransformGroup(); tg.addChild(new Cone(5, 30)); attachBehavior(new RandomWalkBehavior(getBehaviorTransformGroup(), m_CollisionDetector)); return tg; }
From source file:Demo3D.java
/** * Create the subgraph #32// w w w . ja va 2s .co m * * @return javax.media.j3d.TransformGroup trGr32_3 - the root of the * subgraph #32 */ public BranchGroup mySubGraph32() { // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create the first TransformGroup node trGr32_1 to: // 1) attach the Switch node with the five different earth's // representations to the subgraph32 // 2) attach a coordinate system to each earth's representation // 3) rotate each earth about its own y-axis. trGr32_1 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // SwitchBehavior is the class which controls the fonctioning of // the switchEarths node. switchBehavior = new SwitchBehavior(this); switchBehavior.setSchedulingBounds(boundsGen); trGr32_1.addChild(switchBehavior); // The Switch which allows the rendering of the five different // earth's representations. switchEarths = new Switch(); // With the ALLOW_TRANSFORM_WRITE, ALLOW_SWITCH_WRITE and // ALLOW_CHILDREN_READ // capabilities we allow to get or set new capabilities. switchEarths.setCapability(Switch.ALLOW_SWITCH_READ); switchEarths.setCapability(Switch.ALLOW_SWITCH_WRITE); switchEarths.setCapability(Switch.ALLOW_CHILDREN_READ); // Attach the different earth's representations to the Switch node. // Increasing earth_Points = new Earth("points", 0.4f); switchEarths.addChild(earth_Points.myEarth()); // # 0 earth_Lines = new Earth("lines", 0.4f); switchEarths.addChild(earth_Lines.myEarth()); // # 1 earth_Polygons = new Earth("polygons", 0.4f); switchEarths.addChild(earth_Polygons.myEarth()); // # 2 earth_Gouraud = new Earth("gouraud", 0.4f); switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 earth_Texture = new Earth("texture", 0.4f); switchEarths.addChild(earth_Texture.myEarth()); // # 4 // Decreasing switchEarths.addChild(earth_Texture.myEarth()); // # 4 switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 switchEarths.addChild(earth_Polygons.myEarth()); // # 2 switchEarths.addChild(earth_Lines.myEarth()); // # 1 switchEarths.addChild(earth_Points.myEarth()); // # 0 // Attach the Switch node with the five different earth's // representations to the TransformGroup node trGr32_1. trGr32_1.addChild(switchEarths); // Create and attach a coordinate system to the TransformGroup node // trGr32_1, that is to each earth's representation. coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis 0.0f, 0.0f, 1.0f, // Color of the y-axis 1.0f, 0.0f, 0.0f, // Color of the z-axis 0.6f); // Lenght of the 3 axes trGr32_1.addChild(coordSyst); // Create the alpha(t) function for the earth's rotation about // its own y-axis. rotationAlpha_1 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); // Create the earth's rotation about its own y-axis. rotator_1 = new RotationInterpolator(rotationAlpha_1, trGr32_1, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_1.setSchedulingBounds(boundsGen); trGr32_1.addChild(rotator_1); // Create a Transform3D instance to execute the desired "static // translation" of the earth, that is the rotation radius around // the sun. transl = new Transform3D(); vectTransl = new Vector3d(2.5, 0.0, 0.0); transl.set(vectTransl); // Create the second TransformGroup node trGr32_2 and attach the // "static translation" transl to it. trGr32_2 = new TransformGroup(transl); // Attach the trGr32_1 node to the trGr32_2 node. trGr32_2.addChild(trGr32_1); // Create the third TransformGroup node trGr32_3 for the earth's // rotation around the sun. trGr32_3 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Attach the trGr32_2 node to the trGr32_3 node. trGr32_3.addChild(trGr32_2); // Create the alpha(t) function for the earth's rotation around the sun. rotationAlpha_2 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); // To restart correctly the rotation of the earth around the // sun after a detach/add process of the subgraph32 from the // BranchGroup node brGr3. rotationAlpha_2.setStartTime(System.currentTimeMillis()); // Create the earth's rotation around the sun. rotator_2 = new RotationInterpolator(rotationAlpha_2, trGr32_3, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_2.setSchedulingBounds(boundsGen); trGr32_3.addChild(rotator_2); // To allow the detaching of this subgraph32 from the // BranchGroup node brGr3. brGr32 = new BranchGroup(); brGr32.setCapability(BranchGroup.ALLOW_DETACH); brGr32.addChild(trGr32_3); // Return the final version of the BranchGroup node brGr32. return brGr32; }
From source file:KeyNavigateTest.java
public Group createObject(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile, String szCollisionSound) { m_TransformGroup = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(scale);//from w w w . j a va2 s .c o m t3d.setTranslation(position); m_TransformGroup.setTransform(t3d); m_BehaviorTransformGroup = new TransformGroup(); if ((m_nFlags & GEOMETRY) == GEOMETRY) m_BehaviorTransformGroup .addChild(createGeometryGroup(app, position, scale, szTextureFile, szSoundFile)); if ((m_nFlags & SOUND) == SOUND) { MediaContainer media = loadSoundFile(szSoundFile); PointSound pointSound = new PointSound(media, getSoundInitialGain(false), 0, 0, 0); setSoundAttributes(pointSound, false); m_BehaviorTransformGroup.addChild(pointSound); } if ((m_nFlags & COLLISION) == COLLISION) { m_BehaviorTransformGroup.setCapability(Node.ENABLE_COLLISION_REPORTING); m_BehaviorTransformGroup.setCollidable(true); m_BehaviorTransformGroup.setCollisionBounds(getGeometryBounds()); if ((m_nFlags & COLLISION_SOUND) == COLLISION_SOUND) { MediaContainer collideMedia = loadSoundFile(szCollisionSound); m_CollideSound = new BackgroundSound(collideMedia, 1); setSoundAttributes(m_CollideSound, true); m_TransformGroup.addChild(m_CollideSound); } CollisionBehavior collision = new CollisionBehavior(m_BehaviorTransformGroup, this); collision.setSchedulingBounds(getGeometryBounds()); m_BehaviorTransformGroup.addChild(collision); } m_TransformGroup.addChild(m_BehaviorTransformGroup); m_ParentGroup.addChild(m_TransformGroup); return m_BehaviorTransformGroup; }
From source file:TransformExplorer.java
CoordSys(float axisLength) { super(Switch.CHILD_ALL); float coordSysLength = axisLength; float labelOffset = axisLength / 20.0f; float axisRadius = axisLength / 500.0f; float arrowRadius = axisLength / 125.0f; float arrowHeight = axisLength / 50.0f; float tickRadius = axisLength / 125.0f; float tickHeight = axisLength / 250.0f; // Set the Switch to allow changes setCapability(Switch.ALLOW_SWITCH_READ); setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Axis have // grey ambient, black emmissive, grey diffuse and grey specular // coloring.// w w w . j a v a2 s .co m //Material material = new Material(grey, black, grey, white, 64); Material material = new Material(white, black, white, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material); // Create a shared group to hold one axis of the coord sys SharedGroup coordAxisSG = new SharedGroup(); // create a cylinder for the central line of the axis Cylinder cylinder = new Cylinder(axisRadius, coordSysLength, appearance); // cylinder goes from -coordSysLength/2 to coordSysLength in y coordAxisSG.addChild(cylinder); // create the shared arrowhead Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance); SharedGroup arrowHeadSG = new SharedGroup(); arrowHeadSG.addChild(arrowHead); // Create a TransformGroup to move the arrowhead to the top of the // axis // The arrowhead goes from -arrowHeight/2 to arrowHeight/2 in y. // Put it at the top of the axis, coordSysLength / 2 tmpVector.set(0.0f, coordSysLength / 2 + arrowHeight / 2, 0.0f); tmpTrans.set(tmpVector); TransformGroup topTG = new TransformGroup(); topTG.setTransform(tmpTrans); topTG.addChild(new Link(arrowHeadSG)); coordAxisSG.addChild(topTG); // create the minus arrowhead // Create a TransformGroup to turn the cone upside down: // Rotate 180 degrees around Z axis tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(180)); tmpTrans.set(tmpAxisAngle); // Put the arrowhead at the bottom of the axis tmpVector.set(0.0f, -coordSysLength / 2 - arrowHeight / 2, 0.0f); tmpTrans.setTranslation(tmpVector); TransformGroup bottomTG = new TransformGroup(); bottomTG.setTransform(tmpTrans); bottomTG.addChild(new Link(arrowHeadSG)); coordAxisSG.addChild(bottomTG); // Now add "ticks" at 1, 2, 3, etc. // create a shared group for the tick Cylinder tick = new Cylinder(tickRadius, tickHeight, appearance); SharedGroup tickSG = new SharedGroup(); tickSG.addChild(tick); // transform each instance and add it to the coord axis group int maxTick = (int) (coordSysLength / 2); int minTick = -maxTick; for (int i = minTick; i <= maxTick; i++) { if (i == 0) continue; // no tick at 0 // use a TransformGroup to offset to the tick location TransformGroup tickTG = new TransformGroup(); tmpVector.set(0.0f, (float) i, 0.0f); tmpTrans.set(tmpVector); tickTG.setTransform(tmpTrans); // then link to an instance of the Tick shared group tickTG.addChild(new Link(tickSG)); // add the TransformGroup to the coord axis coordAxisSG.addChild(tickTG); } // add a Link to the axis SharedGroup to the coordSys addChild(new Link(coordAxisSG)); // Y axis // Create TransformGroups for the X and Z axes TransformGroup xAxisTG = new TransformGroup(); // rotate 90 degrees around Z axis tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(90)); tmpTrans.set(tmpAxisAngle); xAxisTG.setTransform(tmpTrans); xAxisTG.addChild(new Link(coordAxisSG)); addChild(xAxisTG); // X axis TransformGroup zAxisTG = new TransformGroup(); // rotate 90 degrees around X axis tmpAxisAngle.set(1.0f, 0.0f, 0.0f, (float) Math.toRadians(90)); tmpTrans.set(tmpAxisAngle); zAxisTG.setTransform(tmpTrans); zAxisTG.addChild(new Link(coordAxisSG)); addChild(zAxisTG); // Z axis // Add the labels. First we need a Font3D for the Text3Ds // select the default font, plain style, 0.5 tall. Use null for // the extrusion so we get "flat" text since we will be putting it // into an oriented Shape3D Font3D f3d = new Font3D(new Font("Default", Font.PLAIN, 1), null); // set up the +X label Text3D plusXText = new Text3D(f3d, "+X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusXTextShape = new OrientedShape3D(plusXText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusXTG = new TransformGroup(); tmpVector.set(coordSysLength / 2 + labelOffset, 0.0f, 0.0f); tmpTrans.set(0.15f, tmpVector); plusXTG.setTransform(tmpTrans); plusXTG.addChild(plusXTextShape); addChild(plusXTG); // set up the -X label Text3D minusXText = new Text3D(f3d, "-X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusXTextShape = new OrientedShape3D(minusXText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusXTG = new TransformGroup(); tmpVector.set(-coordSysLength / 2 - labelOffset, 0.0f, 0.0f); tmpTrans.set(0.15f, tmpVector); minusXTG.setTransform(tmpTrans); minusXTG.addChild(minusXTextShape); addChild(minusXTG); // set up the +Y label Text3D plusYText = new Text3D(f3d, "+Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusYTextShape = new OrientedShape3D(plusYText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusYTG = new TransformGroup(); tmpVector.set(0.0f, coordSysLength / 2 + labelOffset, 0.0f); tmpTrans.set(0.15f, tmpVector); plusYTG.setTransform(tmpTrans); plusYTG.addChild(plusYTextShape); addChild(plusYTG); // set up the -Y label Text3D minusYText = new Text3D(f3d, "-Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusYTextShape = new OrientedShape3D(minusYText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusYTG = new TransformGroup(); tmpVector.set(0.0f, -coordSysLength / 2 - labelOffset, 0.0f); tmpTrans.set(0.15f, tmpVector); minusYTG.setTransform(tmpTrans); minusYTG.addChild(minusYTextShape); addChild(minusYTG); // set up the +Z label Text3D plusZText = new Text3D(f3d, "+Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D plusZTextShape = new OrientedShape3D(plusZText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup plusZTG = new TransformGroup(); tmpVector.set(0.0f, 0.0f, coordSysLength / 2 + labelOffset); tmpTrans.set(0.15f, tmpVector); plusZTG.setTransform(tmpTrans); plusZTG.addChild(plusZTextShape); addChild(plusZTG); // set up the -Z label Text3D minusZText = new Text3D(f3d, "-Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT); // orient around the local origin OrientedShape3D minusZTextShape = new OrientedShape3D(minusZText, appearance, OrientedShape3D.ROTATE_ABOUT_POINT, origin); // transform to scale down to 0.15 in height, locate at end of axis TransformGroup minusZTG = new TransformGroup(); tmpVector.set(0.0f, 0.0f, -coordSysLength / 2 - labelOffset); tmpTrans.set(0.15f, tmpVector); minusZTG.setTransform(tmpTrans); minusZTG.addChild(minusZTextShape); addChild(minusZTG); }
From source file:SplineInterpolatorTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/*w w w.j av a 2s.c o m*/ TransformGroup tg = new TransformGroup(); // we need to flip the helicopter model // 90 degrees about the X axis Transform3D t3d = new Transform3D(); t3d.rotX(Math.toRadians(-90)); tg.setTransform(t3d); try { tg.addChild(loadGeometryGroup("heli.obj", app)); // create an Alpha object for the Interpolator Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, (long) Utils.getRandomNumber(0, 500), (long) Utils.getRandomNumber(0, 500), (long) Utils.getRandomNumber(20000, 5000), 4000, 100, (long) Utils.getRandomNumber(20000, 5000), 5000, 50); attachSplinePathInterpolator(alpha, new Transform3D(), new URL(((Java3dApplet) m_Component).getWorkingDirectory(), "heli_spline.xls")); } catch (Exception e) { System.err.println(e.toString()); } return tg; }
From source file:TransformExplorer.java
RotAxis(float axisLength) { super(Switch.CHILD_NONE); setCapability(Switch.ALLOW_SWITCH_READ); setCapability(Switch.ALLOW_SWITCH_WRITE); // set up the proportions for the arrow float axisRadius = axisLength / 120.0f; float arrowRadius = axisLength / 50.0f; float arrowHeight = axisLength / 30.0f; // create the TransformGroup which will be used to orient the axis axisTG = new TransformGroup(); axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); addChild(axisTG);//from ww w.j a v a2 s. c o m // Set up an appearance to make the Axis have // blue ambient, black emmissive, blue diffuse and white specular // coloring. Material material = new Material(blue, black, blue, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material); // create a cylinder for the central line of the axis Cylinder cylinder = new Cylinder(axisRadius, axisLength, appearance); // cylinder goes from -length/2 to length/2 in y axisTG.addChild(cylinder); // create a SharedGroup for the arrowHead Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance); SharedGroup arrowHeadSG = new SharedGroup(); arrowHeadSG.addChild(arrowHead); // Create a TransformGroup to move the cone to the top of the // cylinder tmpVector.set(0.0f, axisLength / 2 + arrowHeight / 2, 0.0f); tmpTrans.set(tmpVector); TransformGroup topTG = new TransformGroup(); topTG.setTransform(tmpTrans); topTG.addChild(new Link(arrowHeadSG)); axisTG.addChild(topTG); // create the bottom of the arrow // Create a TransformGroup to move the cone to the bottom of the // axis so that its pushes into the bottom of the cylinder tmpVector.set(0.0f, -(axisLength / 2), 0.0f); tmpTrans.set(tmpVector); TransformGroup bottomTG = new TransformGroup(); bottomTG.setTransform(tmpTrans); bottomTG.addChild(new Link(arrowHeadSG)); axisTG.addChild(bottomTG); updateAxisTransform(); }