
The quaternion for the rotation i get from the Transform object in my MotionState has the values:
x: -5.559519E-9
y: 0.6384396
z: 7.559638E-8
w: 0.7696719
.. so i think the problem should not be in the graphics positioning but somewhere in the physics.
Here is my MotionState:
Code: Select all
public class StaticObjectMotionState extends MotionState{
Transform transform;
StaticObject object;
public StaticObjectMotionState(Transform initTransform, StaticObject object)
{
transform = initTransform;
this.object = object;
}
@Override
public Transform getWorldTransform(Transform transform) {
transform.set(this.transform);
return this.transform;
}
@Override
public void setWorldTransform(Transform transform) {
object.setPosition(new Vector3f(transform.origin.x, transform.origin.y, transform.origin.z));
javax.vecmath.Quat4f quat = new javax.vecmath.Quat4f();
transform.getRotation(quat);
object.setRotation(new Quaternion(quat.x, quat.y, quat.z, quat.w));
this.transform.set(transform);
}
}
Code: Select all
public class Physics {
private final static Physics instance = new Physics();
private DynamicsWorld dynamicsWorld;
public Physics()
{
DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher collisionDispatcher = new CollisionDispatcher(collisionConfiguration);
SequentialImpulseConstraintSolver constraintSolver = new SequentialImpulseConstraintSolver();
Vector3f worldAabbMin = new Vector3f(-10000, -10000, -10000);
Vector3f worldAabbMax = new Vector3f(10000, 10000, 10000);
int maxProxies = 1024;
AxisSweep3 overlappingPairCache =
new AxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
dynamicsWorld = new DiscreteDynamicsWorld(collisionDispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0,-1,0));
}
public void simulateStep(float delta)
{
dynamicsWorld.stepSimulation(delta);
}
public static Physics getInstance()
{
return instance;
}
public DynamicsWorld getDynamicsWorld()
{
return dynamicsWorld;
}
}
Code: Select all
collisionShape = new StaticPlaneShape(new javax.vecmath.Vector3f(0,1,0), 1);
Transform groundTransform = new Transform();
groundTransform.setIdentity();
groundTransform.origin.set(new javax.vecmath.Vector3f(0.f, -10.f, 0.f));
StaticObjectMotionState motionState = new StaticObjectMotionState(groundTransform, this);
//DefaultMotionState groundMotionState = new DefaultMotionState(groundTransform);
RigidBodyConstructionInfo construction = new RigidBodyConstructionInfo(0, motionState, collisionShape, new javax.vecmath.Vector3f(0f,0f,0f));
rigidBody = new RigidBody(construction);
Code: Select all
collisionShape = new BoxShape(new javax.vecmath.Vector3f(2.0f,1.0f,1.0f));
Transform motionTransform = new Transform();
motionTransform.setIdentity();
motionTransform.origin.set(new javax.vecmath.Vector3f(0, 10, 0));
StaticObjectMotionState motionState = new StaticObjectMotionState(motionTransform, this);
//DefaultMotionState groundMotionState = new DefaultMotionState(motionTransform);
javax.vecmath.Vector3f fallInertia = new javax.vecmath.Vector3f(0,0,0);
collisionShape.calculateLocalInertia(1, fallInertia);
RigidBodyConstructionInfo fallRigidBodyCI = new RigidBodyConstructionInfo(1, motionState, collisionShape, fallInertia);
rigidBody = new RigidBody(fallRigidBodyCI);
Thank you already in advance,
Greetings!