Collision between two BoundingBoxes

Aug 8, 2008 at 4:09 PM
Edited Aug 8, 2008 at 4:16 PM
Hi Community :-)
I have a few question or even more some problem to solve. I have a scene where i can navigate with an character through a world(both .fbx files). Whats the best way for collision detection in this case?I think that i have to test the BoundingBoxes of each mesh from the world with the BoundingBox of my model. Can i do this with the AABox in JigLibX.Geometry?I dunno because i think the BoundingBoxes of the worldmeshes are AA and these from my model are ObjectOrientated. Maby two screenshots could help:  picture_1 and picture_2. As you can see in the second Picture i could detect the collision with the XNA intersection method from BoundingBoxes-Class(fountain<->character). The 'big' BoundingBox around the character is not drawn and the three small ones is needed for game-relatet stuff so don't worry. Now i think i only have to give the two BoundingBoxes to JigLibX over the AABox Class right?
Another Question is relatet to picture 2. When i would implement it this way(with the smallest BoundingBoxes of each fence) i can't imagine that the character moves smooth along the fence. Maybe there is a complete othere solution for solving something?Perhabs triangle based-collision dectection is is this to 'expensive'?!I think so because the character mesh has ~6k polys!

I would be glad if someone could help me or give me some explainations :-)

Best regards,
Florian
Coordinator
Aug 8, 2008 at 8:07 PM
Use triangle based collison for the world. JigLibX uses an Octree to create the *static* triangleMesh. So you can have quite a few triangles. But the best way would be to have 2 meshs. One for graphics (very detailed) and one for Collisions. Thats how many industrial games do their collision. Use the Primitve classes to model your character (e.g. sphere for the head, capsule for the legs and box for the body...)

btw: nice screenshots!
Aug 8, 2008 at 9:51 PM
Thanks for your reply!
There isn't a sample in JigLibGame where u show how to work with the TriangleMesh class?Cause i can't figure out some....
Yes u're suggestion is quit good. So its near to my solution. At the moment is would be enough for the character when he has only one big box around i think. So i will test it with the AABox class because i have the minimum and the maximum from the BoundingBox.
Okay and what would u think is the best way for the world?Only TriangleMesh or also Boxes for the fences. I'm very unsure. Because with the TriangleMesh i can imagine that i 'only' have to push the vertices in the Octree and fine. With boxes i must define them each per each for single fencepart....not nice :-/

Another question related to your Octree. He 'only' handles triangles and can't be using, such as an Octree for Frustrum-Culling, to check if an object is near to another and only then the collision-detection starts?

I actually do some test and have a staticbox where other boxes falling on it. Could you please explain me short why the speed decreases when i scale the boxes bigger?I wondering about ;-)
Coordinator
Aug 9, 2008 at 10:45 AM
Edited Aug 9, 2008 at 10:46 AM
There is a triangleMesh in the demo! Do you want to use JigLibX for physics or for collisionDetection only?

>> Because with the TriangleMesh i can imagine that i 'only' have to push the vertices in the Octree and fine.

You have to push the vertices into the octree and everything IS fine!

>>Another question related to your Octree. He 'only' handles triangles and can't be using, such as an Octree for Frustrum-Culling, to check if an object is near to another and only then the collision-detection starts?

This is done in the CollisionSystem. You have different systems here: CollisionSystemBrute, CollisionSystemGrid and the CollisionSystemSAP. (SAP recommend, based on sweep-and-prune - Here)
The TriangleMesh can handle many triangles (I tested i with quite complex geometries). Your level should be no problem for the engine!


Aug 9, 2008 at 12:11 PM
Edited Aug 9, 2008 at 12:13 PM
Oh sry i will look again for the triangleMesh sample!
We're only like to use the CollisionDetection because we have written an small system for gravity so our character can jump and don't get through the ground. Okay last is really simple and only looks for a specific y-value. So finally we'll use JigLibX also to do that but first off all we would implement the collsionDectection.

It's nice to hear that this is done by the CollisionSystem. I will have a detailed look on these systems and when u say it should not be a problem for our world with triangleMesh i will do this implementation!

Again to my last question and again a screenshot ;-) box_scaling_problem
Okay my problem here in my first test is when i scale the boxes bigger the speed decreases a lot(on the screenshot its scaled bigger). The falling down speed and the collsion speed. When i scale them down to normal size and go near with the camera its runs nice and fast. What could i do?Because in my opinion i can't scale down the wolrd and the character.
Okay i think thats an question i can answer my self when i'm working a bit longer with JigLibX. Just 2 days for now ;-)

Anyway thanks for your advice :D


Aug 11, 2008 at 11:13 PM
Edited Aug 11, 2008 at 11:21 PM
It's me again....

I've implemented the world as an TriangleMesh and it's works great. All primitives like e.a. some boxes falling down collide everywhere correct. Nice so far....

Since yesterday i'm working on the character collision with just a simple box arround him. My problem is now that i don't get the collisionskin updated correct in relation where the body is. After some test this is just my speculation.....
This is the situation. When i now shoot some boxes on it everythink is fine. But when i execute box.Body.MoveTo(Position, World); to bring the box to the model nothing collides. Position and World are the properites of the character. If testet alot in my Update() to get the collisionskin to the new Position...just some:
1) box.CollisionSkin.ApplyLocalTransform(new JigLibX.Math.Transform(-(box.SetMass(1.0f)), Matrix.Identity));
2) box.CollisionSkin.ApplyLocalTransform(new JigLibX.Math.Transform(-(box.SetMass(1.0f)), World));
3) box.Body.Transform = new JigLibX.Math.Transform(box.Body.Position, box.Body.Orientation);
    JigLibX.Math.Transform test = box.Body.Transform;
    box.CollisionSkin.SetNewTransform(ref test);
    box.CollisionSkin.ApplyLocalTransform(test);
4) i also tried  box.Body.UpdatePosition(elapsed); and box.Body.UpdateVelocity(elapsed); between

I create the box in my character class. The box class  is like your BoxObject where i do same what you do in the constructor and i also have the same SetMass()!btw i'm correct that orientation is rotation?!

This is my World calculation for all models(i'm working with RoeEngine2). But i don't think that theres the problem!

public virtual Matrix World
        {
            get
            {
                if (this is IzPherePhysics)
                {
                    IzPherePhysics physicsObject = (IzPherePhysics)this;
                    if (physicsObject.Body != null && physicsObject.Body.CollisionSkin != null)
                    {
                        return Matrix.CreateScale(_scale) * physicsObject.Body.CollisionSkin.GetPrimitiveLocal(0).Transform.Orientation * physicsObject.Body.Orientation * Matrix.CreateTranslation(physicsObject.Body.Position);
                    }
                    else if (physicsObject.Body != null)
                    {
                        return Matrix.CreateScale(_scale) * physicsObject.Body.Orientation * Matrix.CreateTranslation(physicsObject.Body.Position);
                    }
                }
                return Matrix.CreateScale(_scale) * Matrix.CreateFromQuaternion(_rotation) * Matrix.CreateTranslation(_position);
            }
        }

I would be very glad if u or somebody else found a bit of time to help me :D
           


Coordinator
Aug 12, 2008 at 9:14 AM
Edited Aug 12, 2008 at 12:26 PM
Are you using the physic system of the engine?

I think you are doing easy things very complex. It's done in a few minutes. Add a capsule (or box) make it stand upright and write a controller for it, so it moves like a character. Than move that capsule somewhere with Body.MoveTo()  (for me it works, tested it a minute ago) and always move the charater to the capsule position. - Done.
Aug 12, 2008 at 12:40 PM
I think you are doing easy things very complex.

I think so too ;-)

Yes w're using the physics system otherwise the boxes would not falling down from the sky...

What do u mean with stand up right?I just scaled the box in the y-direction atm....

And with a controller u mean a class where i encapsulate the methods like AddWorldForce() oder AddBodyForce correct?!Maybe thats my problem because i dunno used this methods anyway!So if i'm correct that in this way i havent call ApplyLocalTransform on the collisionskin each frame?
btw it is important that i move the charater to the capsule or box position as u wrote and not inverse?I can't imagine...

and is it possible that u can upload/show me u're test or isn't it a seperate project?!

I hope i found sometime tomorrow to follow your advice with the controller...
Aug 16, 2008 at 3:58 PM
Edited Aug 16, 2008 at 4:07 PM
Hi noone i have to disturb you again...sry...

I've now implemented a controller and in the Update() i do a straight forward movemennt on the box with AddBodyForce();...it's just a test!The problem is when the box collides with the fence the box get invisible manytimes...not always. But when this happens the framerate decrease a lot for a moment too. What could be the problem?

btw it is important that i move the charater to the capsule or box position as u wrote and not inverse?I can't imagine...

i'm wrong and had a logical missunderstood...because when i will move the box to the position of the character there couldn't be a collsion because i set always a new position. So now its clear for me that i have to move the box and then set the position/orientation of the character ;-)