Hello everyone, I am having some problems implementing my collision avoidance system for my school project. I hope someone might help me or light things out.
This is the situation: I have some QuadArrays, 8 to be exact, that form an octogonal shape. The shape, these QuadArrays define, represent the walls of the arene where multiple avatars would move around. Up to there everything seems to go right. The problem comes up when I do picking base on the BoundingBox of any of those QuadArrays. The BoundingBox of the QuadArrays seems to be all perpendicular to the axis (x, z) and they take too much space, thus the picking results always in a collision eventhough I might be 15mts away from the actual shape(QuadArray/Wall). I tried redefining the upper and lower points of the corresponding BoundingBoxes of all QuadArrays, so that they should be aligned just the way the QuadArrays are aligned -remember that every Quad is aligned so that they altogether will define an octogon-, but this just makes my Quads to disappear. I have written a simple and independent class that illustrates this. The code is at the end of the message. My question is : how can/must I define these BoundingBoxes so that they are aligned the same way as the QuadArrays and that they take just the same dimensions/space as the Quads, maybe with some extra centimeters. Any tips, help or advice is welcomed. Many thanks in advance. ========================================================================== Code starts here ========================================================================== import java.awt.*; import java.awt.event.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; public class quadArray extends Frame implements ActionListener { protected Canvas3D displayCanvas; protected SimpleUniverse myVWorld; protected Shape3D theShape; protected Button Quit; protected Button ShowBounds; protected Button AdjustBounds; public quadArray() { displayCanvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration ()); myVWorld = new SimpleUniverse(displayCanvas); Quit = new Button("Quit"); ShowBounds = new Button("Show Bounds"); AdjustBounds = new Button("Adjust Bounds"); Quit.addActionListener(this); ShowBounds.addActionListener(this); AdjustBounds.addActionListener(this); this.setLayout(new BorderLayout()); this.add("Center", displayCanvas); Panel ButtonsPanel = new Panel(); ButtonsPanel.setLayout(new GridLayout(1, 3)); ButtonsPanel.add(ShowBounds); ButtonsPanel.add(AdjustBounds); ButtonsPanel.add(Quit); this.add("South", ButtonsPanel); QuadArray theQuad = new QuadArray(4, QuadArray.COORDINATES); theQuad.setCoordinate(0, new Point3f(1.0f, 0.0f, 0.0f)); theQuad.setCoordinate(1, new Point3f(0.0f, 0.0f, -1.0f)); theQuad.setCoordinate(2, new Point3f(0.0f, 1.0f, -1.0f)); theQuad.setCoordinate(3, new Point3f(1.0f, 1.0f, 0.0f)); Appearance theApp = new Appearance(); Material mat = new Material(new Color3f(0.2f, 0.2f, 0.2f), new Color3f(0.0f, 0.0f, 0.5f), new Color3f(1.0f, 1.0f, 1.0f), new Color3f(0.0f, 0.0f, 0.9f), 80.0f); PolygonAttributes polyAttr = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f); theApp.setMaterial(mat); theApp.setPolygonAttributes(polyAttr); theShape = new Shape3D(theQuad, theApp); theShape.setCapability(Shape3D.ALLOW_BOUNDS_READ); theShape.setCapability(Shape3D.ALLOW_BOUNDS_WRITE); theShape.setCapability(Shape3D.ALLOW_COLLISION_BOUNDS_READ); theShape.setCapability(Shape3D.ALLOW_COLLISION_BOUNDS_WRITE); theShape.setCapability(Shape3D.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE); PointLight sunLight = new PointLight(new Color3f(0.9f, 0.9f, 0.9f), new Point3f(0.0f, 1.0f, 1.0f), new Point3f(1.5f, 0.0f, 0.0f)); BoundingSphere inflZone = new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 100.0f); sunLight.setInfluencingBounds(inflZone); TransformGroup trGrp = new TransformGroup(); trGrp.addChild(theShape); trGrp.addChild(sunLight); BranchGroup brGrp = new BranchGroup(); brGrp.addChild(trGrp); myVWorld.getLocale().addBranchGraph(brGrp); Transform3D tr3D = new Transform3D(); tr3D.setTranslation(new Vector3f(0.0f, 0.0f, 3.0f)); myVWorld.getViewingPlatform(). getViewPlatformTransform().setTransform(tr3D); this.setSize(400, 600); this.setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand() == "Quit") { this.dispose(); System.exit(0); } if(e.getActionCommand() == "Show Bounds") { System.out.println("Bounds : " + theShape.getBounds()); System.out.println("Collision Bounds: " + theShape.getCollisionBounds ()); } if(e.getActionCommand() == "Adjust Bounds") { BoundingBox bb = new BoundingBox(new Point3d(-0.10d, 0.0d, 0.0d), new Point3d(0.10d, 1.0d, -Math.sqrt (2.0d))); Transform3D tr3D = new Transform3D(); tr3D.rotY(Math.PI/4); tr3D.setTranslation(new Vector3f(1.0f, 0.0f, 0.0f)); bb.transform(tr3D); theShape.setBoundsAutoCompute(false); theShape.setBounds(bb); theShape.setCollisionBounds(bb); System.out.println("Bounds values changed"); System.out.println("Bounds : " + theShape.getBounds()); System.out.println("Collision Bounds: " + theShape.getCollisionBounds ()); } } public static void main(String[] _args) { quadArray quad = new quadArray(); } } ========================================================================== Code stops here ========================================================================== =========================================================================== 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".