private static final String toString(final Transform3D t3d) { final float[] xf = new float[16]; t3d.get(xf); String ret = ""; for (int i = 0; i < 16; i++) ret += " " + xf[i]; return ret; }
public void setTransform(final Transform3D transform) { if (contentNode == null) return; final Transform3D t = new Transform3D(); final Point3d c = new Point3d(); contentNode.getCenter(c); final Matrix3f m = new Matrix3f(); transform.getRotationScale(m); t.setRotationScale(m); // One might thing a rotation matrix has no translational // component, however, if the rotation is composed of // translation - rotation - backtranslation, it has indeed. final Vector3d v = new Vector3d(); v.x = -m.m00 * c.x - m.m01 * c.y - m.m02 * c.z + c.x; v.y = -m.m10 * c.x - m.m11 * c.y - m.m12 * c.z + c.y; v.z = -m.m20 * c.x - m.m21 * c.y - m.m22 * c.z + c.z; t.setTranslation(v); localRotate.setTransform(t); final Vector3d v2 = new Vector3d(); transform.get(v2); v2.sub(v); t.set(v2); localTranslate.setTransform(t); }
/** * Retrieves the manual translation vector of the view. * * @param v */ public void getTranslateTranslation(final Vector3d v) { translateTG.getTransform(tmp); tmp.get(v); }
/** * Prints out the specified transform in a readable format. * * @param t3d transform to be printed * @param name the name of the transform */ private static void t3dPrint(Transform3D t3d, String name) { double[] m = new double[16] ; t3d.get(m) ; String[] sa = formatMatrixRows(4, 4, m) ; System.err.println(name) ; for (int i = 0 ; i < 4 ; i++) System.err.println(sa[i]) ; }
/** * Retrieves the translation vector which is responsible for centering the * view. * * @param v */ public void getCenterTranslation(final Vector3d v) { centerTG.getTransform(tmp); tmp.get(v); }
/** * Retrieves the translation vector which is responsible for the current * zooming and stores it in the given Vector3d. * * @param v */ public void getZoomTranslation(final Vector3d v) { zoomTG.getTransform(tmp); tmp.get(v); }
/** * Gets the physical to virtual scale. */ protected double getPhysicalToVirtualScale() { view.getCanvas3D(0).getImagePlateToVworld(t3dTmp) ; t3dTmp.get(m16Tmp) ; return Math.sqrt(m16Tmp[0]*m16Tmp[0] + m16Tmp[1]*m16Tmp[1] + m16Tmp[2]*m16Tmp[2]) ; }
/** * Gets the scale from physical units to view platform units. */ protected double getPhysicalToViewPlatformScale() { double vpToVirtualScale ; targetTG.getTransform(t3dTmp) ; t3dTmp.get(m16Tmp) ; vpToVirtualScale = Math.sqrt(m16Tmp[0]*m16Tmp[0] + m16Tmp[1]*m16Tmp[1] + m16Tmp[2]*m16Tmp[2]) ; return getPhysicalToVirtualScale() / vpToVirtualScale ; }
public void writeTransform3D( DataOutput out, Transform3D tran ) throws IOException { Matrix4d matrix = new Matrix4d(); tran.get( matrix ); writeMatrix4d( out, matrix ); }
static FastMatrix toFastMatrix(final Transform3D t3d) { final Matrix4d m = new Matrix4d(); t3d.get(m); return new FastMatrix(new double[][] { { m.m00, m.m01, m.m02, m.m03 }, { m.m10, m.m11, m.m12, m.m13 }, { m.m20, m.m21, m.m22, m.m23 } }); }
/** * Translates a coordinate system. * * @param transform the coordinate system to be translated * @param translation the vector by which to translate */ protected void translateTransform(Transform3D transform, Vector3d translation) { transform.get(v3dTmp) ; v3dTmp.add(translation) ; transform.setTranslation(v3dTmp) ; }
Transform3D transform = new Transform3D(); Vector3f position = new Vector3f(); yourObject.getLocalToVworld(transform); transform.get(position);
@Override public void writeObject( DataOutput out ) throws IOException { super.writeObject( out ); Transform3D trans = new Transform3D(); ((TransformGroup)node).getTransform( trans ); double[] matrix = new double[16]; trans.get( matrix ); for(int i=0; i<16; i++) out.writeDouble( matrix[i] ); }
@Override public void oked(final Matrix4f mat) { final Transform3D t = new Transform3D(mat); final float[] v = new float[16]; t.get(v); univ.setUseToFront(useToFront); record(APPLY_TRANSFORM, affine2string(v)); }
@Override public void oked(final Matrix4f mat) { final Transform3D t = new Transform3D(mat); final float[] v = new float[16]; t.get(v); univ.setUseToFront(useToFront); record(SET_TRANSFORM, affine2string(v)); }
/** * Transforms the target coordinate system about a center point. * This can be used for rotation and scaling. * * @param target the coordinate system to transform * @param center the center point about which to transform * @param transform the transform to apply */ protected void transformAboutCenter (Transform3D target, Point3d center, Transform3D transform) { // Translate to the center. target.get(v3dTmp) ; v3dTmp.sub(center) ; target.setTranslation(v3dTmp) ; // Apply the transform. target.mul(transform, target) ; // Translate back. target.get(v3dTmp) ; v3dTmp.add(center) ; target.setTranslation(v3dTmp) ; }
/** * Reset the orientation and distance of this behavior to the current * values in the ViewPlatform Transform Group */ private void resetView() { Vector3d centerToView = new Vector3d(); targetTG.getTransform( targetTransform ); targetTransform.get( rotMatrix, transVector ); centerToView.sub( transVector, rotationCenter ); distanceFromCenter = centerToView.length(); startDistanceFromCenter = distanceFromCenter; targetTransform.get( rotMatrix ); rotateTransform.set( rotMatrix ); // compute the initial x/y/z offset temp1.set(centerToView); rotateTransform.invert(); rotateTransform.mul(temp1); rotateTransform.get(centerToView); xtrans = centerToView.x; ytrans = centerToView.y; ztrans = centerToView.z; // reset rotMatrix rotateTransform.set( rotMatrix ); }
public void updateFrontBackClip() { zoomTG.getTransform(zoomXform); zoomXform.get(zDir); final double d = zDir.length(); univ.getViewer().getView().setBackClipDistance(5 * d); univ.getViewer().getView().setFrontClipDistance(5 * d / 100); }
public void saveTransform(final Content c) { if (!checkSel(c)) return; final Transform3D t1 = new Transform3D(); c.getLocalTranslate().getTransform(t1); final Transform3D t2 = new Transform3D(); c.getLocalRotate().getTransform(t2); t1.mul(t2); final float[] matrix = new float[16]; t1.get(matrix); if (new TransformIO().saveAffineTransform(matrix)) record(SAVE_TRANSFORM, affine2string(matrix)); }
public void writeObject( DataOutput out ) throws IOException { MultiTransformGroup mtg = universe.getViewingPlatform().getMultiTransformGroup(); int mtgSize = mtg.getNumTransforms(); out.writeInt( mtgSize ); // Store the matrix from each MTG transform Transform3D trans = new Transform3D(); Matrix4d matrix = new Matrix4d(); for(int i=0; i<mtgSize; i++) { TransformGroup tg = mtg.getTransformGroup( i ); tg.getTransform( trans ); trans.get( matrix ); control.writeMatrix4d( out, matrix ); } control.writeObject( out, control.createState( universe.getViewingPlatform().getPlatformGeometry() )); control.writeObject( out, control.createState( universe.getViewer().getAvatar() )); writeLocales( out ); }