An easy way to set the geometric center position of objects?
Posted: Thu Aug 05, 2010 5:46 pm
Hi,
I'm trying to work with the physics engine. The main problem I'm experiencing is how to relate 3D models with physical entities. To make it clear, look at the attached picture. At left there is a Cylinder object (from Bepu engine), and at the right we have a 3d model of a coke (please use your imagination ). If i want to add a "physical" behavior to the coke, what I do is this:
1- Load the coke model, transform its world matrix to set into the desired position
2- Create an instance of a cylinder, and add it to a bepu "space" instance, transform its world matrix to set into the desired position
3- Add the cilinder to the bepuphysicsdrawer, so I can alternate the render of the physical entities with the 3d models to check the positions and transformations are being correctly used
4- at the game Update method, update the space instance
This is cool, and works, I don't know if it is the "correct way", but works (if there is a better way please tell me ). The problem is that there is always an "offset" between the 3d model and the physical entity. So I supose their geometric center is different. In my 3d model I can control the geometric center in 3dmax, setting the pivot before generating the FBX file. In Bepu, I supose it is needed to set the "centerPosition" property of the Cylinder instance. ¿Wich is the best way to do it? I supose a way could be to do a lot of tests and alternate the render of the physical entities with the 3d models to find the position. But this method is not so scientific...
¿Is there a better way to set the center position of an object?
I'm trying to work with the physics engine. The main problem I'm experiencing is how to relate 3D models with physical entities. To make it clear, look at the attached picture. At left there is a Cylinder object (from Bepu engine), and at the right we have a 3d model of a coke (please use your imagination ). If i want to add a "physical" behavior to the coke, what I do is this:
1- Load the coke model, transform its world matrix to set into the desired position
2- Create an instance of a cylinder, and add it to a bepu "space" instance, transform its world matrix to set into the desired position
3- Add the cilinder to the bepuphysicsdrawer, so I can alternate the render of the physical entities with the 3d models to check the positions and transformations are being correctly used
4- at the game Update method, update the space instance
This is cool, and works, I don't know if it is the "correct way", but works (if there is a better way please tell me ). The problem is that there is always an "offset" between the 3d model and the physical entity. So I supose their geometric center is different. In my 3d model I can control the geometric center in 3dmax, setting the pivot before generating the FBX file. In Bepu, I supose it is needed to set the "centerPosition" property of the Cylinder instance. ¿Wich is the best way to do it? I supose a way could be to do a lot of tests and alternate the render of the physical entities with the 3d models to find the position. But this method is not so scientific...
¿Is there a better way to set the center position of an object?