I’m trying to use the physics API but I have problems keeping my dynamic objects steady before i even move them.
That is, following the SimpleTest app I created a Box to use as the floor and a box to stand on the floor, NOT FALLING.
I tried to set the location of the box 1 unit above the floor but the box still falls from above. I also have a problem when loading
models and place them on a TerrainBlock. They keep rotating around without me applying any force on them.
Here’s some sample code:
Level level = new BoxLevel("TestLevel", 100,1, 100);
level.init();
//where the floor is a Box
level.getFloor().setLocalTranslation(new Vector3f(0, -10, 10));
Box boxGraphics = new Box("Box", new Vector3f(), 10f, 10f, 10f);
boxGraphics.setLocalTranslation(new Vector3f(0, -9, 10));
rootNode.attachChild(boxGraphics);
DynamicPhysicsObject boxPhysics = new DynamicPhysicsObject(boxGraphics, 1f);
world.addObject(boxPhysics);
Is there something that I'm missing? Shouldn't the default behaviour of a newly created
DynamicPhysicsObject be the same as a StaticPhysicsObject (provided that no forces or torque are set)?
Are you doing this at initialization time? You might say, boxPhysics.syncWithGraphics() (or something to that effect, I don't have the code in front of me) to make sure it is in sync. You might paste your entire contents of you class in here and it will provide a bit more information.
prowler7 said: Shouldn't the default behaviour of a newly created
DynamicPhysicsObject be the same as a StaticPhysicsObject (provided that no forces or torque are set)?
No, as there is gravity. You can switch off gravity in the physics world of you like (just set it to (0,0,0)).
Is gravity your concern, or is there other behaviour that is unexpected?
Just tried to use syncWithGraphical() but makes no difference. After disabling gravity thebox never shows,
probably because it never falls down(so I've commented it out).
Heres the whole thing:
public class TestLevel extends SimpleGame {
private PhysicsWorld world;
/**
* Called near end of initGame(). Must be defined by derived classes.
*/
protected void simpleInitGame() {
initPhysicsWorld();
initLevel();
initObjects();
}
I think your problem has to do with the fact that you're setting the position of your box at y=-9.0f and 10.0f tall, yet your floor is at y=-10.0f and only one tall. This would make the box start embeded into the floor which will make it pop out with force applied to it because they are overlayed.
irrisor said: Create a sphere, attach it to a node, change the local translation to move the center of the sphere away from the center of the mass, then create a physics object from the node.
The center of mass is the point of reference of the spatial for which the DynamicPhysicsObject is created.
I wrote the following code and it seems to work correctly(only when the bounding volume of the model is a box).
Is that what I'm supposed to do or there's a better way of handling this?
//attach sphere and translate in order to change the center of mass
Sphere sphere = new Sphere("Sphere", 10, 10, 10);
q2Model.attachChild(sphere);
sphere.setCullMode(Spatial.CULL_ALWAYS);
sphere.setLocalTranslation(new Vector3f(0,10,0));
} catch (Exception e) {
e.printStackTrace();
}
rootNode.attachChild(q2Model);
DynamicPhysicsObject boxPhysics = new DynamicPhysicsObject(q2Model, 1f);
world.addObject(boxPhysics);
boxPhysics.syncWithGraphical();
Yes, in fact I've had very similar problems recently having to do with the center of gravity on the model I loaded. I've had specific problems with 3D Studio exporting models and them just being totally screwed up. I found it seems to be a problem with scaling in 3DS. Anyway, you'll either have to get the center of gravity correct before you export it or fix it after you import it. I think someone can probably explain how to do it in jME.
I've had specific problems with 3D Studio exporting models and them just being totally screwed up. I found it seems to be a problem with scaling in 3DS.
darkfrog
when do you scale the model as an object or as an editablemesh/poly sometimes depending where you dp your scaling strange things happen might also consider adjusting the pivot centers before exporting