Bullet RigidBody : modification of the serializer to support the old & new angular factor
This commit is contained in:
parent
7f2c7c5d35
commit
b1473c302c
@ -51,7 +51,9 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>PhysicsRigidBody - Basic physics object</p>
|
* <p>
|
||||||
|
* PhysicsRigidBody - Basic physics object</p>
|
||||||
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class PhysicsRigidBody extends PhysicsCollisionObject {
|
public class PhysicsRigidBody extends PhysicsCollisionObject {
|
||||||
@ -66,6 +68,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PhysicsRigidBody with the supplied collision shape
|
* Creates a new PhysicsRigidBody with the supplied collision shape
|
||||||
|
*
|
||||||
* @param child
|
* @param child
|
||||||
* @param shape
|
* @param shape
|
||||||
*/
|
*/
|
||||||
@ -134,6 +137,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the physics object location
|
* Sets the physics object location
|
||||||
|
*
|
||||||
* @param location the location of the actual physics object
|
* @param location the location of the actual physics object
|
||||||
*/
|
*/
|
||||||
public void setPhysicsLocation(Vector3f location) {
|
public void setPhysicsLocation(Vector3f location) {
|
||||||
@ -144,6 +148,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the physics object rotation
|
* Sets the physics object rotation
|
||||||
|
*
|
||||||
* @param rotation the rotation of the actual physics object
|
* @param rotation the rotation of the actual physics object
|
||||||
*/
|
*/
|
||||||
public void setPhysicsRotation(Matrix3f rotation) {
|
public void setPhysicsRotation(Matrix3f rotation) {
|
||||||
@ -154,6 +159,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the physics object rotation
|
* Sets the physics object rotation
|
||||||
|
*
|
||||||
* @param rotation the rotation of the actual physics object
|
* @param rotation the rotation of the actual physics object
|
||||||
*/
|
*/
|
||||||
public void setPhysicsRotation(Quaternion rotation) {
|
public void setPhysicsRotation(Quaternion rotation) {
|
||||||
@ -249,9 +255,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
// return Converter.convert(tempTrans.basis, rotation);
|
// return Converter.convert(tempTrans.basis, rotation);
|
||||||
// }
|
// }
|
||||||
/**
|
/**
|
||||||
* Sets the node to kinematic mode. in this mode the node is not affected by physics
|
* Sets the node to kinematic mode. in this mode the node is not affected by
|
||||||
* but affects other physics objects. Iits kinetic force is calculated by the amount
|
* physics but affects other physics objects. Iits kinetic force is
|
||||||
* of movement it is exposed to and its weight.
|
* calculated by the amount of movement it is exposed to and its weight.
|
||||||
|
*
|
||||||
* @param kinematic
|
* @param kinematic
|
||||||
*/
|
*/
|
||||||
public void setKinematic(boolean kinematic) {
|
public void setKinematic(boolean kinematic) {
|
||||||
@ -272,8 +279,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void setCcdSweptSphereRadius(long objectId, float radius);
|
private native void setCcdSweptSphereRadius(long objectId, float radius);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the amount of motion that has to happen in one physics tick to trigger the continuous motion detection<br/>
|
* Sets the amount of motion that has to happen in one physics tick to
|
||||||
* This avoids the problem of fast objects moving through other objects, set to zero to disable (default)
|
* trigger the continuous motion detection<br/>
|
||||||
|
* This avoids the problem of fast objects moving through other objects, set
|
||||||
|
* to zero to disable (default)
|
||||||
|
*
|
||||||
* @param threshold
|
* @param threshold
|
||||||
*/
|
*/
|
||||||
public void setCcdMotionThreshold(float threshold) {
|
public void setCcdMotionThreshold(float threshold) {
|
||||||
@ -306,6 +316,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the mass of this PhysicsRigidBody, objects with mass=0 are static.
|
* Sets the mass of this PhysicsRigidBody, objects with mass=0 are static.
|
||||||
|
*
|
||||||
* @param mass
|
* @param mass
|
||||||
*/
|
*/
|
||||||
public void setMass(float mass) {
|
public void setMass(float mass) {
|
||||||
@ -345,8 +356,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the local gravity of this PhysicsRigidBody<br/>
|
* Set the local gravity of this PhysicsRigidBody<br/>
|
||||||
* Set this after adding the node to the PhysicsSpace,
|
* Set this after adding the node to the PhysicsSpace, the PhysicsSpace
|
||||||
* the PhysicsSpace assigns its current gravity to the physics node when its added.
|
* assigns its current gravity to the physics node when its added.
|
||||||
|
*
|
||||||
* @param gravity the gravity vector to set
|
* @param gravity the gravity vector to set
|
||||||
*/
|
*/
|
||||||
public void setGravity(Vector3f gravity) {
|
public void setGravity(Vector3f gravity) {
|
||||||
@ -363,6 +375,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the friction of this physics object
|
* Sets the friction of this physics object
|
||||||
|
*
|
||||||
* @param friction the friction of this physics object
|
* @param friction the friction of this physics object
|
||||||
*/
|
*/
|
||||||
public void setFriction(float friction) {
|
public void setFriction(float friction) {
|
||||||
@ -389,10 +402,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
public void setLinearDamping(float linearDamping) {
|
public void setLinearDamping(float linearDamping) {
|
||||||
setDamping(objectId, linearDamping, getAngularDamping());
|
setDamping(objectId, linearDamping, getAngularDamping());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAngularDamping(float angularDamping) {
|
public void setAngularDamping(float angularDamping) {
|
||||||
setAngularDamping(objectId, angularDamping);
|
setAngularDamping(objectId, angularDamping);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void setAngularDamping(long objectId, float factor);
|
private native void setAngularDamping(long objectId, float factor);
|
||||||
|
|
||||||
public float getLinearDamping() {
|
public float getLinearDamping() {
|
||||||
@ -414,7 +428,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native float getRestitution(long objectId);
|
private native float getRestitution(long objectId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "bouncyness" of the PhysicsRigidBody, best performance if restitution=0
|
* The "bouncyness" of the PhysicsRigidBody, best performance if
|
||||||
|
* restitution=0
|
||||||
|
*
|
||||||
* @param restitution
|
* @param restitution
|
||||||
*/
|
*/
|
||||||
public void setRestitution(float restitution) {
|
public void setRestitution(float restitution) {
|
||||||
@ -425,6 +441,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current angular velocity of this PhysicsRigidBody
|
* Get the current angular velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @return the current linear velocity
|
* @return the current linear velocity
|
||||||
*/
|
*/
|
||||||
public Vector3f getAngularVelocity() {
|
public Vector3f getAngularVelocity() {
|
||||||
@ -437,6 +454,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current angular velocity of this PhysicsRigidBody
|
* Get the current angular velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @param vec the vector to store the velocity in
|
* @param vec the vector to store the velocity in
|
||||||
*/
|
*/
|
||||||
public void getAngularVelocity(Vector3f vec) {
|
public void getAngularVelocity(Vector3f vec) {
|
||||||
@ -445,6 +463,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the angular velocity of this PhysicsRigidBody
|
* Sets the angular velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @param vec the angular velocity of this PhysicsRigidBody
|
* @param vec the angular velocity of this PhysicsRigidBody
|
||||||
*/
|
*/
|
||||||
public void setAngularVelocity(Vector3f vec) {
|
public void setAngularVelocity(Vector3f vec) {
|
||||||
@ -456,6 +475,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current linear velocity of this PhysicsRigidBody
|
* Get the current linear velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @return the current linear velocity
|
* @return the current linear velocity
|
||||||
*/
|
*/
|
||||||
public Vector3f getLinearVelocity() {
|
public Vector3f getLinearVelocity() {
|
||||||
@ -468,6 +488,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current linear velocity of this PhysicsRigidBody
|
* Get the current linear velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @param vec the vector to store the velocity in
|
* @param vec the vector to store the velocity in
|
||||||
*/
|
*/
|
||||||
public void getLinearVelocity(Vector3f vec) {
|
public void getLinearVelocity(Vector3f vec) {
|
||||||
@ -476,6 +497,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the linear velocity of this PhysicsRigidBody
|
* Sets the linear velocity of this PhysicsRigidBody
|
||||||
|
*
|
||||||
* @param vec the linear velocity of this PhysicsRigidBody
|
* @param vec the linear velocity of this PhysicsRigidBody
|
||||||
*/
|
*/
|
||||||
public void setLinearVelocity(Vector3f vec) {
|
public void setLinearVelocity(Vector3f vec) {
|
||||||
@ -486,9 +508,11 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void setLinearVelocity(long objectId, Vector3f vec);
|
private native void setLinearVelocity(long objectId, Vector3f vec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a force to the PhysicsRigidBody, only applies force if the next physics update call
|
* Apply a force to the PhysicsRigidBody, only applies force if the next
|
||||||
* updates the physics space.<br>
|
* physics update call updates the physics space.<br>
|
||||||
* To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force.
|
* To apply an impulse, use applyImpulse, use applyContinuousForce to apply
|
||||||
|
* continuous force.
|
||||||
|
*
|
||||||
* @param force the force
|
* @param force the force
|
||||||
* @param location the location of the force
|
* @param location the location of the force
|
||||||
*/
|
*/
|
||||||
@ -500,10 +524,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void applyForce(long objectId, Vector3f force, Vector3f location);
|
private native void applyForce(long objectId, Vector3f force, Vector3f location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a force to the PhysicsRigidBody, only applies force if the next physics update call
|
* Apply a force to the PhysicsRigidBody, only applies force if the next
|
||||||
* updates the physics space.<br>
|
* physics update call updates the physics space.<br>
|
||||||
* To apply an impulse, use applyImpulse.
|
* To apply an impulse, use applyImpulse.
|
||||||
*
|
*
|
||||||
* @param force the force
|
* @param force the force
|
||||||
*/
|
*/
|
||||||
public void applyCentralForce(Vector3f force) {
|
public void applyCentralForce(Vector3f force) {
|
||||||
@ -514,10 +538,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void applyCentralForce(long objectId, Vector3f force);
|
private native void applyCentralForce(long objectId, Vector3f force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a force to the PhysicsRigidBody, only applies force if the next physics update call
|
* Apply a force to the PhysicsRigidBody, only applies force if the next
|
||||||
* updates the physics space.<br>
|
* physics update call updates the physics space.<br>
|
||||||
* To apply an impulse, use applyImpulse.
|
* To apply an impulse, use applyImpulse.
|
||||||
*
|
*
|
||||||
* @param torque the torque
|
* @param torque the torque
|
||||||
*/
|
*/
|
||||||
public void applyTorque(Vector3f torque) {
|
public void applyTorque(Vector3f torque) {
|
||||||
@ -529,6 +553,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply an impulse to the PhysicsRigidBody in the next physics update.
|
* Apply an impulse to the PhysicsRigidBody in the next physics update.
|
||||||
|
*
|
||||||
* @param impulse applied impulse
|
* @param impulse applied impulse
|
||||||
* @param rel_pos location relative to object
|
* @param rel_pos location relative to object
|
||||||
*/
|
*/
|
||||||
@ -540,7 +565,9 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void applyImpulse(long objectId, Vector3f impulse, Vector3f rel_pos);
|
private native void applyImpulse(long objectId, Vector3f impulse, Vector3f rel_pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a torque impulse to the PhysicsRigidBody in the next physics update.
|
* Apply a torque impulse to the PhysicsRigidBody in the next physics
|
||||||
|
* update.
|
||||||
|
*
|
||||||
* @param vec
|
* @param vec
|
||||||
*/
|
*/
|
||||||
public void applyTorqueImpulse(Vector3f vec) {
|
public void applyTorqueImpulse(Vector3f vec) {
|
||||||
@ -552,7 +579,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all forces from the PhysicsRigidBody
|
* Clear all forces from the PhysicsRigidBody
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void clearForces() {
|
public void clearForces() {
|
||||||
clearForces(objectId);
|
clearForces(objectId);
|
||||||
@ -576,7 +603,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native void setCollisionShape(long objectId, long collisionShapeId);
|
private native void setCollisionShape(long objectId, long collisionShapeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reactivates this PhysicsRigidBody when it has been deactivated because it was not moving
|
* reactivates this PhysicsRigidBody when it has been deactivated because it
|
||||||
|
* was not moving
|
||||||
*/
|
*/
|
||||||
public void activate() {
|
public void activate() {
|
||||||
activate(objectId);
|
activate(objectId);
|
||||||
@ -591,8 +619,10 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
private native boolean isActive(long objectId);
|
private native boolean isActive(long objectId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the sleeping thresholds, these define when the object gets deactivated
|
* sets the sleeping thresholds, these define when the object gets
|
||||||
* to save ressources. Low values keep the object active when it barely moves
|
* deactivated to save ressources. Low values keep the object active when it
|
||||||
|
* barely moves
|
||||||
|
*
|
||||||
* @param linear the linear sleeping threshold
|
* @param linear the linear sleeping threshold
|
||||||
* @param angular the angular sleeping threshold
|
* @param angular the angular sleeping threshold
|
||||||
*/
|
*/
|
||||||
@ -629,11 +659,12 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
public float getAngularFactor() {
|
public float getAngularFactor() {
|
||||||
return getAngularFactor(null).getX();
|
return getAngularFactor(null).getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f getAngularFactor(Vector3f store) {
|
public Vector3f getAngularFactor(Vector3f store) {
|
||||||
// doing like this prevent from breaking the API
|
// doing like this prevent from breaking the API
|
||||||
if(store == null)
|
if (store == null) {
|
||||||
store = new Vector3f();
|
store = new Vector3f();
|
||||||
|
}
|
||||||
getAngularFactor(objectId, store);
|
getAngularFactor(objectId, store);
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
@ -645,26 +676,25 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAngularFactor(Vector3f factor) {
|
public void setAngularFactor(Vector3f factor) {
|
||||||
setAngularFactor(objectId, factor);
|
setAngularFactor(objectId, factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void setAngularFactor(long objectId, Vector3f factor);
|
private native void setAngularFactor(long objectId, Vector3f factor);
|
||||||
|
|
||||||
public Vector3f getLinearFactor() {
|
public Vector3f getLinearFactor() {
|
||||||
Vector3f vec = new Vector3f();
|
Vector3f vec = new Vector3f();
|
||||||
getLinearFactor(objectId, vec);
|
getLinearFactor(objectId, vec);
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void getLinearFactor(long objectId, Vector3f vec);
|
private native void getLinearFactor(long objectId, Vector3f vec);
|
||||||
|
|
||||||
public void setLinearFactor(Vector3f factor) {
|
public void setLinearFactor(Vector3f factor) {
|
||||||
setLinearFactor(objectId, factor);
|
setLinearFactor(objectId, factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void setLinearFactor(long objectId, Vector3f factor);
|
private native void setLinearFactor(long objectId, Vector3f factor);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* do not use manually, joints are added automatically
|
* do not use manually, joints are added automatically
|
||||||
*/
|
*/
|
||||||
@ -675,15 +705,17 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void removeJoint(PhysicsJoint joint) {
|
public void removeJoint(PhysicsJoint joint) {
|
||||||
joints.remove(joint);
|
joints.remove(joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of connected joints. This list is only filled when
|
* Returns a list of connected joints. This list is only filled when the
|
||||||
* the PhysicsRigidBody is actually added to the physics space or loaded from disk.
|
* PhysicsRigidBody is actually added to the physics space or loaded from
|
||||||
|
* disk.
|
||||||
|
*
|
||||||
* @return list of active joints connected to this PhysicsRigidBody
|
* @return list of active joints connected to this PhysicsRigidBody
|
||||||
*/
|
*/
|
||||||
public List<PhysicsJoint> getJoints() {
|
public List<PhysicsJoint> getJoints() {
|
||||||
@ -700,7 +732,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
capsule.write(getGravity(), "gravity", Vector3f.ZERO);
|
capsule.write(getGravity(), "gravity", Vector3f.ZERO);
|
||||||
capsule.write(getFriction(), "friction", 0.5f);
|
capsule.write(getFriction(), "friction", 0.5f);
|
||||||
capsule.write(getRestitution(), "restitution", 0);
|
capsule.write(getRestitution(), "restitution", 0);
|
||||||
capsule.write(getAngularFactor(), "angularFactor", 1);
|
Vector3f angularFactor = getAngularFactor(null);
|
||||||
|
if (angularFactor.x == angularFactor.y && angularFactor.y == angularFactor.z) {
|
||||||
|
capsule.write(getAngularFactor(), "angularFactor", 1);
|
||||||
|
} else {
|
||||||
|
capsule.write(getAngularFactor(null), "angularFactor", Vector3f.UNIT_XYZ);
|
||||||
|
capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ);
|
||||||
|
}
|
||||||
capsule.write(kinematic, "kinematic", false);
|
capsule.write(kinematic, "kinematic", false);
|
||||||
|
|
||||||
capsule.write(getLinearDamping(), "linearDamping", 0);
|
capsule.write(getLinearDamping(), "linearDamping", 0);
|
||||||
@ -730,7 +768,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
|||||||
setKinematic(capsule.readBoolean("kinematic", false));
|
setKinematic(capsule.readBoolean("kinematic", false));
|
||||||
|
|
||||||
setRestitution(capsule.readFloat("restitution", 0));
|
setRestitution(capsule.readFloat("restitution", 0));
|
||||||
setAngularFactor(capsule.readFloat("angularFactor", 1));
|
Vector3f angularFactor = (Vector3f) capsule.readSavable("angularFactor", Vector3f.NAN.clone());
|
||||||
|
if(angularFactor == Vector3f.NAN) {
|
||||||
|
setAngularFactor(capsule.readFloat("angularFactor", 1));
|
||||||
|
} else {
|
||||||
|
setAngularFactor(angularFactor);
|
||||||
|
setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone()));
|
||||||
|
}
|
||||||
setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
|
setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
|
||||||
setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
|
setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
|
||||||
setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
|
setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user