/** * 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(); transform.rotZ(Math.PI); transform.setTranslation(vector); univ.getViewingPlatform().getViewPlatformTransform().setTransform(transform);
public void setTranslation(final float dx, final float dy, final float dz) { final Transform3D t = new Transform3D(); t.setTranslation(new Vector3f(dx, dy, dz)); setTransform(t); }
public void setPosition(final float x, final float y) { this.x = x; this.y = y; final Transform3D p = new Transform3D(); p.setTranslation(new Vector3f(x, y, 0.0f)); positionTG.setTransform(p); }
public void applyTranslation(final float dx, final float dy, final float dz) { final Transform3D t = new Transform3D(); t.setTranslation(new Vector3f(dx, dy, dz)); applyTransform(t); }
/** * 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) ; }
/** * Computes the new transform for this interpolator for a given * alpha value. * * @param alphaValue alpha value between 0.0 and 1.0 * @param transform object that receives the computed transform for * the specified alpha value * * @since Java 3D 1.3 */ @Override public void computeTransform(float alphaValue, Transform3D transform) { double val = (1.0-alphaValue)*startPosition + alphaValue*endPosition; // construct a Transform3D from: axis * translation * axisInverse transv.set(val, 0.0, 0.0); translation.setTranslation(transv); transform.mul(axis, translation); transform.mul(transform, axisInverse); }
TransformGroup translate(Node node,Vector3f vector){ Transform3D transform3D = new Transform3D(); transform3D.setTranslation(vector); TransformGroup transformGroup = new TransformGroup(); transformGroup.setTransform(transform3D); transformGroup.addChild(node); return transformGroup; } for(int i=0;vec[i];i++) translate(Your_Object,new Vector3f(x,y,vec[i]); //do this while you still have elements in your vector. //you may want to set a value, let's say 2500 that indicates that you ran out of objects //in that case, you will have for(int i=0;vec[i]!=2500;i++)
PlatformGeometry pg = new PlatformGeometry(); TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(0f, 0f, -1f)); objScale.setTransform(t3d); Text2D text = new Text2D("Text to display", Cell.BLACK, "Verdana", 18, 1); objScale.addChild(text); pg.addChild(objScale); simpleUniverse.getViewingPlatform().setPlatformGeometry(pg);
TransformGroup moveGroup = new TransformGroup(); Transform3D move = new Transform3D(); move.setTranslation(new Vector3f(0.0f, 0.0f, -10.0f)); //^^ set the Vector3f to where you want the object to be moveGroup.setTransform(move); moveGroup.addChild(YOUR_OBJECT);
TransformGroup getNewBox(float hpos) { Cuboid box = new Cuboid(0.03f, 0.03f, 0.03f, cubeAppearance); TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Vector3f vector = new Vector3f(0f, hposf, 0f); transform.setTranslation(vector); tg.addChild(box); tg.setTransform(transform); return tg; } { rootGroup.addChild(getNewBox(0f); rootGroup.addChild(getNewBox(0.3f); rootGroup.addChild(getNewBox(0.6f); rootGroup.addChild(getNewBox(0.9f); }
TransformGroup tg2 = new TransformGroup (); //set the appearance of the product boxes (transparent) Appearance app = new Appearance(); app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED,0.2f)); //create a box having length = l, breadth = b and height = h Box box = new Box( (float )item[p].getLength(), (float) item[p].getBreadth(), (float) item[p].getHeight(), app); // vector to translate the item box to the position (x, y, z) Vector3f position = new Vector3f((float) x, (float) y, (float) z); //creation of a 3D transform group Transform3D transform = new Transform3D(); transform.setTranslation(position); tg2.setTransform(transform); //add new item box to the transform group tg2.addChild(box); tg2.setCapability(Group.ALLOW_CHILDREN_EXTEND); BranchGroup scene = new BranchGroup(); scene.addChild(tg2); scene1.addChild(scene);
public void setLength(final float l) { this.length = l; lineShape.setGeometry(createLineGeometry()); textShape.setGeometry(createTextGeometry()); final Transform3D d = new Transform3D(); d.setTranslation(new Vector3f(length / 2, -length / 2, 0.0f)); textTG.setTransform(d); }
// The transform group that moves the cube TransformGroup tgThatMovesTheCube = new TransformGroup(); tgThatMovesTheCube .addChild(new ColorCube(0.4)); // The transform group that "attaches" the sphere to the cube: TransformGroup tgThatAttachesTheSphere = new TransformGroup(); tgThatAttachesTheSphere.addChild(new Sphere(...)); // The transform of this transform group: It is a transform // that moves the sphere (from its original position) to // one side of the cube (at its original position) Transform3D attachingTransform = new Transform3D(); attachingTransform.setTranslation(new Vector3f(1,0,0)); tgThatAttachesTheSphere.setTransform(attachingTransform); // Attach the transformed (!) sphere to the same TG as the cube: tgThatMovesTheCube.addChild(tgThatAttachesTheSphere);
private void computeCompositeTransform() { ViewPlatform vp; if ((canvas3d == null) || (canvas3d.view == null) || (((vp = canvas3d.view.getViewPlatform()) == null)) || (((ViewPlatformRetained)(vp.retained)) == null)) { compTransform.set(modelTransform); return; } ViewPlatformRetained vpR = (ViewPlatformRetained)vp.retained; if ((vpR == null) || (vpR.locale == null)) { compTransform.set(modelTransform); return; } HiResCoord localeHiRes = vpR.locale.hiRes; if (localeHiRes.equals(hiRes)) { compTransform.set(modelTransform); } else { Transform3D trans = new Transform3D(); Vector3d localeTrans = new Vector3d(); localeHiRes.difference( hiRes, localeTrans ); trans.setTranslation( localeTrans ); compTransform.mul(trans, modelTransform); } }
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); }
public void addVertex(Image3DUniverse univ, Color3f color, float x, float y, float z) { BranchGroup bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(x, y, z)); tg.setTransform(t3d); bg.addChild(tg); Appearance app = new Appearance(); ColoringAttributes cattr = new ColoringAttributes(); cattr.setColor(color); app.setColoringAttributes(cattr); tg.addChild(new Sphere(0.1f, app)); univ.getScene().addChild(bg); }
private void addText(final String s, final Point3f pos, final float fontsize, final Color3f c) { final Transform3D translation = new Transform3D(); translation.rotX(Math.PI); translation.setTranslation(new Vector3f(pos)); final TransformGroup tg = new TransformGroup(translation); final OrientedShape3D textShape = new OrientedShape3D(); textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); textShape.setRotationPoint(new Point3f(0, 0, 0)); textShape.setConstantScaleEnable(true); final Text2D t2d = new Text2D(s, c, "Helvetica", 24, Font.PLAIN); t2d.setRectangleScaleFactor(0.03f); textShape.setGeometry(t2d.getGeometry()); textShape.setAppearance(t2d.getAppearance()); tg.addChild(textShape); addChild(tg); }
public Scalebar(final float length) { final Transform3D position = new Transform3D(); positionTG = new TransformGroup(position); positionTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); positionTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); addChild(positionTG); lineShape = new Shape3D(); lineShape.setGeometry(createLineGeometry()); lineShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); positionTG.addChild(lineShape); final Transform3D texttranslate = new Transform3D(); texttranslate.setTranslation(new Vector3f(length / 2, -length / 2, 0.0f)); textTG = new TransformGroup(texttranslate); textTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); positionTG.addChild(textTG); textShape = new OrientedShape3D(); textShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); textShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); textShape.setGeometry(createTextGeometry()); textShape.setAppearance(createTextAppearance()); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); textTG.addChild(textShape); }
private void addText(final Group bg, final String s, final Point3f pos, final Color3f c) { final Transform3D translation = new Transform3D(); translation.setTranslation(new Vector3f(-radius, -radius, 0)); final TransformGroup tg = new TransformGroup(translation); final Text2D t2d = new Text2D(s, c, "Helvetica", 24, Font.PLAIN); t2d.setRectangleScaleFactor(0.03f); final Geometry g = t2d.getGeometry(); final Appearance a = t2d.getAppearance(); final RenderingAttributes ra = new RenderingAttributes(); ra.setDepthTestFunction(RenderingAttributes.ALWAYS); a.setRenderingAttributes(ra); g.setCapability(Geometry.ALLOW_INTERSECT); final OrientedShape3D textShape = new OrientedShape3D(); textShape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); textShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); textShape.setRotationPoint(new Point3f()); textShape.setConstantScaleEnable(true); textShape.setGeometry(g); textShape.setAppearance(a); tg.setCapability(ENABLE_PICK_REPORTING); tg.setPickable(true); tg.addChild(textShape); bg.addChild(tg); }