Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
intersectsWithBox(box) is not working

bagg
Registered User
Quote
2010-12-08 07:12:45

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.


niko
Moderator
Quote
2010-12-08 08:26:56

Hm, the implementation looks right:


CL3D.Box3d.prototype.intersectsWithBox = function(box)
{
return this.MinEdge.X <= box.MaxEdge.X && this.MinEdge.Y <= box.MaxEdge.Y && this.MinEdge.Z <= box.MaxEdge.Z &&
this.MaxEdge.X >= box.MinEdge.X && this.MaxEdge.Y >= box.MinEdge.Y && this.MaxEdge.Z >= box.MinEdge.Z;
}


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.


bagg
Registered User
Quote
2010-12-08 10:26:20

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>


niko
Moderator
Quote
2010-12-08 13:26:37

Yes, I think the bounding box is simply not correct here. It's a bug.


bagg
Registered User
Quote
2010-12-09 13:22:33

Are you going to fix it soon because i can't go on without it ?


niko
Moderator
Quote
2010-12-09 16:02:38

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)

var yourFunction = function()
{
testbox.Pos.X=testbox.Pos.X+50;

testbox.updateAbsolutePosition();
testbox1.updateAbsolutePosition();

if (testbox.getTransformedBoundingBox().intersectsWithBox (testbox1.getTransformedBoundingBox()))
{
alert ('Found Collision');
}
}

Also note: You had an ';' after your if.


bagg
Registered User
Quote
2010-12-09 17:28:45

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.


niko
Moderator
Quote
2010-12-10 12:11:26

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.


bagg
Registered User
Quote
2010-12-10 12:43:47

At the above correction that you gave me if you replace the TransformedBoundingBox with BoundingBox it finds collision from the first click.


niko
Moderator
Quote
2010-12-11 06:46:06

Yes, because both boxes are in object space then. Then they overlap all the time, because both are at the origin.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internati?nal" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact