Collisions and size

charlie

29-01-2006 20:49:36

When I create a Collision I must specify the size vector. But I want the User to be able to specify any mesh and just state whether it's a box or sphere (I'm just interested in boxes and spheres as dynamic objects). So I acutally don't know the size and I haven't find a method to determine it. (Is there one?)

So what can I do to solve this problem? Is there any way to detect the size of my mesh or does ogrenewt this somehow by it's own?

haffax

29-01-2006 21:15:41

For boxes you can use the AABB of the mesh (Mesh::getBounds) and for a sphere you can use the radius (Mesh::getBoundingSphereRadius), or if you want the sphere to be an ellipsoid you can use the AABB too here (halfed on each axis)

charlie

30-01-2006 07:41:45

Ah, ok, thanks. I'll give it a try.
By the way: In ogreOde there was a TreeMesh for static Objects, which have a more complex form than boxes, cylinders and co. Is there something aquivalent in OgreNewt?

haffax

30-01-2006 09:13:11

Yes, its the TreeCollision in OgreNewt.

pfo

30-01-2006 17:57:43

Hey Charlie: if you want to specify the size of your entity, do this:

psuedocode:

get the bounding box of the entity
get the scale of its node
get the extent of the entity ((box.Max() - box.Min) * scale)
now, you need to get the scale necessary to set entity to 'size' (size is a Vector3), like this:

Vector3 scale = size / extent;

Now set the scale of the node and use that size to create your collision body. This is a much easier way of envisioning size of entity in a physics engine, rather than having to deal with some arbitrary node scale, this can calculate it for you.