List of usage examples for javax.media.j3d Transform3D mul
public final void mul(Transform3D t1)
From source file:Morphing.java
private BranchGroup createSceneGraph() { // 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.4);/*from ww w .ja v a 2 s .c om*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights 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.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objScale.addChild(aLgt); objScale.addChild(lgt1); // // Create the transform group nodes for the 3 original objects // and the morphed object. Add them to the root of the // branch graph. // TransformGroup objTrans[] = new TransformGroup[4]; for (int i = 0; i < 4; i++) { objTrans[i] = new TransformGroup(); objScale.addChild(objTrans[i]); } Transform3D tr = new Transform3D(); Transform3D rotX90 = new Transform3D(); rotX90.rotX(90.0 * Math.PI / 180.0); objTrans[0].getTransform(tr); tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[0].setTransform(tr); objTrans[1].getTransform(tr); tr.setTranslation(new Vector3d(0.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[1].setTransform(tr); objTrans[2].getTransform(tr); tr.setTranslation(new Vector3d(2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[2].setTransform(tr); objTrans[3].getTransform(tr); tr.setTranslation(new Vector3d(0.0, -2.0, -2.0)); tr.mul(rotX90); objTrans[3].setTransform(tr); // Now load the object files Scene s[] = new Scene[3]; GeometryArray g[] = new GeometryArray[3]; Shape3D shape[] = new Shape3D[3]; ObjectFile loader = new ObjectFile(ObjectFile.RESIZE); for (int i = 0; i < 3; i++) { s[i] = null; g[i] = null; shape[i] = null; } for (int i = 0; i < 3; i++) { try { s[i] = loader.load(objFiles[i]); } catch (FileNotFoundException e) { System.err.println(e); System.exit(1); } catch (ParsingErrorException e) { System.err.println(e); System.exit(1); } catch (IncorrectFormatException e) { System.err.println(e); System.exit(1); } BranchGroup b = s[i].getSceneGroup(); shape[i] = (Shape3D) b.getChild(0); g[i] = (GeometryArray) shape[i].getGeometry(); shape[i].setGeometry(g[i]); objTrans[i].addChild(b); } // // Create a Morph node, and set the appearance and input geometry // arrays. Set the Morph node's capability bits to allow the weights // to be modified at runtime. // Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); Morph morph = new Morph(g, app); morph.setCapability(Morph.ALLOW_WEIGHTS_READ); morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE); objTrans[3].addChild(morph); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200, 2000, 1000, 200); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objScale.addChild(mBeh); return objRoot; }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen/*w ww . jav a 2 s . c o m*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
private void formKeyPressed(KeyEvent evt) { if (lockView) { return;//from ww w .j a v a2s. c o m } double dAngle = Math.PI / 144; double dScale = 129. / 128.; if (storingFrames) { dAngle = Math.PI / 360; dScale = 513. / 512.; } if ((evt.getModifiers() & KeyEvent.CTRL_MASK) != 0) { dAngle = Math.PI / 2; } if ((evt.getModifiers() & KeyEvent.SHIFT_MASK) != 0) { dAngle = Math.PI / 6; } objRotate.getTransform(tempTransform); Transform3D rot = new Transform3D(); switch (evt.getKeyCode()) { case KeyEvent.VK_NUMPAD5: reset(); break; case KeyEvent.VK_DOWN: case KeyEvent.VK_KP_DOWN: case KeyEvent.VK_NUMPAD2: rot.rotX(dAngle); break; case KeyEvent.VK_UP: case KeyEvent.VK_KP_UP: case KeyEvent.VK_NUMPAD8: rot.rotX(-dAngle); break; case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: case KeyEvent.VK_NUMPAD4: rot.rotY(-dAngle); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: case KeyEvent.VK_NUMPAD6: rot.rotY(dAngle); break; case KeyEvent.VK_PAGE_UP: case KeyEvent.VK_NUMPAD9: rot.rotZ(dAngle); break; case KeyEvent.VK_PAGE_DOWN: case KeyEvent.VK_NUMPAD3: rot.rotZ(-dAngle); break; } rot.mul(tempTransform); objRotate.setTransform(rot); switch (evt.getKeyCode()) { case KeyEvent.VK_HOME: case KeyEvent.VK_NUMPAD7: mouseScale *= dScale; break; case KeyEvent.VK_END: case KeyEvent.VK_NUMPAD1: mouseScale /= dScale; break; } tempTransform = new Transform3D(new Matrix3d(1., 0., 0., 0., 1., 0., 0., 0., 1.), //sceneCenter, new Vector3d(0.0, 0.0, 0.0), externScale * mouseScale); objScale.setTransform(tempTransform); switch (evt.getKeyCode()) { case CAMERA_UP_KEY: cameraUpKeyPressed = true; processCameraKeys(evt); break; case CAMERA_DOWN_KEY: cameraDownKeyPressed = true; processCameraKeys(evt); break; case CAMERA_LEFT_KEY: cameraLeftKeyPressed = true; processCameraKeys(evt); break; case CAMERA_RIGHT_KEY: cameraRightKeyPressed = true; processCameraKeys(evt); break; case CAMERA_FORWARD_KEY: cameraForwardKeyPressed = true; processCameraKeys(evt); break; case CAMERA_BACKWARD_KEY: cameraBackwardKeyPressed = true; processCameraKeys(evt); break; // TODO milimetr: delete the code below after testing case '8': pickObject.setPickModuleMode(1); break; case '9': pickObject.setPickModuleMode(2); break; case '0': pickObject.setPickModuleMode(3); break; default: break; } }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
private void processCameraKeys(KeyEvent evt) { double dAngle = Math.PI / 144; double dScale = 129. / 128.; if (storingFrames) { dAngle = Math.PI / 360;//from w ww .ja va 2s . c o m dScale = 513. / 512.; } if ((evt.getModifiers() & KeyEvent.CTRL_MASK) != 0) { dAngle = Math.PI / 2; } TransformGroup cam = universe.getViewingPlatform().getViewPlatformTransform(); Transform3D camTr; Transform3D cRot; Transform3D tmpTr; Vector3d cMov; if (cameraUpKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cRot = new Transform3D(); cRot.rotX(-dAngle); camTr.mul(cRot); cam.setTransform(camTr); } if (cameraDownKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cRot = new Transform3D(); cRot.rotX(dAngle); camTr.mul(cRot); cam.setTransform(camTr); } if (cameraRightKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cRot = new Transform3D(); cRot.rotY(-dAngle); camTr.mul(cRot); cam.setTransform(camTr); } if (cameraLeftKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cRot = new Transform3D(); cRot.rotY(dAngle); camTr.mul(cRot); cam.setTransform(camTr); } if (cameraForwardKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cMov = new Vector3d(); cMov.x = 0; cMov.y = 0; cMov.z = -(dScale / 50); tmpTr = new Transform3D(); cam.getTransform(tmpTr); tmpTr.set(new Vector3d()); tmpTr.transform(cMov); tmpTr.set(cMov); camTr.mul(tmpTr); cam.setTransform(camTr); } if (cameraBackwardKeyPressed) { camTr = new Transform3D(); cam.getTransform(camTr); cMov = new Vector3d(); cMov.x = 0; cMov.y = 0; cMov.z = (dScale / 50); tmpTr = new Transform3D(); cam.getTransform(tmpTr); tmpTr.set(new Vector3d()); tmpTr.transform(cMov); tmpTr.set(cMov); camTr.mul(tmpTr); cam.setTransform(camTr); } }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
public void animate(double[] params) { if (lockView) { return;/*from w w w . j a va 2 s . c o m*/ } objRotate.getTransform(tempTransform); Transform3D rot = new Transform3D(); Transform3D tmp = new Transform3D(); tmp.rotX(params[0]); rot.mul(tmp); tmp.rotY(params[1]); rot.mul(tmp); tmp.rotZ(params[2]); rot.mul(tmp); rot.mul(tempTransform); objRotate.setTransform(rot); objTranslate.getTransform(rot); Vector3d trans = new Vector3d(params[3], params[4], params[5]); tmp = new Transform3D(); tmp.setTranslation(trans); rot.mul(tmp); objTranslate.setTransform(rot); mouseScale *= params[6]; tempTransform = new Transform3D(new Matrix3d(1., 0., 0., 0., 1., 0., 0., 0., 1.), //sceneCenter, new Vector3d(0.0, 0.0, 0.0), externScale * mouseScale); objScale.setTransform(tempTransform); }