List of usage examples for javax.media.j3d Transform3D get
public final void get(Vector3d trans)
From source file:Viewer3D.java
public void init() { if (filename == null) { // the path to the file for an applet try {//from www . j av a 2s. c om java.net.URL path = getCodeBase(); filename = new java.net.URL(path.toString() + "./ballcone.lws"); } catch (java.net.MalformedURLException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); System.exit(1); } } // Construct the Lw3d loader and load the file Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL); Scene loaderScene = null; try { loaderScene = lw3dLoader.load(filename); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Construct the applet canvas setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a basic universe setup and the root of our scene u = new SimpleUniverse(c); BranchGroup sceneRoot = new BranchGroup(); // Change the back clip distance; the default is small for // some lw3d worlds View theView = u.getViewer().getView(); theView.setBackClipDistance(50000f); // Now add the scene graph defined in the lw3d file if (loaderScene.getSceneGroup() != null) { // Instead of using the default view location (which may be // completely bogus for the particular file you're loading), // let's use the initial view from the file. We can get // this by getting the view groups from the scene (there's // only one for Lightwave 3D), then using the inverse of the // transform on that view as the transform for the entire scene. // First, get the view groups (shouldn't be null unless there // was something wrong in the load TransformGroup viewGroups[] = loaderScene.getViewGroups(); // Get the Transform3D from the view and invert it Transform3D t = new Transform3D(); viewGroups[0].getTransform(t); Matrix4d m = new Matrix4d(); t.get(m); m.invert(); t.set(m); // Now we've got the transform we want. Create an // appropriate TransformGroup and parent the scene to it. // Then insert the new group into the main BranchGroup. TransformGroup sceneTransform = new TransformGroup(t); sceneTransform.addChild(loaderScene.getSceneGroup()); sceneRoot.addChild(sceneTransform); } // Make the scene graph live by inserting the root into the universe u.addBranchGraph(sceneRoot); }
From source file:SimpleSounds.java
/** * Add a sound to the transform group. This takes a point sound object and * loads into it a sounds from a given file. The edge of the sound's extent * is also defined in a parameter./*from ww w . j ava 2 s. com*/ * * @param tg * TransformGroup that the sound is to be added to * @param sound * PointSound to be used * @param soundFile * String that is the name of the sound file to be loaded * @param edge * float that represents the sound's maximum extent */ protected void addObjectSound(TransformGroup tg, PointSound sound, String soundFile, float edge) { //First we get the current transform so that we can //position the sound in the same place Transform3D objXfm = new Transform3D(); Vector3f objPosition = new Vector3f(); tg.getTransform(objXfm); objXfm.get(objPosition); //Create the media container to load the sound MediaContainer soundContainer = new MediaContainer(soundFile); //Use the loaded data in the sound sound.setSoundData(soundContainer); sound.setInitialGain(1.0f); //Set the position to that of the given transform sound.setPosition(new Point3f(objPosition)); //Allow use to switch the sound on and off sound.setCapability(PointSound.ALLOW_ENABLE_READ); sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); sound.setSchedulingBounds(bounds); //Set it off to start with sound.setEnable(false); //Set it to loop forever sound.setLoop(BackgroundSound.INFINITE_LOOPS); //Use the edge value to set to extent of the sound Point2f[] attenuation = { new Point2f(0.0f, 1.0f), new Point2f(edge, 0.1f) }; sound.setDistanceGain(attenuation); //Add the sound to the transform group tg.addChild(sound); }
From source file:Text2DTest.java
/** * Process a keyboard event to move or rotate the viewer. *///from w w w . j av a 2s . c o m void processManualEvent(AWTEvent[] events) { for (int i = 0; i < events.length; ++i) { if (events[i] instanceof KeyEvent) { KeyEvent event = (KeyEvent) events[i]; if (event.getKeyCode() == KeyEvent.VK_EQUALS) { continue; } Transform3D t = new Transform3D(); viewTransformGroup.getTransform(t); Vector3f viewDir = new Vector3f(0f, 0f, -1f); Vector3f translation = new Vector3f(); t.get(translation); t.transform(viewDir); if (event.getKeyCode() == KeyEvent.VK_UP) { translation.x += viewDir.x; translation.y += viewDir.y; translation.z += viewDir.z; } else if (event.getKeyCode() == KeyEvent.VK_DOWN) { translation.x -= viewDir.x; translation.y -= viewDir.y; translation.z -= viewDir.z; } else if (event.getKeyCode() == KeyEvent.VK_RIGHT) { rotation += -.1; } else if (event.getKeyCode() == KeyEvent.VK_LEFT) { rotation += .1; } t.rotY(rotation); t.setTranslation(translation); viewTransformGroup.setTransform(t); } } }
From source file:MouseNavigateTest.java
public static Point3d getEulerRotation(Transform3D t3d) { Point3d Rotation = new Point3d(); Matrix3d m1 = new Matrix3d(); t3d.get(m1); // extract the rotation angles from the upper 3x3 rotation // component of the 4x4 transformation matrix Rotation.y = -java.lang.Math.asin(m1.getElement(2, 0)); double c = java.lang.Math.cos(Rotation.y); double tRx, tRy, tRz; if (java.lang.Math.abs(Rotation.y) > 0.00001) { tRx = m1.getElement(2, 2) / c;/* w w w .j a v a2s . c o m*/ tRy = -m1.getElement(2, 1) / c; Rotation.x = java.lang.Math.atan2(tRy, tRx); tRx = m1.getElement(0, 0) / c; tRy = -m1.getElement(1, 0) / c; Rotation.z = java.lang.Math.atan2(tRy, tRx); } else { Rotation.x = 0.0; tRx = m1.getElement(1, 1); tRy = m1.getElement(0, 1); Rotation.z = java.lang.Math.atan2(tRy, tRx); } Rotation.x = -Rotation.x; Rotation.z = -Rotation.z; // now try to ensure that the values are positive by adding 2PI if // necessary... if (Rotation.x < 0.0) Rotation.x += 2 * java.lang.Math.PI; if (Rotation.y < 0.0) Rotation.y += 2 * java.lang.Math.PI; if (Rotation.z < 0.0) Rotation.z += 2 * java.lang.Math.PI; return Rotation; }
From source file:AvatarTest.java
/** * Process a keyboard event//w w w . ja v a 2 s .c o m */ private void processAWTEvent(AWTEvent[] events) { for (int n = 0; n < events.length; n++) { if (events[n] instanceof KeyEvent) { KeyEvent eventKey = (KeyEvent) events[n]; if (eventKey.getID() == KeyEvent.KEY_PRESSED) { int keyCode = eventKey.getKeyCode(); int keyChar = eventKey.getKeyChar(); Vector3f translate = new Vector3f(); Transform3D t3d = new Transform3D(); m_TransformGroup.getTransform(t3d); t3d.get(translate); switch (keyCode) { case KeyEvent.VK_LEFT: translate.x += TRANSLATE_LEFT; break; case KeyEvent.VK_RIGHT: translate.x += TRANSLATE_RIGHT; break; } // System.out.println( "Steering: " + translate.x ); translate.y = 0.5f; t3d.setTranslation(translate); m_TransformGroup.setTransform(t3d); } } } }
From source file:ViewProj.java
public BranchGroup createVWorldViewSG() { // 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(); objRoot.addChild(objTrans);/*w w w . j a va 2 s . c o m*/ // get the eye point, field of view and clip distances float fov = (float) view.getFieldOfView(); // figure out the angle factors to find points along the edges // of the FOV // X = fovSpreadX * (Y - eyeVW.y) + eyeVW.x; float fovSpreadX = (float) Math.tan(fov / 2); // Z = fovSpreadZ * (X - eyeVW.x) + eyeVW.z; float fovSpreadZ = 1.0f / fovSpreadX; //System.out.println("fovSpreadX = " + fovSpreadX); //System.out.println("fovSpreadZ = " + fovSpreadZ); Transform3D vpTransform = new Transform3D(); viewingPlatform.getViewPlatformTransform().getTransform(vpTransform); Vector3f vpTranslation = new Vector3f(); vpTransform.get(vpTranslation); eyePtVW.set(vpTranslation); eyePtVW.negate(); // get the eye point in our 2D coord system. Point3f eyePt = new Point3f(0.0f, eyePtVW.z, 0.1f); float frontClipDist = (float) view.getFrontClipDistance(); float backClipDist = (float) view.getBackClipDistance(); // set up the clip plane lines Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(frontClipDist * fovSpreadX, eyePtVW.z + frontClipDist, 0.1f); cpPoints[1] = new Point3f(cpPoints[0]); cpPoints[1].x *= -1; Point3f backLeft = new Point3f(-backClipDist * fovSpreadX, eyePtVW.z + backClipDist, 0.1f); cpPoints[2] = backLeft; Point3f backRight = new Point3f(backLeft); backRight.x *= -1; cpPoints[3] = backRight; cpPoints[4] = cpPoints[0]; //for (int i = 0; i < 4; i++) { // System.out.println("cpPoints[" + i + "] = " + cpPoints[i]); //} 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); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // get the limits of the space float minY = eyePt.y; float maxY = backLeft.y; float minX = backLeft.x; float maxX = backRight.x; // figure out the X and Y extents and offsets float deltaX = maxX - minX; float deltaY = maxY - minY; float offsetX = -(maxX + minX) / 2.0f; float offsetY = -(maxY + minY) / 2.0f; float gridSize = Math.max(deltaX, deltaY); // scale the grid slightly to give a border around the edge gridSize *= 1.1f; //System.out.println("offsetX = " + offsetX); //System.out.println("offsetY = " + offsetY); // Scale the view to fit -1 to 1 Transform3D trans = new Transform3D(); trans.set(new Vector3f(offsetX, offsetY, 0.0f), 2.0f / gridSize); objTrans.setTransform(trans); // figure out a grid step that is a multiple of 10 which keeps the // number of steps less than 30. float gridStep = 1.0f; while ((gridSize / gridStep) > 30.0) { gridStep *= 10; } int gridNumSteps = (int) Math.ceil(gridSize / gridStep) + 1; // allocate the grid points array, four points for each step (x and y) // with a couple extra points for the extra grid points added // below int gridNumPoints = 4 * (gridNumSteps + 4); Point3f[] gridPts = new Point3f[gridNumPoints]; for (int i = 0; i < gridNumPoints; i++) { gridPts[i] = new Point3f(); } // find the grid limits. Add a step on each side to make sure // the grid is larger than the view float gridMinY = gridStepFloor(minY, gridStep) - gridStep; float gridMaxY = gridStepCeil(maxY, gridStep) + gridStep; float gridMinX = gridStepFloor(minX, gridStep) - gridStep; float gridMaxX = gridStepCeil(maxX, gridStep) + gridStep; //System.out.println("gridMinY = " + gridMinY); //System.out.println("gridMaxY = " + gridMaxY); //System.out.println("gridMinX = " + gridMinX); //System.out.println("gridMaxX = " + gridMaxX); // set up the background grid Appearance bgApp = new Appearance(); ColoringAttributes bgCa = new ColoringAttributes(); bgCa.setColor(grey); LineAttributes bgLa = new LineAttributes(); bgApp.setColoringAttributes(bgCa); // clear out the clip grid point list numClipGridPts = 0; // set up the vertical lines int numPts = 0; for (float x = gridMinX; x <= gridMaxX; x += gridStep) { gridPts[numPts].x = x; gridPts[numPts].y = gridMinY; gridPts[numPts].z = -0.2f; gridPts[numPts + 1].x = x; gridPts[numPts + 1].y = gridMaxY; gridPts[numPts + 1].z = -0.2f; numPts += 2; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipZ = fovSpreadZ * Math.abs(x - eyePtVW.x); if (clipZ < frontClipDist) { // clip to front clip plane clipZ = frontClipDist; } if (clipZ < backClipDist) { // clip to back clip plane // line is not clipped clipGridPtsVW[numClipGridPts].x = x; clipGridPtsVW[numClipGridPts].y = clipZ + eyePtVW.z; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = x; clipGridPtsVW[numClipGridPts + 1].y = backClipDist + eyePtVW.z; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray vertLa = new LineArray(numPts, LineArray.COORDINATES); vertLa.setCoordinates(0, gridPts, 0, numPts); Shape3D vertShape = new Shape3D(vertLa, bgApp); objTrans.addChild(vertShape); // set up the horizontal lines numPts = 0; for (float y = gridMinY; y <= gridMaxY; y += gridStep) { gridPts[numPts].x = gridMinX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; gridPts[numPts].x = gridMaxX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipDist = (y - eyePtVW.z); if ((clipDist > frontClipDist) && (clipDist < backClipDist)) { float clipX = fovSpreadX * clipDist; clipGridPtsVW[numClipGridPts].x = -clipX; clipGridPtsVW[numClipGridPts].y = y; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = clipX; clipGridPtsVW[numClipGridPts + 1].y = y; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray horizLa = new LineArray(numPts, LineArray.COORDINATES); horizLa.setCoordinates(0, gridPts, 0, numPts); Shape3D horizShape = new Shape3D(horizLa, bgApp); objTrans.addChild(horizShape); // draw the clipped grid. if (numClipGridPts > 0) { LineArray clipLa = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLa.setCoordinates(0, clipGridPtsVW, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipGridLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLa, clipGridApp); objTrans.addChild(clipShape); } // set up the coordinate system Appearance coordSysApp = new Appearance(); LineAttributes coordSysLa = new LineAttributes(); coordSysLa.setLineWidth(3.0f); coordSysApp.setLineAttributes(coordSysLa); ColoringAttributes coordSysCa = new ColoringAttributes(grey, ColoringAttributes.SHADE_FLAT); coordSysApp.setColoringAttributes(coordSysCa); Point3f[] coordSysPts = new Point3f[4]; coordSysPts[0] = new Point3f(gridMinX, 0, -0.5f); coordSysPts[1] = new Point3f(gridMaxX, 0, -0.5f); coordSysPts[2] = new Point3f(0, gridMinY, -0.5f); coordSysPts[3] = new Point3f(0, gridMaxY, -0.5f); LineArray coordSysLines = new LineArray(4, LineArray.COORDINATES); coordSysLines.setCoordinates(0, coordSysPts); Shape3D coordSysShape = new Shape3D(coordSysLines, coordSysApp); objTrans.addChild(coordSysShape); // 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); int step = 360 / (numCirclePts - 1); for (int deg = 0; deg < 360; deg += step) { double angle = Math.toRadians(deg); circlePtsVW[deg / 10].x = sphereRadius * (float) Math.sin(angle); circlePtsVW[deg / 10].y = sphereRadius * (float) Math.cos(angle); circlePtsVW[deg / 10].z = -0.3f; } circlePtsVW[numCirclePts - 1].set(circlePtsVW[0]); 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, circlePtsVW); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
From source file:KeyNavigateTest.java
public boolean isCollision(Transform3D t3d, boolean bViewSide) { // get the translation t3d.get(m_Translation); // we need to scale up by the scale that was // applied to the root TG on the view side of the scenegraph if (bViewSide != false) m_Translation.scale(1.0 / getScale()); Vector3d mapSquareSize = getMapSquareSize(); // first check that we are still inside the "world" if (m_Translation.x < -FLOOR_WIDTH + mapSquareSize.x || m_Translation.x > FLOOR_WIDTH - mapSquareSize.x || m_Translation.y < -FLOOR_LENGTH + mapSquareSize.y || m_Translation.y > FLOOR_LENGTH - mapSquareSize.y) return true; if (bViewSide != false) // then do a pixel based look up using the map return isCollision(m_Translation); return false; }
From source file:ffx.ui.MainPanel.java
/** * Merge two or more selected FSystem Nodes into one FSystem node. There are * a few gotchas that need to be fixed//from w w w . ja va 2 s. co m * * @param nodesToMerge a {@link java.util.ArrayList} object. */ public void merge(ArrayList<MSNode> nodesToMerge) { ArrayList<MSNode> activeNodes = new ArrayList<MSNode>(); for (MSNode node : nodesToMerge) { if (node != null && !(node instanceof MSRoot)) { activeNodes.add(node); } } if (activeNodes.size() <= 1) { return; } // Set up a structure to hold the new system FFXSystem active = hierarchy.getActive(); File file = SystemFilter.version(hierarchy.getActive().getFile()); FFXSystem system = new FFXSystem(file, "Merge Result", active.getProperties()); system.setKeyFile(active.getKeyFile()); system.setKeywords(KeyFilter.open(active.getKeyFile())); // Fill arrays with the atoms and bonds from the systems to be combined ArrayList<Atom> mergedAtoms = new ArrayList<Atom>(); ArrayList<Bond> mergedBonds = new ArrayList<Bond>(); ArrayList<FFXSystem> systems = new ArrayList<FFXSystem>(); TransformGroup parentTransformGroup = null; FFXSystem parentSystem; Transform3D parentTransform3D = new Transform3D(); Vector3d parentPosition = new Vector3d(); Vector3d atomPosition = new Vector3d(); // TINKER Atom Numbers start at 1 int atomNum = 1; Vector3d zero = new Vector3d(0.0, 0.0, 0.0); for (MSNode m : activeNodes) { parentSystem = (FFXSystem) m.getMSNode(FFXSystem.class); if (parentSystem == null) { return; } if (!systems.contains(parentSystem)) { graphicsCanvas.updateSceneWait(parentSystem, false, true, RendererCache.ViewModel.WIREFRAME, false, null); systems.add(parentSystem); } // Move each atom into the global frame by applying the System // Transform to // relative atomic position parentTransformGroup = parentSystem.getOriginToRot(); parentTransformGroup.getTransform(parentTransform3D); parentTransform3D.get(parentPosition); parentTransform3D.setTranslation(zero); // parentTransform3D.setScale(1.0d); ArrayList<Atom> atoms = m.getAtomList(); ArrayList<ROLS> bonds = m.getBondList(); for (Atom atom : atoms) { atom.removeFromParent(); atom.setXYZIndex(atomNum++); mergedAtoms.add(atom); atom.getV3D(atomPosition); parentTransform3D.transform(atomPosition); atomPosition.add(parentPosition); atom.moveTo(atomPosition); } for (ROLS msm : bonds) { Bond bond = (Bond) msm; bond.removeFromParent(); mergedBonds.add((Bond) msm); } } for (FFXSystem sys : systems) { close(sys); } MergeFilter mergeFilter = new MergeFilter(system, mergedAtoms, mergedBonds); UIFileOpener fileOpener = new UIFileOpener(mergeFilter, this); if (fileOpenerThreads > 0) { fileOpener.setNThreads(fileOpenerThreads); } Thread thread = new Thread(fileOpener); thread.start(); }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/*w ww. j a va 2s . c o m*/ * * @param pt1 _more_ * @param xyz1 _more_ * @param xyz2 _more_ * @param actualPoint _more_ * @param animateMove _more_ */ protected void goTo(FlythroughPoint pt1, double[] xyz1, double[] xyz2, double[] actualPoint, boolean animateMove) { currentHeading = 180; if (actualPoint == null) { actualPoint = xyz2; } NavigatedDisplay navDisplay = viewManager.getNavigatedDisplay(); MouseBehavior mouseBehavior = navDisplay.getMouseBehavior(); double[] currentMatrix = navDisplay.getProjectionMatrix(); double[] aspect = navDisplay.getDisplayAspect(); try { if (pt1.getDescription() != null) { getHtmlView().setText(pt1.getDescription()); } else { getHtmlView().setText(""); } processReadout(pt1); float x1 = (float) xyz1[0]; float y1 = (float) xyz1[1]; float z1 = (float) xyz1[2]; float x2 = (float) xyz2[0]; float y2 = (float) xyz2[1]; float z2 = (float) xyz2[2]; double zoom = (pt1.hasZoom() ? pt1.getZoom() : getZoom()); if (zoom == 0) { zoom = 0.1; } double tiltx = (pt1.hasTiltX() ? pt1.getTiltX() : tilt[0]); double tilty = (pt1.hasTiltY() ? pt1.getTiltY() : tilt[1]); double tiltz = (pt1.hasTiltZ() ? pt1.getTiltZ() : tilt[2]); //Check for nans if ((x2 != x2) || (y2 != y2) || (z2 != z2)) { return; } if ((x1 != x1) || (y1 != y1) || (z1 != z1)) { return; } double[] m = pt1.getMatrix(); if (m == null) { m = new double[16]; Transform3D t = new Transform3D(); if (orientation.equals(ORIENT_UP)) { y2 = y1 + 100; x2 = x1; } else if (orientation.equals(ORIENT_DOWN)) { y2 = y1 - 100; x2 = x1; } else if (orientation.equals(ORIENT_LEFT)) { x2 = x1 - 100; y2 = y1; } else if (orientation.equals(ORIENT_RIGHT)) { x2 = x1 + 100; y2 = y1; } if ((x1 == x2) && (y1 == y2) && (z1 == z2)) { return; } Vector3d upVector; if (doGlobe()) { upVector = new Vector3d(x1, y1, z1); } else { upVector = new Vector3d(0, 0, 1); } //Keep flat in z for non globe Point3d p1 = new Point3d(x1, y1, z1); Point3d p2 = new Point3d(x2, y2, ((!getUseFixedZ() || doGlobe()) ? z2 : z1)); t.lookAt(p1, p2, upVector); t.get(m); EarthLocation el1 = navDisplay.getEarthLocation(p1.x, p1.y, p1.z, false); EarthLocation el2 = navDisplay.getEarthLocation(p2.x, p2.y, p2.z, false); Bearing bearing = Bearing.calculateBearing(new LatLonPointImpl(getLat(el1), getLon(el1)), new LatLonPointImpl(getLat(el2), getLon(el2)), null); currentHeading = bearing.getAngle(); double[] tiltMatrix = mouseBehavior.make_matrix(tiltx, tilty, tiltz, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0); m = mouseBehavior.multiply_matrix(tiltMatrix, m); if (aspect != null) { double[] aspectMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, aspect[0], aspect[1], aspect[2], 0.0, 0.0, 0.0); // m = mouseBehavior.multiply_matrix(aspectMatrix, m); } double[] scaleMatrix = mouseBehavior.make_matrix(0.0, 0.0, 0.0, zoom, 0.0, 0.0, 0.0); m = mouseBehavior.multiply_matrix(scaleMatrix, m); } currentPoint = pt1; location = currentPoint.getEarthLocation(); if (doGlobe()) { setPts(locationLine, 0, x1 * 2, 0, y1 * 2, 0, z1 * 2); // setPts(locationLine2, 0, x2 * 2, 0, y2 * 2, 0, z2 * 2); } else { setPts(locationLine, x1, x1, y1, y1, 1, -1); } RealTuple markerLocation = new RealTuple(RealTupleType.SpatialCartesian3DTuple, new double[] { x1, y1, z1 }); if (xyz1[0] != xyz2[0]) { Transform3D rotTransform; VisADGeometryArray marker = (VisADGeometryArray) getMarker().clone(); double rotx = 0; double roty = 0; double rotz = 0; rotz = -Math.toDegrees(Math.atan2(actualPoint[1] - xyz1[1], actualPoint[0] - xyz1[0])) + 90; if (doGlobe()) { Vector3d upVector = new Vector3d(x1, y1, z1); rotTransform = new Transform3D(); rotTransform.lookAt(new Point3d(x1, y1, z1), new Point3d(x2, y2, z2), upVector); Matrix3d m3d = new Matrix3d(); rotTransform.get(m3d); rotTransform = new Transform3D(m3d, new Vector3d(0, 0, 0), 1); rotTransform.invert(); // ShapeUtility.rotate(marker, rotTransform,(float)x1,(float)y1,(float)z1); ShapeUtility.rotate(marker, rotTransform); } else { double[] markerM = navDisplay.getMouseBehavior().make_matrix(rotx, roty, rotz, 1.0, 0.0, 0.0, 0.0); rotTransform = new Transform3D(markerM); ShapeUtility.rotate(marker, rotTransform); } locationMarker.setPoint(markerLocation, marker); } else { locationMarker.setPoint(markerLocation); } locationLine.setVisible(showLine); // locationLine2.setVisible(showLine); locationMarker.setVisible(showMarker); if (hasTimes && getShowTimes()) { DateTime dttm = pt1.getDateTime(); if (dttm != null) { viewManager.getAnimationWidget().setTimeFromUser(dttm); } } if (changeViewpointCbx.isSelected()) { if (animateMove) { navDisplay.animateMatrix(m, animationSpeed); } else { navDisplay.setProjectionMatrix(m); } } if (!Misc.equals(lastLocation, pt1.getEarthLocation())) { lastLocation = pt1.getEarthLocation(); EarthLocationTuple tuplePosition = new EarthLocationTuple(lastLocation.getLatitude(), lastLocation.getLongitude(), lastLocation.getAltitude()); doShare(ucar.unidata.idv.control.ProbeControl.SHARE_POSITION, tuplePosition); } } catch (NumberFormatException exc) { logException("Error parsing number:" + exc, exc); } catch (javax.media.j3d.BadTransformException bte) { try { navDisplay.setProjectionMatrix(currentMatrix); } catch (Exception ignore) { } } catch (Exception exc) { logException("Error", exc); if (animationWidget != null) { animationWidget.setRunning(false); } return; } }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
protected void moveCurrentObject() { Transform3D tr = null; updateCurrentModule();/*from w w w . j ava2 s . c o m*/ if (currentObject == null) return; transformingCurrentObject = !transformingCurrentObject; if (transformingCurrentObject) { System.out.println("start: " + externScale + "*" + mouseScale); if (parentFrame != null && parentFrame instanceof Display3DFrame) ((Display3DFrame) parentFrame).getTransformMenu().setText("transforming object"); tg = currentObject.getTransformObj(); pg = (OpenBranchGroup) tg.getParent(); ppg = (OpenBranchGroup) pg.getParent(); LocalToWindow ltw = new LocalToWindow(tg.getChild(0), canvas); ltw.update(); tr = ltw.getLocalToVworld(); float[] t = new float[16]; tr.get(t); for (int i = 0; i < t.length; i += 4) System.out.printf("%5.3f %5.3f %5.3f %5.3f %n", t[i], t[i + 1], t[i + 2], t[i + 3]); Matrix4f cltwMatrix = new Matrix4f(); tr.get(cltwMatrix); invLTW.invert(cltwMatrix); float[] row = new float[4]; System.out.println("inv"); for (int i = 0; i < 4; i++) { invLTW.getRow(i, row); System.out.printf("%5.3f %5.3f %5.3f %5.3f %n", row[0], row[1], row[2], row[3]); } ppg.removeChild(pg); tg.setTransform(tr); alternateRootObj.addChild(pg); transformedNode = TRANSFORMED_OBJECT; mouseRotate.setTransformGroup(tg); mouseTranslate.setTransformGroup(tg); mouseZoom.setTransformGroup(tg); } else { if (tg == null) return; System.out.println("end: " + externScale + "*" + mouseScale); LocalToWindow ltw = new LocalToWindow(tg.getChild(0), canvas); ltw.update(); tr = ltw.getLocalToVworld(); Matrix4f trMatrix = new Matrix4f(); tr.get(trMatrix); float[] t = new float[16]; tr.get(t); for (int i = 0; i < t.length; i += 4) System.out.printf("%5.3f %5.3f %5.3f %5.3f %n", t[i], t[i + 1], t[i + 2], t[i + 3]); Matrix4f objMatrix = new Matrix4f(); objMatrix.mul(invLTW, trMatrix); alternateRootObj.removeChild(pg); tr.set(objMatrix); tr.get(t); for (int i = 0; i < t.length; i += 4) System.out.printf("%5.3f %5.3f %5.3f %5.3f %n", t[i], t[i + 1], t[i + 2], t[i + 3]); tg.setTransform(tr); ppg.addChild(pg); moveScene(); } }