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