List of usage examples for javax.media.j3d Transform3D Transform3D
public Transform3D()
From source file:ExLinearFog.java
public ColumnScene(Component observer) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add a few lights AmbientLight ambient = new AmbientLight(); ambient.setEnable(true);/*from w w w .j a v a 2 s . c o m*/ ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f)); ambient.setInfluencingBounds(worldBounds); addChild(ambient); DirectionalLight dir1 = new DirectionalLight(); dir1.setEnable(true); dir1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); dir1.setDirection(new Vector3f(0.8f, -0.35f, 0.5f)); dir1.setInfluencingBounds(worldBounds); addChild(dir1); DirectionalLight dir2 = new DirectionalLight(); dir2.setEnable(true); dir2.setColor(new Color3f(0.75f, 0.75f, 1.0f)); dir2.setDirection(new Vector3f(-0.7f, -0.35f, -0.5f)); dir2.setInfluencingBounds(worldBounds); addChild(dir2); // Load textures TextureLoader texLoader = new TextureLoader("grass06.jpg", observer); Texture grassTex = texLoader.getTexture(); if (grassTex == null) System.err.println("Cannot load grass06.jpg texture"); else { grassTex.setBoundaryModeS(Texture.WRAP); grassTex.setBoundaryModeT(Texture.WRAP); grassTex.setMinFilter(Texture.NICEST); grassTex.setMagFilter(Texture.NICEST); grassTex.setMipMapMode(Texture.BASE_LEVEL); grassTex.setEnable(true); } texLoader = new TextureLoader("marble10.jpg", observer); Texture walkTex = texLoader.getTexture(); if (walkTex == null) System.err.println("Cannot load marble10.jpg texture"); else { walkTex.setBoundaryModeS(Texture.WRAP); walkTex.setBoundaryModeT(Texture.WRAP); walkTex.setMinFilter(Texture.NICEST); walkTex.setMagFilter(Texture.NICEST); walkTex.setMipMapMode(Texture.BASE_LEVEL); walkTex.setEnable(true); } texLoader = new TextureLoader("granite07rev.jpg", observer); columnTex = texLoader.getTexture(); if (columnTex == null) System.err.println("Cannot load granite07rev.jpg texture"); else { columnTex.setBoundaryModeS(Texture.WRAP); columnTex.setBoundaryModeT(Texture.WRAP); columnTex.setMinFilter(Texture.NICEST); columnTex.setMagFilter(Texture.NICEST); columnTex.setMipMapMode(Texture.BASE_LEVEL); columnTex.setEnable(true); } // // Build the ground // +-----+---+-----+ // | | | | // | G | W | G | // | | | | // +-----+---+-----+ // // where "G" is grass, and "W" is a walkway between columns // Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Walkway appearance Appearance walkApp = new Appearance(); Material walkMat = new Material(); walkMat.setAmbientColor(0.5f, 0.5f, 0.5f); walkMat.setDiffuseColor(1.0f, 1.0f, 1.0f); walkMat.setSpecularColor(0.0f, 0.0f, 0.0f); walkApp.setMaterial(walkMat); TextureAttributes walkTexAtt = new TextureAttributes(); walkTexAtt.setTextureMode(TextureAttributes.MODULATE); walkTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(1.0, 6.0, 1.0)); walkTexAtt.setTextureTransform(tr); walkApp.setTextureAttributes(walkTexAtt); if (walkTex != null) walkApp.setTexture(walkTex); // Grass appearance Appearance grassApp = new Appearance(); Material grassMat = new Material(); grassMat.setAmbientColor(0.5f, 0.5f, 0.5f); grassMat.setDiffuseColor(1.0f, 1.0f, 1.0f); grassMat.setSpecularColor(0.0f, 0.0f, 0.0f); grassApp.setMaterial(grassMat); TextureAttributes grassTexAtt = new TextureAttributes(); grassTexAtt.setTextureMode(TextureAttributes.MODULATE); grassTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(2.0, 8.0, 1.0)); grassTexAtt.setTextureTransform(tr); grassApp.setTextureAttributes(grassTexAtt); if (grassTex != null) grassApp.setTexture(grassTex); // Left grass trans.set(-LawnWidth / 2.0f - WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass1 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass1); addChild(tg); // Right grass trans.set(LawnWidth / 2.0f + WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass2 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass2); addChild(tg); // Walkway trans.set(0.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid walk = new ElevationGrid(2, // X dimension 2, // Z dimension WalkwayWidth, // X spacing WalkwayDepth, // Z spacing walkApp); // appearance tg.addChild(walk); addChild(tg); // // Build several columns on the floor // SharedGroup column = buildSharedColumn(); Group columns = buildColumns(column); addChild(columns); }
From source file:FourByFour.java
/** * Initialization//from www . j a v a 2 s. com */ public void init() { // Set the port number. port = 4111; // Set the graphics window size. width = 350; height = 350; // Set the weighting factors used for scoring. level_weight = 1311; move_weight = 111; time_weight = 1000; // Create the "base" color for the AWT components. setBackground(new Color(200, 200, 200)); // Read the instructions file. if (appletFlag) { // Get the host from which this applet came. host = getCodeBase().getHost(); try { inStream = new BufferedInputStream(new URL(getCodeBase(), "instructions.txt").openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; while (character != -1) { text[count++] = (byte) character; character = inStream.read(); } textString = new String(text); inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } else { try { inStream = new BufferedInputStream(new FileInputStream("instructions.txt")); text = new byte[5000]; int character = inStream.read(); int count = 0; while (character != -1) { text[count++] = (byte) character; character = inStream.read(); } textString = new String(text); inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } // Read the high-scores file. places = new int[20]; scores = new int[20]; names = new String[20]; if (appletFlag) { try { inStream = new BufferedInputStream(new URL(getCodeBase(), "scores.txt").openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32, 44); st.eolIsSignificant(false); int count = 0; int token = st.nextToken(); boolean scoreFlag = true; String string; while (count < 20) { places[count] = (int) st.nval; string = new String(""); token = st.nextToken(); while (token == StreamTokenizer.TT_WORD) { string += st.sval; string += " "; token = st.nextToken(); } names[count] = string; scores[count] = (int) st.nval; token = st.nextToken(); count++; } inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } else { try { inStream = new BufferedInputStream(new FileInputStream("scores.txt")); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32, 44); st.eolIsSignificant(false); int count = 0; int token = st.nextToken(); boolean scoreFlag = true; String string; while (count < 20) { places[count] = (int) st.nval; string = new String(""); token = st.nextToken(); while (token == StreamTokenizer.TT_WORD) { string += st.sval; string += " "; token = st.nextToken(); } names[count] = string; scores[count] = (int) st.nval; token = st.nextToken(); count++; } inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } // The positions object sets up the switch nodes which // control the rendering of the player's positions. positions = new Positions(); // Create the game board object which is responsible // for keeping track of the moves on the game board // and determining what move the computer should make. board = new Board(this, positions, width, height); positions.setBoard(board); // Create a 2D graphics canvas. canvas2D = new Canvas2D(board); canvas2D.setSize(width, height); canvas2D.setLocation(width + 10, 5); canvas2D.addMouseListener(canvas2D); board.setCanvas(canvas2D); // Create the 2D backbuffer backbuffer2D = createImage(width, height); canvas2D.setBuffer(backbuffer2D); // Create a 3D graphics canvas. canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); canvas3D.setSize(width, height); canvas3D.setLocation(5, 5); // Create the scene branchgroup. BranchGroup scene3D = createScene3D(); // Create a universe with the Java3D universe utility. universe = new SimpleUniverse(canvas3D); universe.addBranchGraph(scene3D); // Use parallel projection. View view = universe.getViewer().getView(); view.setProjectionPolicy(View.PARALLEL_PROJECTION); // Set the universe Transform3D object. TransformGroup tg = universe.getViewingPlatform().getViewPlatformTransform(); Transform3D transform = new Transform3D(); transform.set(65.f, new Vector3f(0.0f, 0.0f, 400.0f)); tg.setTransform(transform); // Create the canvas container. c_container = new Panel(); c_container.setSize(720, 360); c_container.setLocation(0, 0); c_container.setVisible(true); c_container.setLayout(null); add(c_container); // Add the 2D and 3D canvases to the container. c_container.add(canvas2D); c_container.add(canvas3D); // Turn off the layout manager, widgets will be sized // and positioned explicitly. setLayout(null); // Create the button container. b_container = new Panel(); b_container.setSize(720, 70); b_container.setLocation(0, 360); b_container.setVisible(true); b_container.setLayout(null); // Create the buttons. instruct_button = new Button("Instructions"); instruct_button.setSize(135, 25); instruct_button.setLocation(10, 10); instruct_button.setVisible(true); instruct_button.addActionListener(this); new_button = new Button("New Game"); new_button.setSize(135, 25); new_button.setLocation(150, 10); new_button.setVisible(true); new_button.addActionListener(this); undo_button = new Button("Undo Move"); undo_button.setSize(135, 25); undo_button.setLocation(290, 10); undo_button.setVisible(true); undo_button.addActionListener(this); skill_button = new Button("Skill Level"); skill_button.setSize(135, 25); skill_button.setLocation(430, 10); skill_button.setVisible(true); skill_button.addActionListener(this); high_button = new Button("High Scores"); high_button.setSize(135, 25); high_button.setLocation(570, 10); high_button.setVisible(true); high_button.addActionListener(this); b_container.add(new_button); b_container.add(undo_button); b_container.add(skill_button); b_container.add(high_button); b_container.add(instruct_button); // Add the button container to the applet. add(b_container); // Create the "Skill Level" dialog box. skill_panel = new Panel(); skill_panel.setSize(400, 300); skill_panel.setLocation(200, 20); skill_panel.setLayout(null); skill_label = new Label("Pick your skill level:"); skill_label.setSize(200, 25); skill_label.setLocation(25, 20); skill_label.setVisible(true); skill_panel.add(skill_label); group = new CheckboxGroup(); Checkbox skill_1 = new Checkbox("Babe in the Woods ", group, false); Checkbox skill_2 = new Checkbox("Walk and Chew Gum ", group, false); Checkbox skill_3 = new Checkbox("Jeopardy Contestant ", group, false); Checkbox skill_4 = new Checkbox("Rocket Scientist ", group, false); Checkbox skill_5 = new Checkbox("Be afraid, be very afraid", group, true); skill_1.setSize(170, 25); skill_1.setLocation(80, 60); skill_1.setVisible(true); skill_2.setSize(170, 25); skill_2.setLocation(80, 100); skill_2.setVisible(true); skill_3.setSize(170, 25); skill_3.setLocation(80, 140); skill_3.setVisible(true); skill_4.setSize(170, 25); skill_4.setLocation(80, 180); skill_4.setVisible(true); skill_5.setSize(170, 25); skill_5.setLocation(80, 220); skill_5.setVisible(true); skill_return_button = new Button("Return"); skill_return_button.setSize(120, 25); skill_return_button.setLocation(300, 370); skill_return_button.setVisible(false); skill_return_button.addActionListener(this); skill_panel.add(skill_1); skill_panel.add(skill_2); skill_panel.add(skill_3); skill_panel.add(skill_4); skill_panel.add(skill_5); skill_panel.setVisible(false); add(skill_return_button); add(skill_panel); // Create the "Instructions" panel. instruct_return_button = new Button("Return"); instruct_return_button.setLocation(300, 370); instruct_return_button.setSize(120, 25); instruct_return_button.setVisible(false); instruct_return_button.addActionListener(this); instruct_text = new TextArea(textString, 100, 200, TextArea.SCROLLBARS_VERTICAL_ONLY); instruct_text.setSize(715, 350); instruct_text.setLocation(0, 0); instruct_text.setVisible(false); add(instruct_text); add(instruct_return_button); high_panel = new Panel(); high_panel.setSize(715, 350); high_panel.setLocation(0, 0); high_panel.setVisible(false); high_panel.setLayout(null); high_label = new Label("High Scores"); high_label.setLocation(330, 5); high_label.setSize(200, 30); high_label.setVisible(true); high_panel.add(high_label); high_places = new Label[20]; high_names = new Label[20]; high_scores = new Label[20]; for (int i = 0; i < 20; i++) { high_places[i] = new Label(Integer.toString(i + 1)); high_places[i].setSize(20, 30); high_places[i].setVisible(true); high_names[i] = new Label(names[i]); high_names[i].setSize(150, 30); high_names[i].setVisible(true); high_scores[i] = new Label(Integer.toString(scores[i])); high_scores[i].setSize(150, 30); high_scores[i].setVisible(true); if (i < 10) { high_places[i].setLocation(70, i * 30 + 40); high_names[i].setLocation(100, i * 30 + 40); high_scores[i].setLocation(260, i * 30 + 40); } else { high_places[i].setLocation(425, (i - 10) * 30 + 40); high_names[i].setLocation(455, (i - 10) * 30 + 40); high_scores[i].setLocation(615, (i - 10) * 30 + 40); } high_panel.add(high_places[i]); high_panel.add(high_names[i]); high_panel.add(high_scores[i]); } high_return_button = new Button("Return"); high_return_button.setSize(120, 25); high_return_button.setLocation(300, 370); high_return_button.setVisible(false); high_return_button.addActionListener(this); add(high_return_button); add(high_panel); // Create the "Winner" dialog box winner_panel = new Panel(); winner_panel.setLayout(null); winner_panel.setSize(600, 500); winner_panel.setLocation(0, 0); winner_return_button = new Button("Return"); winner_return_button.setSize(120, 25); winner_return_button.setLocation(300, 360); winner_return_button.addActionListener(this); winner_panel.add(winner_return_button); winner_label = new Label(""); winner_label.setSize(200, 30); winner_label.setLocation(270, 110); winner_score_label = new Label(""); winner_score_label.setSize(200, 30); winner_top_label = new Label("You have a score in the top 20."); winner_top_label.setSize(200, 25); winner_top_label.setLocation(260, 185); winner_top_label.setVisible(false); winner_name_label = new Label("Enter your name here:"); winner_name_label.setSize(150, 25); winner_name_label.setLocation(260, 210); winner_name_label.setVisible(false); winner_name = new TextField(""); winner_name.setSize(200, 30); winner_name.setLocation(260, 240); winner_name.setVisible(false); winner_panel.add(winner_label); winner_panel.add(winner_score_label); winner_panel.add(winner_top_label); winner_panel.add(winner_name_label); winner_panel.add(winner_name); winner_panel.setVisible(false); add(winner_panel); }
From source file:LightTest.java
public void synchLightToUi() { super.synchLightToUi(); // set some defaults if things go wrong... double x = 0; double y = 0; double z = 0; double constant = 0.01; double linear = 0; double quadratic = 0; try {/*from w w w .j a v a 2s. co m*/ x = Double.valueOf(m_XPositionTextField.getText()).doubleValue(); y = Double.valueOf(m_YPositionTextField.getText()).doubleValue(); z = Double.valueOf(m_ZPositionTextField.getText()).doubleValue(); constant = Double.valueOf(m_ConstantAttenuationTextField.getText()).doubleValue(); linear = Double.valueOf(m_LinearAttenuationTextField.getText()).doubleValue(); quadratic = Double.valueOf(m_QuadraticAttenuationTextField.getText()).doubleValue(); } catch (java.lang.NumberFormatException e) { // invalid numeric input - just ignore. } ((PointLight) m_Light).setPosition((float) x, (float) y, (float) z); ((PointLight) m_Light).setAttenuation((float) constant, (float) linear, (float) quadratic); if (m_TransformGroup != null) { Transform3D t3d = new Transform3D(); m_TransformGroup.getTransform(t3d); t3d.setTranslation(new Vector3d(x, y, z)); m_TransformGroup.setTransform(t3d); } if (m_Sphere != null) { Appearance app = new Appearance(); Color3f objColor = new Color3f(); m_Light.getColor(objColor); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); m_Sphere.getShape(Sphere.BODY).setAppearance(app); } }
From source file:Demo3D.java
/** * Create the subgraph #2//from w w w . ja v a 2 s.co m * * @return javax.media.j3d.BranchGroup brGr2 - the root of the subgraph #2 */ public BranchGroup mySubGraph2() { // Create the BranchGroup node brGr2 of the second subgraph. brGr2 = new BranchGroup(); // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create a Transform3D instance rot1 to perform the necessary // "static rotation" for the desired cube's position. rot1 = new Transform3D(); // Rotation of Pi/2 - arctan(1/sqrt(2)) = 0.955 rad about the // (1,0,-1)-axis passing through the origin. axe_rot = new AxisAngle4f(1.0f, 0.0f, -1.0f, 0.955f); rot1.setRotation(axe_rot); // Create the first TransformGroup node trGr2_1 and attach the // "static rotation" rot1 instance to it. trGr2_1 = new TransformGroup(rot1); // Create and attach a coordinate system to the TransformGroup node // trGr2_1 of the subgraph #2, that is to the cube. 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.4f); // Lenght of the 3 axes trGr2_1.addChild(coordSyst); // Create the ColorCube (Shape3D) and attach it to the // TransformGroup node trGr2_1 of the subgraph #2. colorCube = new ColorCube(0.5f); trGr2_1.addChild(colorCube); // Create the second TransformGroup node trGr2_2. trGr2_2 = 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. trGr2_2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Attach the first node trGr2_1 to the second node trGr2_2. trGr2_2.addChild(trGr2_1); // Prepare the RotationInterpolator (Behavior) for the // cube's rotation about the y-axis. trans1 = new Transform3D(); // Create the alpha(t) function. rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); // Create the cube's rotation about the y-axis. rotator = new RotationInterpolator(rotationAlpha, trGr2_2, trans1, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(boundsGen); trGr2_2.addChild(rotator); brGr2.addChild(trGr2_2); // Compile the subgraph to optimize the performances. brGr2.compile(); // Return the final version of the BranchGroup node brGr2 return brGr2; }
From source file:ViewProj.java
public BranchGroup createProjViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); Transform3D scale = new Transform3D(); scale.set(0.9);//from w w w . j av a 2s . com objTrans.setTransform(scale); objRoot.addChild(objTrans); // create the clip limits line Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(-1, -1, 0.1f); cpPoints[1] = new Point3f(1, -1, 0.1f); cpPoints[2] = new Point3f(1, 1, 0.1f); cpPoints[3] = new Point3f(-1, 1, 0.1f); cpPoints[4] = cpPoints[0]; int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); LineAttributes cpLa = new LineAttributes(); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // transform and render the clip grid points updateProjTrans(); if (numClipGridPts > 0) { // transform the clipGridPts for (int i = 0; i < numClipGridPts; i++) { projectPoint(clipGridPtsVW[i], clipGridPtsProj[i]); } LineArray clipLn = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLn.setCoordinates(0, clipGridPtsProj, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLn, clipGridApp); objTrans.addChild(clipShape); } // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); // transform the circlePts for (int i = 0; i < numCirclePts; i++) { projectPoint(circlePtsVW[i], circlePtsProj[i]); } int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsProj); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
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 . j ava 2 s . com 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:MouseNavigateTest.java
public TornadoMouseBehavior() { m_Object = null;/*from www. ja v a2 s. c o m*/ m_NewPos = new Point3f(); m_OldPos = new Point3f(); m_Translation = new Transform3D(); m_TranslationVector = new Vector3f(); m_bDragging = false; m_Transform3D = new Transform3D(); }
From source file:ExText.java
public void setViewpoint(Point3f position, Vector3f direction) { Transform3D t = new Transform3D(); t.set(new Vector3f(position)); exampleViewTransform.setTransform(t); // how to set direction? }
From source file:ExText.java
public void reset() { Transform3D trans = new Transform3D(); exampleSceneTransform.setTransform(trans); trans.set(new Vector3f(0.0f, 0.0f, 10.0f)); exampleViewTransform.setTransform(trans); setNavigationType(navigationType);//w ww . ja v a 2 s .c o m }
From source file:LightTest.java
public void synchLightToUi() { super.synchLightToUi(); // set some defaults if things go wrong... double x = 0; double y = 0; double z = 0; double conc = 1; double spread = 2; try {// w w w . j a v a 2 s. c om x = Double.valueOf(m_XDirectionTextField.getText()).doubleValue(); y = Double.valueOf(m_YDirectionTextField.getText()).doubleValue(); z = Double.valueOf(m_ZDirectionTextField.getText()).doubleValue(); conc = Double.valueOf(m_ConcentrationTextField.getText()).doubleValue(); spread = Double.valueOf(m_SpreadAngleTextField.getText()).doubleValue(); } catch (java.lang.NumberFormatException e) { // invalid numeric input - just ignore. } ((SpotLight) m_Light).setDirection((float) x, (float) y, (float) z); ((SpotLight) m_Light).setConcentration((float) conc); ((SpotLight) m_Light).setSpreadAngle((float) spread); if (m_DirectionTransformGroup != null) { Vector3d coneVector = new Vector3d(0, -1, 0); Vector3d lightVector = new Vector3d(x, y, z); coneVector.normalize(); lightVector.normalize(); Vector3d axisVector = new Vector3d(); axisVector.cross(coneVector, lightVector); double angle = java.lang.Math.acos(coneVector.dot(lightVector)); AxisAngle4d rotAxis = new AxisAngle4d(axisVector.x, axisVector.y, axisVector.z, angle); Transform3D t3d = new Transform3D(); t3d.setRotation(rotAxis); m_DirectionTransformGroup.setTransform(t3d); } if (m_Cone != null) { Appearance app = new Appearance(); Color3f objColor = new Color3f(); m_Light.getColor(objColor); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); m_Cone.getShape(Cone.CAP).setAppearance(app); } }