Raycasting against movable GImpactMeshShape, is it possible?

tunnuz
Posts: 11
Joined: Wed Dec 01, 2010 8:37 am

Raycasting against movable GImpactMeshShape, is it possible?

Post by tunnuz »

Hello, I have found this Erwin reply to this topic:
In all cases I recommend to just stick with Bullet's collision detection: Bullet doesn't use GIMPACT by default, it is just an optional extension.
But I can't understand if is it possible to do raycasting against moving GImpactMeshShape or not. Any ideas?

Thank you
Tunnuz
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by Flix »

Yes, raycasting should work. (I use a "raycast panel" inside my simulations, on which I can display raytrace screenshots, and I can see Gimpact shapes too inside it).
tunnuz
Posts: 11
Joined: Wed Dec 01, 2010 8:37 am

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by tunnuz »

And it is sufficient to set the btCollisionObject transform to move the shape to its position?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by Flix »

tunnuz wrote:And it is sufficient to set the btCollisionObject transform to move the shape to its position?
Mmmhhh, what do you mean exactly?

From your post it seems you're using plain btCollisionObjects (i.e. without motionState and btRigidBody) and you can't move them correctly if they use a GImpact shape. Do you mean that ?

I've never tried it (I thought you could use GImpact shapes both with btRigidBody and btCollisionObject like all the other Bullet shapes).
If this is true, maybe GImpact shapes can't be moved when they are set to static btRigidBody or plain btCollisionObjects: it would be an issue for people using only libBulletCollision without libBulletDynamics...
tunnuz
Posts: 11
Joined: Wed Dec 01, 2010 8:37 am

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by tunnuz »

Flix wrote: From your post it seems you're using plain btCollisionObjects (i.e. without motionState and btRigidBody) and you can't move them correctly if they use a GImpact shape. Do you mean that ?
Exactly. I am using libBulletCollision to represent a 3D scene and do ray-casting on objects. In this scene I represent my objects with (btCollisionObjects with) btBvhTriangleMeshShapes if they are static and btGImpactMeshShapes if they are dynamic. Dynamic objects can move around and I want to do ray-casting correctly on them considering their real position (I have a shape for each object, no shared shapes). For instance, to get their AABB (note: this has nothing to do with ray-casting) I am doing:

Code: Select all

mObject->setWorldTransform( btTransform ( newOrientation, newPosition ) );
mObject->activate( true );	
Which only works for my GImpact mesh shapes, and that's nice since my triangle mesh shapes are static and I don't need to update their AABB. Thus, I would like to do the same for ray-casting: update shape position, raycast. However as far as I know the code above doesn't "move" the shape since it doesn't have a "position". How to do that?

Thank you
Tunnuz
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by Flix »

Flix wrote:However as far as I know the code above doesn't "move" the shape since it doesn't have a "position". How to do that?
Wait a minute.

Shapes cannot be moved. They can be shared by multiple rigid bodies/collision objects (but in case they're deformable it's usually better to keep a shape per object). The transform belongs to the object/body, not to the shape.

When you do raycasting you can do it in different ways (see the appRaytracer demo); you may try to change the way you do it.
You may also try to replicate the behaviour you're seeing in this demo http://bulletphysics.org/Bullet/phpBB3/ ... =raytracer: it uses a btCollisionWorld like in your base code (maybe the default Bullet demo does the same...).

Basically what I'm trying to say is that:
1) You may be right. Maybe GImpact shapes in collision worlds can't be moved correctly (or by moving them raycast somehow breaks). In that case you may try to use btBvhTriangleMeshShapes only and see if it works...
2) You may be wrong and you did not move/raycast correctly.
I'm feeling too lazy to check it myself, sorry :oops:

P.S. Maybe you can try to manually update the AABB of the (GImpact) body after you've moved it.
P.S.2. It should be the default, but try setting:

Code: Select all

world->setForceUpdateAllAabbs(true);
(There is a method to manually update the aabb per object too, but I can't find it right now).
tunnuz
Posts: 11
Joined: Wed Dec 01, 2010 8:37 am

Re: Raycasting against movable GImpactMeshShape, is it possi

Post by tunnuz »

Flix wrote: Wait a minute.

Shapes cannot be moved. They can be shared by multiple rigid bodies/collision objects (but in case they're deformable it's usually better to keep a shape per object). The transform belongs to the object/body, not to the shape.
Ok, that's clear to me. But how the ray-casting technique works, then? Does it automatically consider the shape in the position specified by the related collision object's transform?
Flix wrote: When you do raycasting you can do it in different ways (see the appRaytracer demo); you may try to change the way you do it.
You may also try to replicate the behaviour you're seeing in this demo http://bulletphysics.org/Bullet/phpBB3/ ... =raytracer: it uses a btCollisionWorld like in your base code (maybe the default Bullet demo does the same...).
Ok, I must take a look to the example, thank you for pointing it.

Thank you for taking the time to reply, I will update this post with the solution as soon as I have some results.

Tunnuz