Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi Niko. I have a problem with collision between bounding boxes.I have two cubescenenodes and when i am trying to detect a collision detection between their bounding boxes it finds collision even if there is no collision between them.I am sure that the bounding boxes are right (they are just two cubes with size 200).The problem exists for both getBoundingBox and getTransformedBoundingBox.Can you check if there is a bug? And another thing.It could be very usefull if we could take the children of a scenenode with a function sceneNode.getChildren instead of parsing all sceneNodes in a scene in order to find if they have a specific Parent. |
||||
|
Hm, the implementation looks right:
Did you look into the boxes and see if their values are correct? About the children: You are right. You could also use sceneNode.Children (it's an array) to get this, although it's not documented. |
||||
|
Just Check this code out.(It's not running in firefox 4 beta 7) use chrome It alerts collision found with first click!!! <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="copperlicht.js"></script> </head> <body> <div align="center"> <b>Tutorial 03: Showing how to create your own scene node.</b><br/> <canvas id="3darea" width="1024" height="768" style="background-color:000000"> </canvas> </div> <script type="text/javascript"> <!-- main = function() { // create the 3d engine var engine = new CL3D.CopperLicht('3darea'); if (!engine.initRenderer()) return; // this browser doesn't support WebGL // add a new 3d scene var scene = new CL3D.Scene(); engine.addScene(scene); scene.setBackgroundColor(CL3D.createColor(1, 204, 232, 249)); var testbox = new CL3D.CubeSceneNode(200); engine.getScene().getRootSceneNode().addChild(testbox); testbox.Pos.X = -300; // set material texture of the cube: testbox.getMaterial(0).Tex1 = engine.getTextureManager().getTexture("test.jpg", true); testbox.updateAbsolutePosition(); var testbox1 = new CL3D.CubeSceneNode(200); engine.getScene().getRootSceneNode().addChild(testbox1); testbox1.Pos.X = 300; // set material texture of the cube: testbox1.getMaterial(0).Tex1 = engine.getTextureManager().getTexture("test.jpg", true); testbox1.updateAbsolutePosition(); var yourFunction = function() { testbox.Pos.X=testbox.Pos.X+50; if (testbox.getBoundingBox().intersectsWithBox(testbox1.getBoundingBox())); {alert ('Found Collision');} } var animator = new CL3D.Animator(engine.getScene(), engine, yourFunction); testbox.addAnimator(animator); // add a user controlled camera with a first person shooter style camera controller var cam = new CL3D.CameraSceneNode(); cam.Pos.X = 0; cam.Pos.Y = 0; cam.Pos.Z = -800; scene.getRootSceneNode().addChild(cam); scene.setActiveCamera(cam); } main(); --> </script> </body> </html> |
||||
|
Yes, I think the bounding box is simply not correct here. It's a bug. |
||||
|
Are you going to fix it soon because i can't go on without it ? |
||||
|
I just took a look into it, and I think CopperLicht is correct. I think your boxes simply have not been updated. Simply change your code to this: Change 'yourfunction' to something like this: (I didn't test it, but this is more closer, I guess)
Also note: You had an ';' after your if. |
||||
|
Ok you are right but this only works with transformed bounding boxes.What if i want the exact dimensions (bounding boxes not transformed bounding boxes)? Thanks. |
||||
|
Not sure what you mean by this. Either you have the transformed axis aligned boxes with the position of the scene node or the bounding boxes in the object space which is not transformed. You can use both. |
||||
|
At the above correction that you gave me if you replace the TransformedBoundingBox with BoundingBox it finds collision from the first click. |
||||
|
Yes, because both boxes are in object space then. Then they overlap all the time, because both are at the origin. |
|