Explosion

Post Reply
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Explosion

Post by B_old »

Hi,

I'm wondering about explosion effects and their implementation. I found this thread (http://bulletphysics.org/Bullet/phpBB3/ ... =explosion) about the topic but I'd still like to bring this up again.
How do you guys do explosions?
Here is a way I thought about:
1. Find all affected objects, for example by using a ghostshape
2. Trace rays from the center of the explosion to 1 or many sample points of the affected objects, if the ray hits a static/kinematic object the corresponding sample is not affected by the explosion

That way you have basic occlusion and by using a few samples per object (10 or so?) you could have effects like stuff spinning because it was hit (only) at a corner.

What do you think?
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: Explosion

Post by sparkprime »

Ah I remember that thread... good times... I still haven't implemented explosions in my game but they're on the todo list, will probably do it by the end of summer.

The problem I see with using a ghost shape (as opposed to a direct collision query which is slower) is that it has to exist in the scene for a while before the explosion. So if you know there's going to be an explosion at a particular point some frames in advance then that's OK. But for an instantaneous explosion I don't know if it would work. Erwin?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Explosion

Post by Flix »

sparkprime wrote:The problem I see with using a ghost shape (as opposed to a direct collision query which is slower) is that it has to exist in the scene for a while before the explosion. So if you know there's going to be an explosion at a particular point some frames in advance then that's OK. But for an instantaneous explosion I don't know if it would work.
I, in an old post, wrote: What is the difference between using a ghostObject/pairCachingGhostObject and using aabbTest/contactTest queries?
(I suppose that ghost objects have their manifold points refreshed automatically every physic frame by Bullet, even if the user don't need to use them that often, and contact queries must be used "on the fly". Is it correct?)
Erwin, as an answer, wrote: The most important difference is that aabbTest/contactTest has to calculate the overlapping AABB's and contact information from scratch, while the btGhostObject approach is incremental (it only computes changes). So if there are a lot of objects in the world, and you can keep a btGhostObject in a given location for a longer period of time, it could be more efficient. In other words, it doesn't make sense to insert a btGhostObject only a single frame, or moving it around a lot, in that case a aabbTest/contactTest is more suitable.

The difference might be not so big anymore, because Bullet uses the btDbvtBroadphase for a fast O(log n) search. Also the btAxisSweep3 uses this optional dynamic btDbvt acceleration stucture by default (as long as you don't disable the 'disableRaycastAccelerator')
So probably we can use aabbTest/contactTest queries instead of ghost objects.
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Explosion

Post by B_old »

Flix wrote:So probably we can use aabbTest/contactTest queries instead of ghost objects.
Sounds good. But what exactly do those aabbTest/contactTest queries mean? Is there an interface for them or do you implement them yourself?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Explosion

Post by Flix »

B_old wrote:But what exactly do those aabbTest/contactTest queries mean? Is there an interface for them or do you implement them yourself?
Please read this post for further info (I didn't try it myself at the moment):
http://bulletphysics.org/Bullet/phpBB3/ ... est#p18791
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Explosion

Post by B_old »

Thanks for the link.
But what do you do if the radius of your explosion can be arbitrary?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Explosion

Post by Flix »

B_old wrote:But what do you do if the radius of your explosion can be arbitrary?
Why you're asking it ?
If you want to use a contact test, but don't want to create a different collision shape each time, you can probaly use setLocalScaling() many times on the same sphere collision shape.

P.S. As I wrote before, I've never used the "contactTest" feature myself (at the moment), but I've found another post about it here: http://bulletphysics.org/Bullet/phpBB3/ ... est#p17423, and I've discovered that it's used in the Bullet "collisionInterfaceDemo" too.
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Explosion

Post by B_old »

Flix wrote: Why you're asking it ?
If you want to use a contact test, but don't want to create a different collision shape each time, you can probaly use setLocalScaling() many times on the same sphere collision shape.
I'm asking because I wasn't aware of the setLocalScaling() method.
I'll have to find some more info on this, because right now I'm wondering if this can be used to only have 1 instance of every CollisionShape. Right now I have a CollisionShape for every scale I use.

Thanks for the answers and links, they are very helpful for me!
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: Explosion

Post by sparkprime »

You can create a sphere on the stack, no need to worry about it.
B_old
Posts: 79
Joined: Tue Sep 26, 2006 1:10 pm

Re: Explosion

Post by B_old »

sparkprime wrote:You can create a sphere on the stack, no need to worry about it.
Somehow that never occurred to me, but it sounds like a good solution.

Do you know whether the callback for testCollision() will provide all contact-points with a certain object grouped together? In other words, if I receive a contact-point for one object and then for another, can I assume that no other contact-points for the first object will follow?
Post Reply