Jump to content
  • Advertisement
Sign in to follow this  
dpadam450

Destructible Mesh w/ Physics

This topic is 842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this missile pod and I'm creating a destructible mesh out of it. I've gone in and manually made some cuts through several parts of the mesh as you can see. I'm planning on creating rectangular boxes around each separated piece for simplicity in simulating destruction physics.
 
Right now all the individual cut pieces (15 total) share the same origin as the original mesh. This way I can just spawn them all at the center of the old mesh and they will be at the correct location.
 
My issue with this is that if I create physics boxes, I will have to scale and rotate them to fit the destructible pieces as shown in my picture. This means that the physics boxes start with some rotation matrix to match the object, while the actual drawn destructible objects are all in the identity matrix.
 
Therefore when I'm done simulating the physics boxes I have to determine how to draw these 15 meshes to the screen which are all in the same object space, while the physics objects are all in world space. So should I just take all those physics objects and put them into the 3D mesh space then before drawing?

 

I don't think there is any other easy way to do it.

 
[sharedmedia=core:attachments:32040]
Edited by dpadam450

Share this post


Link to post
Share on other sites
Advertisement

Which physics library are you using?

Usually there's a distinction between a rigid body, and the collision shapes that are attached to it.

In some libraries, it should be no problem for the collision shape to be offset from the local origin, and have the center of mass exist at the middle of that shape.

Share this post


Link to post
Share on other sites

I'm not using any at the moment. I was starting to implement my own a bit, but I think I'm going to go with Bullet. I've only used Newton Physics Library before.

 

I think you are suggesting that this be a rigid body with 15 collision shapes?  That is fine, as long as there is a way for me to scale and rotate them and then say this is all the "physics objects bind pose" so that when I get matrices back from the physics engine, they will indeed be relative to their bind pose or the reference frame of my missile turret so that I can have my matrices for drawing be correct.

 

Regardless though, that pretty much is the way to do it? Export all these meshes with 1 center point instead of individual center points? Seems to be easiest.

Edited by dpadam450

Share this post


Link to post
Share on other sites
If they're all disconnected from each other, it would be 15 rigid bodies with 1 collision shape each.
 
Bullet is a pain in the ass with this -- there is no ability to set the center of mass of an object; the center of mass is always it's local origin. Also, shapes are always centered around the rigid body's local origin :(
 
So yep, to deal with this you've got to make some kind of "physics object bind pose" system, which exists in between your gameplay/rendering code and the bullet API.
You'll probably also need to wrap your collision shape in a btCompoundShape, which allows the child shape to exist at an offset, which allows you to adjust the center of mass.

In my engine, I've got this kind of crap to get the kind of matrices that the graphics system is expecting:
	Mat4 GetPhysicsMatrix()
	{
		const btTransform& centreOfMassOffset = m_scene->m_centreOfMassOffset[m_body->getUserIndex()];
		return m_body->getWorldTransform() * bindPose;
	}
	void SetPhysicsMatrix( const Mat4& tx )
	{
 		Mat4& inverseBindPose = m_scene->m_centreOfMassOffset[m_body->getUserIndex()].inverse();
		m_body->setWorldTransform( inverseBindPose * tx );
	}

Share this post


Link to post
Share on other sites

Actually you can set the center of mass. It's just in a stranger way.
http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=2209
It's basically translating the mesh objects away from it's origin.

Yeah - because the center of mass is it's origin.

So if you want an object to not be at the origin, and have the center of mass at it's own center, you can't... without wrapping bullet with your own "center of mass" transform like I have above :wink:

Share this post


Link to post
Share on other sites

Is bullet the suggested physics engine? What about physX? I'd really love to roll my own so I have control of the code but I think it's going to be a pain.

Share this post


Link to post
Share on other sites

Is bullet the suggested physics engine? What about physX? I'd really love to roll my own so I have control of the code but I think it's going to be a pain.

Bullet is very good. I'm using it in my racing game at the moment :D

I've got all of the Bullet code inside my engine project directly, not even linked as a DLL/static library - which gives you a lot of control over exactly how you use all its parts.

One other downside is that Bullet is not a google'able word. Searching for e.g. "bullet collision detection" will mostly bring up results that have nothing to do with the "Bullet" physics library :lol:

 

PhysX is better. Its CCD is amazing compared to Bullet's and I think it's generally faster. It's also got all the fancy GPU-side stuff if you care, but personally this just pisses me off that NVidia develops this as a weapon in their marketplace battle against AMD (i.e. it's a conflict of interest). If your engine is multi-threaded, you can also very easily plug PhysX into your engine's threading system to get it to perform work across multiple cores.

The catch is that you don't get source without paying, and you only get Windows without paying. If you want to support other platforms or get the source code, you better have a real game budget, or a silver tongue :(

Oh, it actually has proper center of mass controls too :wink:

 

Rolling your own would be an intense learning experience, but without years of practice, would likely be much slower and less stable than Bullet -- unless you're focusing on a very small and specialized area.

Share this post


Link to post
Share on other sites

PhysX is better. Its CCD is amazing compared to Bullet's and I think it's generally faster. It's also got all the fancy GPU-side stuff if you care, but personally this just pisses me off that NVidia develops this as a weapon in their marketplace battle against AMD (i.e. it's a conflict of interest). If your engine is multi-threaded, you can also very easily plug PhysX into your engine's threading system to get it to perform work across multiple cores.

The catch is that you don't get source without paying, and you only get Windows without paying. If you want to support other platforms or get the source code, you better have a real game budget, or a silver tongue :(

Oh, it actually has proper center of mass controls too :wink:

It is now kind of open source, you only have to create an nVidia developer account, and request access to the Github repo. It contains as far as I see the full PhysX SDK, and parts of the APEX SDK (Core and Destruction is in it, and there are traces of the other modules, but i didn't managed to get them compiled), the latter is a nightmare to compile.
https://developer.nvidia.com/physx-source-github

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!