I'm currently working on modelling a robot in Java3D, but Cylinders are currently giving me some trouble at the moment. I've added a box with height 325, and two cylinders height 325, then several translations are applied to them to put them in different positions. Finally, the whole thing is scaled right down (0.0001 * the size). However, visually, the box looks about double the height of the cylinder, and when I multiply the cylinder's radius and height by two, it is exactly the right size...
Has anyone got any idea why this might be happening? Below is the code. The cylinders (firstCyl, secondCyl) can be found at the lines marked ***** and the box that I was comparing it (sb) to can be found at &&&&& This problem also seems to affect a couple of the translations that I've been using (float separation is set as 1000, however when the secondCyl is translated that far away from the firstCyl it only seems to move 500). I've tried moving the cylinders between different transform groups, but nothing seems to help: has anyone got any ideas? Thankyou for your time Andy Dunmore package myUniverse; import java.awt.BorderLayout; import java.awt.Container; import java.awt.GraphicsConfiguration; import javax.media.j3d.Appearance; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.ColoringAttributes; import javax.media.j3d.DirectionalLight; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.swing.JFrame; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.Box; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.geometry.Cylinder; import com.sun.j3d.utils.universe.SimpleUniverse; public class testUni extends JFrame{ public testUni() { // Create the universe and the window for it to go in. super("MyUniverse"); setSize(600,600); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config, false); pane.add("Center", canvas); SimpleUniverse universe = new SimpleUniverse(canvas); // Create a structure to contain objects BranchGroup root = new BranchGroup(); //measurements for the robot's body. final int bodyWidth = 1225; //(12.25 inches) final int bodyHeight = 2800; //(28 inches) final int bodyDepth = 975; //(9.75 inches) Appearance bodyAppearance = new Appearance(); Color3f bodyColor = new Color3f(0.9f, 0.9f, 0.9f); ColoringAttributes bodyColorer = new ColoringAttributes (bodyColor, ColoringAttributes.FASTEST); bodyAppearance.setColoringAttributes(bodyColorer); Box body = new Box(bodyWidth, bodyHeight, bodyDepth, bodyAppearance); Transform3D positionBody = new Transform3D(); Vector3d bodyTranslator = new Vector3d (bodyWidth,bodyHeight,bodyDepth); positionBody.setTranslation(bodyTranslator); TransformGroup bodyGroup = new TransformGroup(positionBody); bodyGroup.addChild(body); //measurements for the zed component final int zedHeight = 4750; final int zedDepth = 325; final int zedWidth = 525; Appearance zedAppearance = new Appearance(); Color3f zedColor = new Color3f(0.4f, 0.4f, 0.4f); //Color3f zedColor = new Color3f(0.2f, 0.2f, 0.2f); // darker more realistic colour ColoringAttributes zedColorer = new ColoringAttributes (zedColor, ColoringAttributes.FASTEST); zedAppearance.setColoringAttributes(zedColorer); Box zed = new Box(zedWidth, zedHeight, zedDepth, zedAppearance); Transform3D positionZed = new Transform3D(); int protrudingAboveBody = 1950; Vector3d zedTranslator = new Vector3d(bodyWidth,bodyHeight+ protrudingAboveBody,1.8*bodyDepth); positionZed.setTranslation(zedTranslator); TransformGroup zedGroup = new TransformGroup(positionZed); zedGroup.addChild(zed); // Measurements for the shoulder box (sb) final int sbHeight = 325; final int sbDepth = 325; final int sbWidth = 735; Appearance sbAppearance = new Appearance(); Color3f sbColor = new Color3f(0.7f, 0.6f, 0.5f); ColoringAttributes sbColorer = new ColoringAttributes (sbColor, ColoringAttributes.FASTEST); sbAppearance.setColoringAttributes(sbColorer); Box sb = new Box(sbWidth, sbHeight, sbDepth, sbAppearance); // &&&&& Transform3D positionSb = new Transform3D(); Vector3d sbTranslator = new Vector3d (2*zedWidth,1.2*zedHeight,2*bodyDepth+400); positionSb.setTranslation(sbTranslator); TransformGroup sbGroup = new TransformGroup(positionSb); sbGroup.addChild(sb); // upper-arm bone final float scRadius = 200; final float scHeight = 325; final float elRadius = 200; final float elHeight = 325; final float separation = 1000; // 10 inches separation final float boneHeight = 150; final float boneDepth = 375; final float boneWidth = 1000; Appearance uaAppearance = new Appearance(); Color3f uaColor = new Color3f(0.4f, 0.5f, 0.2f); ColoringAttributes uaColorer = new ColoringAttributes (uaColor, ColoringAttributes.FASTEST); uaAppearance.setColoringAttributes(uaColorer); Cylinder firstCyl = new Cylinder(scRadius, scHeight, uaAppearance); // ***** Cylinder secondCyl = new Cylinder(elRadius, elHeight, uaAppearance); // ***** Box uaBone = new Box(boneWidth, boneHeight, boneDepth, uaAppearance); Transform3D positionCyl = new Transform3D(); Transform3D positionBone = new Transform3D(); Vector3d cylTranslation = new Vector3d(separation,0,0); Vector3d boneTranslation = new Vector3d(separation,50,0); positionCyl.setTranslation(cylTranslation); positionBone.setTranslation(boneTranslation); TransformGroup cylTransform = new TransformGroup (positionCyl); TransformGroup boneTransform = new TransformGroup (positionBone); cylTransform.addChild(secondCyl); boneTransform.addChild(uaBone); Transform3D positionUa = new Transform3D(); Vector3d uaTranslator = new Vector3d (2*zedWidth,zedHeight,2*bodyDepth+500); positionUa.setTranslation(uaTranslator); TransformGroup uaGroup = new TransformGroup(positionUa); //Box testSb = new Box(sbWidth, sbHeight, sbDepth, sbAppearance); uaGroup.addChild(firstCyl); uaGroup.addChild(boneTransform); uaGroup.addChild(cylTransform); //uaGroup.addChild(testSb); System.out.println(secondCyl.getRadius()); //try moving the cylinders to a higher level group and seeing if they //change size. otherwise map out the branchtree and see if there is an //error there. // scale the whole robot to a viewable size. Transform3D transform = new Transform3D(); Transform3D scaler = new Transform3D(); Transform3D tempRotate = new Transform3D(); //transform.rotX(Math.PI/4d); //tempRotate.rotY(Math.PI/4d); Vector3d scaleFactor = new Vector3d(0.0001,0.0001,0.0001); //scaler.setScale(0.0001); //transform.mul(tempRotate); transform.setScale(scaleFactor); //transform.mul(scaler); TransformGroup transformation = new TransformGroup (transform); //Construct the tree transformation.addChild(bodyGroup); transformation.addChild(zedGroup); transformation.addChild(sbGroup); transformation.addChild(uaGroup); root.addChild(transformation); // Create a red light that shines for 100m from the origin Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, - 12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); root.addChild(light1); Cylinder testCyl = new Cylinder(scRadius, 5*scHeight, uaAppearance); sbGroup.addChild(testCyl); // create a sphere centred at 0,0,0 for measuring purposes. Sphere sphere = new Sphere(0.04f); //root.addChild(sphere); //Look towards the robot //universe.getViewingPlatform().setNominalViewingTransform (); // Normal way of setting up viewing platform Transform3D T3D = new Transform3D(); Vector3d translateCamera = new Vector3d(); TransformGroup vpTrans = universe.getViewingPlatform ().getViewPlatformTransform(); //double angleX = Math.PI/4; T3D.rotX(angleX); //double angleY = Math.PI/4; T3D.rotY(angleY); //double angleZ = Math.PI/4 T3D.rotZ(angleZ); double x = 0.15; double y = 0.6; double z = 2; translateCamera.set(x,y,z); T3D.setTranslation(translateCamera); vpTrans.setTransform(T3D); // add the group of objects to the Universe //root.compile(); //What Does this DO??? universe.addBranchGraph(root); // add a window listener to terminate the program when the window closes. addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing (java.awt.event.WindowEvent evt) {System.exit(0);} } ); } public static void main(String[] args) { new testUni().show(); } } =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".