I don't think there is any other easy way to do it.
I don't think there is any other easy way to do it.
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.
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.
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 );
}
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.
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:
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.
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.
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