OSDN Git Service

- add collision callbacks to native bullet
authornormen667 <normen667@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 15 Oct 2011 14:27:28 +0000 (14:27 +0000)
committernormen667 <normen667@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 15 Oct 2011 14:27:28 +0000 (14:27 +0000)
- add SixDofSpringJoint to native bullet
(thanks to @chototsu)

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@8395 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

27 files changed:
engine/src/bullet/com/jme3/bullet/PhysicsSpace.java
engine/src/bullet/com/jme3/bullet/collision/PhysicsCollisionEvent.java
engine/src/bullet/com/jme3/bullet/collision/PhysicsCollisionEventFactory.java
engine/src/bullet/com/jme3/bullet/collision/PhysicsCollisionObject.java
engine/src/bullet/com/jme3/bullet/joints/SixDofJoint.java
engine/src/bullet/com/jme3/bullet/joints/SixDofSpringJoint.java [new file with mode: 0644]
engine/src/bullet/com/jme3/bullet/objects/PhysicsCharacter.java
engine/src/bullet/com/jme3/bullet/objects/PhysicsGhostObject.java
engine/src/bullet/com/jme3/bullet/objects/PhysicsRigidBody.java
engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java
engine/src/bullet/native/build.xml
engine/src/bullet/native/bullet.properties
engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp
engine/src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionObject.cpp
engine/src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionObject.h
engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.cpp [new file with mode: 0644]
engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.h [new file with mode: 0644]
engine/src/bullet/native/com_jme3_bullet_objects_PhysicsCharacter.cpp
engine/src/bullet/native/com_jme3_bullet_objects_PhysicsGhostObject.cpp
engine/src/bullet/native/com_jme3_bullet_objects_PhysicsGhostObject.h
engine/src/bullet/native/com_jme3_bullet_objects_PhysicsRigidBody.cpp
engine/src/bullet/native/jmeClasses.cpp
engine/src/bullet/native/jmeClasses.h
engine/src/bullet/native/jmeMotionState.cpp
engine/src/bullet/native/jmePhysicsSpace.cpp
engine/src/bullet/native/jmePhysicsSpace.h
engine/src/bullet/native/jmeUserPointer.h [new file with mode: 0644]

index 35bd447..d2f02e7 100644 (file)
@@ -329,6 +329,10 @@ public class PhysicsSpace {
 //            }
 //        });
 //    }
+    private void addCollisionEvent_native(PhysicsCollisionObject node, PhysicsCollisionObject node1, long manifoldPointObjectId) {
+//        System.out.println("addCollisionEvent:"+node.getObjectId()+" "+ node1.getObjectId());
+        collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId));
+    }
     /**
      * updates the physics space
      * @param time the current time value
index e79e315..a9f63d6 100644 (file)
@@ -49,58 +49,13 @@ public class PhysicsCollisionEvent extends EventObject {
     private int type;
     private PhysicsCollisionObject nodeA;
     private PhysicsCollisionObject nodeB;
-    public final Vector3f localPointA;
-    public final Vector3f localPointB;
-    public final Vector3f positionWorldOnB;
-    public final Vector3f positionWorldOnA;
-    public final Vector3f normalWorldOnB;
-    public float distance1;
-    public float combinedFriction;
-    public float combinedRestitution;
-    public int partId0;
-    public int partId1;
-    public int index0;
-    public int index1;
-    public Object userPersistentData;
-    public float appliedImpulse;
-    public boolean lateralFrictionInitialized;
-    public float appliedImpulseLateral1;
-    public float appliedImpulseLateral2;
-    public int lifeTime;
-    public final Vector3f lateralFrictionDir1;
-    public final Vector3f lateralFrictionDir2;
+    private long manifoldPointObjectId = 0;
 
-    public PhysicsCollisionEvent(int type, PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB) {
-        this(type, nodeA, nodeB, new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f(), 0, 0, 0, 0, 0, 0, 0, null, 0, false, 0, 0, 0, new Vector3f(), new Vector3f());
-    }
-    
-    public PhysicsCollisionEvent(int type, PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB, Vector3f localPointA, Vector3f localPointB, Vector3f positionWorldOnB, Vector3f positionWorldOnA, Vector3f normalWorldOnB, float distance1, float combinedFriction, float combinedRestitution, int partId0, int partId1, int index0, int index1, Object userPersistentData, float appliedImpulse, boolean lateralFrictionInitialized, float appliedImpulseLateral1, float appliedImpulseLateral2, int lifeTime, Vector3f lateralFrictionDir1, Vector3f lateralFrictionDir2) {
+    public PhysicsCollisionEvent(int type, PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB, long manifoldPointObjectId) {
         super(nodeA);
-        this.type = type;
-        this.nodeA = nodeA;
-        this.nodeB = nodeB;
-        this.localPointA = localPointA;
-        this.localPointB = localPointB;
-        this.positionWorldOnB = positionWorldOnB;
-        this.positionWorldOnA = positionWorldOnA;
-        this.normalWorldOnB = normalWorldOnB;
-        this.distance1 = distance1;
-        this.combinedFriction = combinedFriction;
-        this.combinedRestitution = combinedRestitution;
-        this.partId0 = partId0;
-        this.partId1 = partId1;
-        this.index0 = index0;
-        this.index1 = index1;
-        this.userPersistentData = userPersistentData;
-        this.appliedImpulse = appliedImpulse;
-        this.lateralFrictionInitialized = lateralFrictionInitialized;
-        this.appliedImpulseLateral1 = appliedImpulseLateral1;
-        this.appliedImpulseLateral2 = appliedImpulseLateral2;
-        this.lifeTime = lifeTime;
-        this.lateralFrictionDir1 = lateralFrictionDir1;
-        this.lateralFrictionDir2 = lateralFrictionDir2;
+        this.manifoldPointObjectId = manifoldPointObjectId;
     }
-
+    
     /**
      * used by event factory, called when event is destroyed
      */
@@ -109,56 +64,18 @@ public class PhysicsCollisionEvent extends EventObject {
         this.type = 0;
         this.nodeA = null;
         this.nodeB = null;
-//        this.localPointA = null;
-//        this.localPointB = null;
-//        this.positionWorldOnB = null;
-//        this.positionWorldOnA = null;
-//        this.normalWorldOnB = null;
-//        this.distance1 = null
-//        this.combinedFriction = null;
-//        this.combinedRestitution = null;
-//        this.partId0 = null;
-//        this.partId1 = null;
-//        this.index0 = null;
-//        this.index1 = null;
-        this.userPersistentData = null;
-//        this.appliedImpulse = null;
-//        this.lateralFrictionInitialized = null;
-//        this.appliedImpulseLateral1 = null;
-//        this.appliedImpulseLateral2 = null;
-//        this.lifeTime = null;
-//        this.lateralFrictionDir1 = null;
-//        this.lateralFrictionDir2 = null;
+        this.manifoldPointObjectId = 0;
     }
 
     /**
      * used by event factory, called when event reused
      */
-    public void refactor(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB, Vector3f localPointA, Vector3f localPointB, Vector3f positionWorldOnB, Vector3f positionWorldOnA, Vector3f normalWorldOnB, float distance1, float combinedFriction, float combinedRestitution, int partId0, int partId1, int index0, int index1, Object userPersistentData, float appliedImpulse, boolean lateralFrictionInitialized, float appliedImpulseLateral1, float appliedImpulseLateral2, int lifeTime, Vector3f lateralFrictionDir1, Vector3f lateralFrictionDir2) {
+    public void refactor(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB, long manifoldPointObjectId) {
         this.source = source;
         this.type = type;
         this.nodeA = source;
         this.nodeB = nodeB;
-        this.localPointA.set(localPointA);
-        this.localPointB.set(localPointB);
-        this.positionWorldOnB.set(positionWorldOnB);
-        this.positionWorldOnA.set(positionWorldOnA);
-        this.normalWorldOnB.set(normalWorldOnB);
-        this.distance1 = distance1;
-        this.combinedFriction = combinedFriction;
-        this.combinedRestitution = combinedRestitution;
-        this.partId0 = partId0;
-        this.partId1 = partId1;
-        this.index0 = index0;
-        this.index1 = index1;
-        this.userPersistentData = userPersistentData;
-        this.appliedImpulse = appliedImpulse;
-        this.lateralFrictionInitialized = lateralFrictionInitialized;
-        this.appliedImpulseLateral1 = appliedImpulseLateral1;
-        this.appliedImpulseLateral2 = appliedImpulseLateral2;
-        this.lifeTime = lifeTime;
-        this.lateralFrictionDir1.set(lateralFrictionDir1);
-        this.lateralFrictionDir2.set(lateralFrictionDir2);
+        this.manifoldPointObjectId = manifoldPointObjectId;
     }
 
     public int getType() {
@@ -194,82 +111,109 @@ public class PhysicsCollisionEvent extends EventObject {
     }
 
     public float getAppliedImpulse() {
-        return appliedImpulse;
+        return getAppliedImpulse(manifoldPointObjectId);
     }
+    private native float getAppliedImpulse(long manifoldPointObjectId);
 
     public float getAppliedImpulseLateral1() {
-        return appliedImpulseLateral1;
+        return getAppliedImpulseLateral1(manifoldPointObjectId);
     }
+    private native float getAppliedImpulseLateral1(long manifoldPointObjectId);
 
     public float getAppliedImpulseLateral2() {
-        return appliedImpulseLateral2;
+        return getAppliedImpulseLateral2(manifoldPointObjectId);
     }
+    private native float getAppliedImpulseLateral2(long manifoldPointObjectId);
 
     public float getCombinedFriction() {
-        return combinedFriction;
+        return getCombinedFriction(manifoldPointObjectId);
     }
+    private native float getCombinedFriction(long manifoldPointObjectId);
 
     public float getCombinedRestitution() {
-        return combinedRestitution;
+        return getCombinedRestitution(manifoldPointObjectId);
     }
+    private native float getCombinedRestitution(long manifoldPointObjectId);
 
     public float getDistance1() {
-        return distance1;
+        return getDistance1(manifoldPointObjectId);
     }
+    private native float getDistance1(long manifoldPointObjectId);
 
     public int getIndex0() {
-        return index0;
+        return getIndex0(manifoldPointObjectId);
     }
+    private native int getIndex0(long manifoldPointObjectId);
 
     public int getIndex1() {
-        return index1;
+        return getIndex1(manifoldPointObjectId);
     }
+    private native int getIndex1(long manifoldPointObjectId);
 
-    public Vector3f getLateralFrictionDir1() {
+    public Vector3f getLateralFrictionDir1(Vector3f lateralFrictionDir1) {
+        getLateralFrictionDir1(manifoldPointObjectId, lateralFrictionDir1);
         return lateralFrictionDir1;
     }
+    private native void getLateralFrictionDir1(long manifoldPointObjectId, Vector3f lateralFrictionDir1);
 
-    public Vector3f getLateralFrictionDir2() {
+    public Vector3f getLateralFrictionDir2(Vector3f lateralFrictionDir2) {
+        getLateralFrictionDir2(manifoldPointObjectId, lateralFrictionDir2);
         return lateralFrictionDir2;
     }
+    private native void getLateralFrictionDir2(long manifoldPointObjectId, Vector3f lateralFrictionDir2);
 
     public boolean isLateralFrictionInitialized() {
-        return lateralFrictionInitialized;
+        return isLateralFrictionInitialized(manifoldPointObjectId);
     }
+    private native boolean isLateralFrictionInitialized(long manifoldPointObjectId);
 
     public int getLifeTime() {
-        return lifeTime;
+        return getLifeTime(manifoldPointObjectId);
     }
+    private native int getLifeTime(long manifoldPointObjectId);
 
-    public Vector3f getLocalPointA() {
+    public Vector3f getLocalPointA(Vector3f localPointA) {
+        getLocalPointA(manifoldPointObjectId, localPointA);
         return localPointA;
     }
+    private native void getLocalPointA(long manifoldPointObjectId, Vector3f localPointA);
 
-    public Vector3f getLocalPointB() {
+    public Vector3f getLocalPointB(Vector3f localPointB) {
+        getLocalPointB(manifoldPointObjectId, localPointB);
         return localPointB;
     }
+    private native void getLocalPointB(long manifoldPointObjectId, Vector3f localPointB);
 
-    public Vector3f getNormalWorldOnB() {
+    public Vector3f getNormalWorldOnB(Vector3f normalWorldOnB) {
+        getNormalWorldOnB(manifoldPointObjectId, normalWorldOnB);
         return normalWorldOnB;
     }
+    private native void getNormalWorldOnB(long manifoldPointObjectId, Vector3f normalWorldOnB);
 
     public int getPartId0() {
-        return partId0;
+        return getPartId0(manifoldPointObjectId);
     }
+    private native int getPartId0(long manifoldPointObjectId);
 
     public int getPartId1() {
-        return partId1;
+        return getPartId1(manifoldPointObjectId);
     }
 
-    public Vector3f getPositionWorldOnA() {
+    private native int getPartId1(long manifoldPointObjectId);
+
+    public Vector3f getPositionWorldOnA(Vector3f positionWorldOnA) {
+        getPositionWorldOnA(positionWorldOnA);
         return positionWorldOnA;
     }
+    private native void getPositionWorldOnA(long manifoldPointObjectId, Vector3f positionWorldOnA);
 
-    public Vector3f getPositionWorldOnB() {
+    public Vector3f getPositionWorldOnB(Vector3f positionWorldOnB) {
+        getPositionWorldOnB(manifoldPointObjectId, positionWorldOnB);
         return positionWorldOnB;
     }
+    private native void getPositionWorldOnB(long manifoldPointObjectId, Vector3f positionWorldOnB);
 
-    public Object getUserPersistentData() {
-        return userPersistentData;
-    }
+//    public Object getUserPersistentData() {
+//        return userPersistentData;
+//    }
 }
index 51d4fe4..4d88fc0 100644 (file)
@@ -41,12 +41,12 @@ public class PhysicsCollisionEventFactory {
 
     private ConcurrentLinkedQueue<PhysicsCollisionEvent> eventBuffer = new ConcurrentLinkedQueue<PhysicsCollisionEvent>();
 
-    public PhysicsCollisionEvent getEvent(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB) {
+    public PhysicsCollisionEvent getEvent(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB, long manifoldPointObjectId) {
         PhysicsCollisionEvent event = eventBuffer.poll();
         if (event == null) {
-            event = new PhysicsCollisionEvent(type, source, nodeB);
+            event = new PhysicsCollisionEvent(type, source, nodeB, manifoldPointObjectId);
         }else{
-//            event.refactor(type, source, nodeB);
+            event.refactor(type, source, nodeB, manifoldPointObjectId);
         }
         return event;
     }
index 7455939..3ccd098 100644 (file)
@@ -125,6 +125,9 @@ public abstract class PhysicsCollisionObject implements Savable {
      */
     public void setCollisionGroup(int collisionGroup) {
         this.collisionGroup = collisionGroup;
+        if (objectId != 0) {
+            setCollisionGroup(objectId, collisionGroup);
+        }
     }
 
     /**
@@ -135,6 +138,9 @@ public abstract class PhysicsCollisionObject implements Savable {
      */
     public void addCollideWithGroup(int collisionGroup) {
         this.collisionGroupsMask = this.collisionGroupsMask | collisionGroup;
+        if (objectId != 0) {
+            setCollideWithGroups(objectId, this.collisionGroupsMask);
+        }
     }
 
     /**
@@ -143,6 +149,9 @@ public abstract class PhysicsCollisionObject implements Savable {
      */
     public void removeCollideWithGroup(int collisionGroup) {
         this.collisionGroupsMask = this.collisionGroupsMask & ~collisionGroup;
+        if (objectId != 0) {
+            setCollideWithGroups(this.collisionGroupsMask);
+        }
     }
 
     /**
@@ -151,6 +160,9 @@ public abstract class PhysicsCollisionObject implements Savable {
      */
     public void setCollideWithGroups(int collisionGroups) {
         this.collisionGroupsMask = collisionGroups;
+        if (objectId != 0) {
+            setCollideWithGroups(objectId, this.collisionGroupsMask);
+        }
     }
 
     /**
@@ -161,6 +173,11 @@ public abstract class PhysicsCollisionObject implements Savable {
         return collisionGroupsMask;
     }
 
+    protected void initUserPointer() {
+        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "initUserPointer() objectId = {0}", Long.toHexString(objectId));
+        initUserPointer(objectId, collisionGroup, collisionGroupsMask);
+    }
+    native void initUserPointer(long objectId, int group, int groups);
     /**
      * Creates a visual debug shape of the current collision shape of this physics object<br/>
      * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
@@ -278,6 +295,8 @@ public abstract class PhysicsCollisionObject implements Savable {
     }
     
     protected native void attachCollisionShape(long objectId, long collisionShapeId);
+    native void setCollisionGroup(long objectId, int collisionGroup);
+    native void setCollideWithGroups(long objectId, int collisionGroups);
 
     @Override
     public void write(JmeExporter e) throws IOException {
index 6bed78f..05d75df 100644 (file)
@@ -59,14 +59,14 @@ import java.util.logging.Logger;
  */
 public class SixDofJoint extends PhysicsJoint {
 
-    private Matrix3f rotA, rotB;
-    private boolean useLinearReferenceFrameA;
-    private LinkedList<RotationalLimitMotor> rotationalMotors = new LinkedList<RotationalLimitMotor>();
-    private TranslationalLimitMotor translationalMotor;
-    private Vector3f angularUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY);
-    private Vector3f angularLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY);
-    private Vector3f linearUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY);
-    private Vector3f linearLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY);
+    Matrix3f rotA, rotB;
+    boolean useLinearReferenceFrameA;
+    LinkedList<RotationalLimitMotor> rotationalMotors = new LinkedList<RotationalLimitMotor>();
+    TranslationalLimitMotor translationalMotor;
+    Vector3f angularUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY);
+    Vector3f angularLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY);
+    Vector3f linearUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY);
+    Vector3f linearLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY);
 
     public SixDofJoint() {
     }
@@ -160,7 +160,7 @@ public class SixDofJoint extends PhysicsJoint {
 
     private native void setAngularLowerLimit(long objctId, Vector3f vector);
 
-    private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA);
+    native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA);
 
     @Override
     public void read(JmeImporter im) throws IOException {
diff --git a/engine/src/bullet/com/jme3/bullet/joints/SixDofSpringJoint.java b/engine/src/bullet/com/jme3/bullet/joints/SixDofSpringJoint.java
new file mode 100644 (file)
index 0000000..1fa312f
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.bullet.joints;
+
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.math.Matrix3f;
+import com.jme3.math.Vector3f;
+import com.jme3.bullet.joints.motors.RotationalLimitMotor;
+import com.jme3.bullet.joints.motors.TranslationalLimitMotor;
+import com.jme3.bullet.objects.PhysicsRigidBody;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.OutputCapsule;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <i>From bullet manual:</i><br>
+ * This generic constraint can emulate a variety of standard constraints,
+ * by configuring each of the 6 degrees of freedom (dof).
+ * The first 3 dof axis are linear axis, which represent translation of rigidbodies,
+ * and the latter 3 dof axis represent the angular motion. Each axis can be either locked,
+ * free or limited. On construction of a new btGeneric6DofConstraint, all axis are locked.
+ * Afterwards the axis can be reconfigured. Note that several combinations that
+ * include free and/or limited angular degrees of freedom are undefined.
+ * @author normenhansen
+ */
+public class SixDofSpringJoint extends SixDofJoint {
+
+   final boolean       springEnabled[] = new boolean[6];
+   final float equilibriumPoint[] = new float[6];
+   final float springStiffness[] = new float[6];
+   final float springDamping[] = new float[6]; // between 0 and 1 (1 == no damping)
+
+    public SixDofSpringJoint() {
+    }
+
+    /**
+     * @param pivotA local translation of the joint connection point in node A
+     * @param pivotB local translation of the joint connection point in node B
+     */
+    public SixDofSpringJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) {
+        super(nodeA, nodeB, pivotA, pivotB, rotA, rotB, useLinearReferenceFrameA);
+    }
+    public void enableSpring(int index, boolean onOff) {
+        enableSpring(objectId, index, onOff);
+    }
+    native void enableSpring(long objctId, int index, boolean onOff);
+
+    public void setStiffness(int index, float stiffness) {
+        setStiffness(objectId, index, stiffness);
+    }
+    native void setStiffness(long objctId, int index, float stiffness);
+
+    public void setDamping(int index, float damping) {
+        setDamping(objectId, index, damping);
+
+    }
+    native void setDamping(long objctId, int index, float damping);
+    public void setEquilibriumPoint() { // set the current constraint position/orientation as an equilibrium point for all DOF
+        setEquilibriumPoint(objectId);
+    }
+    native void setEquilibriumPoint(long objctId);
+    public void setEquilibriumPoint(int index){ // set the current constraint position/orientation as an equilibrium point for given DOF
+        setEquilibriumPoint(objectId, index);
+    }
+    native void setEquilibriumPoint(long objctId, int index);
+    @Override
+    native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA);
+
+}
index d9ee34d..430ed99 100644 (file)
@@ -79,6 +79,7 @@ public class PhysicsCharacter extends PhysicsCollisionObject {
         if (objectId == 0) {
             objectId = createGhostObject();
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Creating GhostObject {0}", Long.toHexString(objectId));
+            initUserPointer();
         }
         setCharacterFlags(objectId);
         attachCollisionShape(objectId, collisionShape.getObjectId());
index a037b00..d644f70 100644 (file)
@@ -80,6 +80,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
             objectId = createGhostObject();
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Ghost Object {0}", Long.toHexString(objectId));
             setGhostFlags(objectId);
+            initUserPointer();
         }
 //        if (gObject == null) {
 //            gObject = new PairCachingGhostObject();
@@ -91,13 +92,13 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     private native long createGhostObject();
 
     private native void setGhostFlags(long objectId);
-    
+
     @Override
     public void setCollisionShape(CollisionShape collisionShape) {
         super.setCollisionShape(collisionShape);
         if (objectId == 0) {
             buildObject();
-        }else{
+        } else {
             attachCollisionShape(objectId, collisionShape.getObjectId());
         }
     }
@@ -109,7 +110,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public void setPhysicsLocation(Vector3f location) {
         setPhysicsLocation(objectId, location);
     }
-    
+
     private native void setPhysicsLocation(long objectId, Vector3f location);
 
     /**
@@ -119,7 +120,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public void setPhysicsRotation(Matrix3f rotation) {
         setPhysicsRotation(objectId, rotation);
     }
-    
+
     private native void setPhysicsRotation(long objectId, Matrix3f rotation);
 
     /**
@@ -129,7 +130,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public void setPhysicsRotation(Quaternion rotation) {
         setPhysicsRotation(objectId, rotation);
     }
-    
+
     private native void setPhysicsRotation(long objectId, Quaternion rotation);
 
     /**
@@ -142,7 +143,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
         getPhysicsLocation(objectId, trans);
         return trans;
     }
-    
+
     private native void getPhysicsLocation(long objectId, Vector3f vector);
 
     /**
@@ -155,7 +156,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
         getPhysicsRotation(objectId, rot);
         return rot;
     }
-    
+
     private native void getPhysicsRotation(long objectId, Quaternion rot);
 
     /**
@@ -168,7 +169,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
         getPhysicsRotationMatrix(objectId, rot);
         return rot;
     }
-    
+
     private native void getPhysicsRotationMatrix(long objectId, Matrix3f rot);
 
     /**
@@ -179,7 +180,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
         getPhysicsLocation(objectId, vec);
         return vec;
     }
-    
+
     /**
      * @return the physicsLocation
      */
@@ -201,7 +202,6 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
 //    public PairCachingGhostObject getObjectId() {
 //        return gObject;
 //    }
-
     /**
      * destroys this PhysicsGhostNode and removes it from memory
      */
@@ -215,13 +215,20 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
      * @return All CollisionObjects overlapping with this GhostNode.
      */
     public List<PhysicsCollisionObject> getOverlappingObjects() {
-//        overlappingObjects.clear();
+        overlappingObjects.clear();
+        getOverlappingObjects(objectId);
 //        for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) {
 //            overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer());
 //        }
         return overlappingObjects;
     }
 
+    protected native void getOverlappingObjects(long objectId);
+
+    private void addOverlappingObject_native(PhysicsCollisionObject co) {
+        overlappingObjects.add(co);
+    }
+
     /**
      *
      * @return With how many other CollisionObjects this GhostNode is currently overlapping.
@@ -229,7 +236,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public int getOverlappingCount() {
         return getOverlappingCount(objectId);
     }
-    
+
     private native int getOverlappingCount(long objectId);
 
     /**
@@ -244,7 +251,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public void setCcdSweptSphereRadius(float radius) {
         setCcdSweptSphereRadius(objectId, radius);
     }
-    
+
     private native void setCcdSweptSphereRadius(long objectId, float radius);
 
     public void setCcdMotionThreshold(float threshold) {
@@ -256,7 +263,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject {
     public float getCcdSweptSphereRadius() {
         return getCcdSweptSphereRadius(objectId);
     }
-    
+
     private native float getCcdSweptSphereRadius(long objectId);
 
     public float getCcdMotionThreshold() {
index eac3f3e..21e9bfc 100644 (file)
@@ -121,6 +121,7 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
         } else {
             setStatic(objectId, false);
         }
+        initUserPointer();
     }
 
     /**
index 6896769..c0ae323 100644 (file)
@@ -149,6 +149,12 @@ public class PhysicsVehicle extends PhysicsRigidBody {
         setCoordinateSystem(vehicleId, 0, 1, 2);
         for (VehicleWheel wheel : wheels) {
             wheel.setWheelId(addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel()));
+            wheel.setFrictionSlip(tuning.frictionSlip);
+            wheel.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm);
+            wheel.setSuspensionStiffness(tuning.suspensionStiffness);
+            wheel.setWheelsDampingCompression(tuning.suspensionCompression);
+            wheel.setWheelsDampingRelaxation(tuning.suspensionDamping);
+            wheel.setMaxSuspensionForce(tuning.maxSuspensionForce);
         }
     }
 
index 9d46638..7c3fbd0 100644 (file)
@@ -5,6 +5,9 @@
     <!-- load properties -->
     <property file="src/bullet/native/bullet.properties"/>
     <!-- condition for mac platform check -->
+    <condition property="isSolaris">
+        <os name="SunOS"/>
+    </condition>
     <condition property="isMac">
         <and>
             <os family="mac" />
@@ -22,6 +25,9 @@
             <not>
                 <os family="mac"/>
             </not>
+            <not>
+                <os name="SunOS"/>
+            </not>
         </and>
     </condition>
     <!-- condition for x86_64 check -->
@@ -41,7 +47,7 @@
         <fileset refid="lib.jme.jars"/>
     </pathconvert>
 
-    <target name="build-bullet-natives" description="builds the native bullet library for the platform being run on" depends="-create-folders, create-native-headers, -nativelib-osx, -nativelib-windows, -nativelib-linux">
+    <target name="build-bullet-natives" description="builds the native bullet library for the platform being run on" depends="-create-folders, create-native-headers, -nativelib-osx, -nativelib-windows, -nativelib-linux, -nativelib-solaris">
         <echo message="Updating native jME3-bullet-natives.jar"/>
         <zip basedir="${bullet.output.base}/jarcontent" file="${bullet.output.base}/jME3-bullet-natives.jar" compress="true"/>
         <copy file="${bullet.output.base}/jME3-bullet-natives.jar" todir="dist/lib"/>
@@ -51,6 +57,7 @@
         <javah destdir="${bullet.source.dir}" classpath="${bullet.build.dir}${path.separator}${lib.importpath}" force="yes">
             <class name="com.jme3.bullet.PhysicsSpace"/>
 
+            <class name="com.jme3.bullet.collision.PhysicsCollisionEvent"/>
             <class name="com.jme3.bullet.collision.PhysicsCollisionObject"/>
             <class name="com.jme3.bullet.objects.PhysicsCharacter"/>
             <class name="com.jme3.bullet.objects.PhysicsGhostObject"/>
@@ -78,6 +85,7 @@
             <class name="com.jme3.bullet.joints.HingeJoint"/>
             <class name="com.jme3.bullet.joints.Point2PointJoint"/>
             <class name="com.jme3.bullet.joints.SixDofJoint"/>
+            <class name="com.jme3.bullet.joints.SixDofSpringJoint"/>
             <class name="com.jme3.bullet.joints.SliderJoint"/>
             <class name="com.jme3.bullet.joints.motors.RotationalLimitMotor"/>
             <class name="com.jme3.bullet.joints.motors.TranslationalLimitMotor"/>
             <includepath path="${bullet.java.include}/linux"/>
             <includepath path="${bullet.bullet.include}"/>
             <!--compilerarg value="-m32"/-->
+            <compilerarg value="-m32"/>
+            <compilerarg value="-static-libgcc"/>
             <linker name="${bullet.linux.compiler}">
+                <!-- linkerarg value="-static-libgcc"/ -->
                 <libset dir="${bullet.folder}/src/BulletMultiThreaded" libs="BulletMultiThreaded"/>
                 <libset dir="${bullet.folder}/src/BulletDynamics" libs="BulletDynamics"/>
                 <libset dir="${bullet.folder}/src/BulletCollision" libs="BulletCollision"/>
         </cc>
         <delete file="${bullet.output.dir}/linux/history.xml"/>
     </target>
+    
+    <target name="-nativelib-solaris" if="isSolaris">
+        <echo message="Building Solaris version of native bullet"/>
+        <mkdir dir="${bullet.output.dir}/linux"/>
+        <cc name="${bullet.solaris.compiler}" warnings="severe" debug="${bullet.compile.debug}" link="shared" outfile="${bullet.output.dir}/solaris/${bullet.library.name}" objdir="${bullet.build.dir}">
+            <fileset dir="${bullet.source.dir}">
+                <include name="*.cpp">
+                </include>
+            </fileset>
+            <includepath path="${bullet.java.include}"/>
+            <includepath path="${bullet.java.include}/solaris"/>
+            <includepath path="${bullet.bullet.include}"/>
+            <!--compilerarg value="-m32"/-->
+            <compilerarg value="-m32"/>
+            <compilerarg value="-fno-strict-aliasing"/>
+            <compilerarg value="-pthread"/>
+            <compilerarg value="-fPIC"/>
+            <compilerarg value="-D_REENTRANT"/>
+            <compilerarg value="-static-libstdc++"/>
+            <compilerarg value="-static-libgcc"/>
+            <compilerarg value="-D_REENTRANT"/>
+            <linker name="${bullet.solaris.compiler}">
+                <linkerarg value="-R/usr/sfw/lib"/>
+                <libset dir="${bullet.folder}/src/BulletMultiThreaded" libs="BulletMultiThreaded"/>
+                <libset dir="${bullet.folder}/src/BulletDynamics" libs="BulletDynamics"/>
+                <libset dir="${bullet.folder}/src/BulletCollision" libs="BulletCollision"/>
+                <libset dir="${bullet.folder}/src/LinearMath" libs="LinearMath"/>
+            </linker>
+        </cc>
+        <delete file="${bullet.output.dir}/solaris/history.xml"/>
+    </target>
 
     <target name="-nativelib-windows" if="isWindows">
         <echo message="Building Windows version of native bullet"/>
index ca8c444..0c6a246 100644 (file)
@@ -16,7 +16,7 @@ bullet.osx.syslibroot=/Developer/SDKs/MacOSX10.5.sdk
 # change this to msvc for MS Visual Studio compiler
 bullet.windows.compiler=g++
 bullet.linux.compiler=g++
-
+bullet.solaris.compiler=g++
 # native header include directories
 bullet.java.include=${java.home}/../include
 # OSX has no JRE, only JDK
index 9e8b1ce..1801e8a 100644 (file)
@@ -32,7 +32,7 @@
 #include "com_jme3_bullet_PhysicsSpace.h"
 #include "jmePhysicsSpace.h"
 #include "jmeBulletUtil.h"
-
+#include "jmeUserPointer.h"
 /**
  * Author: Normen Hansen
  */
@@ -93,6 +93,9 @@ extern "C" {
             env->ThrowNew(newExc, "The collision object does not exist.");
             return;
         }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = space;
+
         space->getDynamicsWorld()->addCollisionObject(collisionObject);
     }
 
@@ -116,6 +119,8 @@ extern "C" {
             return;
         }
         space->getDynamicsWorld()->removeCollisionObject(collisionObject);
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = NULL;
     }
 
     /*
@@ -137,6 +142,8 @@ extern "C" {
             env->ThrowNew(newExc, "The collision object does not exist.");
             return;
         }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = space;
         space->getDynamicsWorld()->addRigidBody(collisionObject);
     }
 
@@ -159,6 +166,8 @@ extern "C" {
             env->ThrowNew(newExc, "The collision object does not exist.");
             return;
         }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = NULL;
         space->getDynamicsWorld()->removeRigidBody(collisionObject);
     }
 
@@ -181,7 +190,12 @@ extern "C" {
             env->ThrowNew(newExc, "The collision object does not exist.");
             return;
         }
-        space->getDynamicsWorld()->addCollisionObject(collisionObject, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = space;
+        space->getDynamicsWorld()->addCollisionObject(collisionObject,
+                btBroadphaseProxy::CharacterFilter,
+                btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter
+        );
     }
 
     /*
@@ -203,6 +217,8 @@ extern "C" {
             env->ThrowNew(newExc, "The collision object does not exist.");
             return;
         }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        userPointer -> space = NULL;
         space->getDynamicsWorld()->removeCollisionObject(collisionObject);
     }
 
index 38eeb67..515041a 100644 (file)
@@ -35,6 +35,8 @@
  */
 #include "com_jme3_bullet_collision_PhysicsCollisionObject.h"
 #include "jmeBulletUtil.h"
+#include "jmePhysicsSpace.h"
+#include "jmeUserPointer.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -75,8 +77,73 @@ extern "C" {
             env->ThrowNew(newExc, "The native object does not exist.");
             return;
         }
+        if (collisionObject -> getUserPointer() != NULL){
+            jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+            delete(userPointer);
+        }
         delete(collisionObject);
     }
+    /*
+     * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+     * Method:    initUserPointer
+     * Signature: (JII)V
+     */
+    JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_initUserPointer
+      (JNIEnv *env, jobject object, jlong objectId, jint group, jint groups) {
+        btCollisionObject* collisionObject = (btCollisionObject*) objectId;
+        if (collisionObject == NULL) {
+            jclass newExc = env->FindClass("java/lang/NullPointerException");
+            env->ThrowNew(newExc, "The native object does not exist.");
+            return;
+        }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        if (userPointer != NULL) {
+//            delete(userPointer);
+        }
+        userPointer = new jmeUserPointer();
+        userPointer -> javaCollisionObject = env->NewWeakGlobalRef(object);
+        userPointer -> group = group;
+        userPointer -> groups = groups;
+        userPointer -> space = NULL;
+        collisionObject -> setUserPointer(userPointer);
+    }
+    /*
+     * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+     * Method:    setCollisionGroup
+     * Signature: (JI)V
+     */
+    JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollisionGroup
+      (JNIEnv *env, jobject object, jlong objectId, jint group) {
+        btCollisionObject* collisionObject = (btCollisionObject*) objectId;
+        if (collisionObject == NULL) {
+            jclass newExc = env->FindClass("java/lang/NullPointerException");
+            env->ThrowNew(newExc, "The native object does not exist.");
+            return;
+        }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        if (userPointer != NULL){
+            userPointer -> group = group;
+        }
+    }
+    /*
+     * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+     * Method:    setCollideWithGroups
+     * Signature: (JI)V
+     */
+    JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollideWithGroups
+      (JNIEnv *env, jobject object, jlong objectId, jint groups) {
+        btCollisionObject* collisionObject = (btCollisionObject*) objectId;
+        if (collisionObject == NULL) {
+            jclass newExc = env->FindClass("java/lang/NullPointerException");
+            env->ThrowNew(newExc, "The native object does not exist.");
+            return;
+        }
+        jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
+        if (userPointer != NULL){
+            userPointer -> groups = groups;
+        }
+    }
+
 #ifdef __cplusplus
 }
 #endif
index 955c7e3..db5bf7a 100644 (file)
@@ -43,6 +43,14 @@ extern "C" {
 #define com_jme3_bullet_collision_PhysicsCollisionObject_COLLISION_GROUP_16 32768L
 /*
  * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+ * Method:    initUserPointer
+ * Signature: (JII)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_initUserPointer
+  (JNIEnv *, jobject, jlong, jint, jint);
+
+/*
+ * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
  * Method:    attachCollisionShape
  * Signature: (JJ)V
  */
@@ -51,6 +59,22 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_att
 
 /*
  * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+ * Method:    setCollisionGroup
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollisionGroup
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
+ * Method:    setCollideWithGroups
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollideWithGroups
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     com_jme3_bullet_collision_PhysicsCollisionObject
  * Method:    finalizeNative
  * Signature: (J)V
  */
diff --git a/engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.cpp b/engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.cpp
new file mode 100644 (file)
index 0000000..282b400
--- /dev/null
@@ -0,0 +1,103 @@
+
+/**
+ * Author: Normen Hansen
+ */
+#include "com_jme3_bullet_joints_SixDofSpringJoint.h"
+#include "jmeBulletUtil.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    enableString
+ * Signature: (JIZ)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_enableSpring
+  (JNIEnv *env, jobject object, jlong jointId, jint index, jboolean onOff) {
+    btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId;
+    joint -> enableSpring(index, onOff);
+}
+
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setStiffness
+ * Signature: (JIF)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setStiffness
+  (JNIEnv *env, jobject object, jlong jointId, jint index, jfloat stiffness) {
+    btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId;
+    joint -> setStiffness(index, stiffness);
+}
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setDamping
+ * Signature: (JIF)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setDamping
+  (JNIEnv *env, jobject object, jlong jointId, jint index, jfloat damping) {
+    btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId;
+    joint -> setDamping(index, damping);
+}
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setEquilibriumPoint
+ * Signature: (JIF)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__J
+  (JNIEnv *env, jobject object, jlong jointId) {
+    btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId;
+    joint -> setEquilibriumPoint();
+}
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setEquilibriumPoint
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__JI
+  (JNIEnv *env, jobject object, jlong jointId, jint index) {
+    btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId;
+    joint -> setEquilibriumPoint(index);
+}
+
+
+
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    createJoint
+ * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J
+ */
+JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_createJoint
+    (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) {
+        jmeClasses::initJavaClasses(env);
+        btRigidBody* bodyA = (btRigidBody*) bodyIdA;
+        btRigidBody* bodyB = (btRigidBody*) bodyIdB;
+        btMatrix3x3* mtx1 = &btMatrix3x3();
+        btMatrix3x3* mtx2 = &btMatrix3x3();
+/*        btTransform* transA = &btTransform(*mtx1);
+        jmeBulletUtil::convert(env, pivotA, &transA->getOrigin());
+        jmeBulletUtil::convert(env, rotA, &transA->getBasis());
+        btTransform* transB = &btTransform(*mtx2);
+        jmeBulletUtil::convert(env, pivotB, &transB->getOrigin());
+        jmeBulletUtil::convert(env, rotB, &transB->getBasis());
+*/
+        btTransform transA;
+        jmeBulletUtil::convert(env, pivotA, &transA.getOrigin());
+        jmeBulletUtil::convert(env, rotA, &transA.getBasis());
+        btTransform transB;
+        jmeBulletUtil::convert(env, pivotB, &transB.getOrigin());
+        jmeBulletUtil::convert(env, rotB, &transB.getBasis());
+
+        btGeneric6DofSpringConstraint* joint = new btGeneric6DofSpringConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA);
+        return (long)joint;
+    }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.h b/engine/src/bullet/native/com_jme3_bullet_joints_SixDofSpringJoint.h
new file mode 100644 (file)
index 0000000..b4fced0
--- /dev/null
@@ -0,0 +1,61 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_jme3_bullet_joints_SixDofSpringJoint */
+
+#ifndef _Included_com_jme3_bullet_joints_SixDofSpringJoint
+#define _Included_com_jme3_bullet_joints_SixDofSpringJoint
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    enableSpring
+ * Signature: (JIZ)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_enableSpring
+  (JNIEnv *, jobject, jlong, jint, jboolean);
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setStiffness
+ * Signature: (JIF)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setStiffness
+  (JNIEnv *, jobject, jlong, jint, jfloat);
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setDamping
+ * Signature: (JIF)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setDamping
+  (JNIEnv *, jobject, jlong, jint, jfloat);
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setEquilibriumPoint
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__J
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    setEquilibriumPoint
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__JI
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     com_jme3_bullet_joints_SixDofSpringJoint
+ * Method:    createJoint
+ * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J
+ */
+JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_createJoint
+  (JNIEnv *, jobject, jlong, jlong, jobject, jobject, jobject, jobject, jboolean);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
index ea52548..b8d3afa 100644 (file)
@@ -68,7 +68,7 @@ extern "C" {
             env->ThrowNew(newExc, "The native object does not exist.");
             return;
         }
-        ghost->setCollisionFlags(ghost->getCollisionFlags() | btCollisionObject::CF_CHARACTER_OBJECT);
+        ghost->setCollisionFlags(/*ghost->getCollisionFlags() |*/ btCollisionObject::CF_CHARACTER_OBJECT);
         ghost->setCollisionFlags(ghost->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
     }
 
index 42d496e..b0c8944 100644 (file)
 #include <BulletCollision/CollisionDispatch/btGhostObject.h>
 
 #include "com_jme3_bullet_objects_PhysicsGhostObject.h"
+#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
 #include "jmeBulletUtil.h"
-
+#include "jmePhysicsSpace.h"
+#include "jmeUserPointer.h"
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -167,6 +169,48 @@ extern "C" {
         jmeBulletUtil::convert(env, &ghost->getWorldTransform().getBasis(), value);
     }
 
+    class jmeGhostOverlapCallback : public btOverlapCallback {
+        JNIEnv* m_env;
+        jobject m_object;
+    public:
+        jmeGhostOverlapCallback(JNIEnv *env, jobject object)
+                :m_env(env),
+                 m_object(object)
+        {
+        }
+        virtual ~jmeGhostOverlapCallback() {}
+        virtual bool    processOverlap(btBroadphasePair& pair)
+        {
+            btCollisionObject *co1 = (btCollisionObject *)pair.m_pProxy0->m_clientObject;
+            jmeUserPointer *up1 = (jmeUserPointer*)co1 -> getUserPointer();
+
+            m_env->CallVoidMethod(m_object, jmeClasses::PhysicsGhostObject_addOverlappingObject, up1->javaCollisionObject);
+            if (m_env->ExceptionCheck()) {
+                m_env->Throw(m_env->ExceptionOccurred());
+                return false;
+            }
+
+            return false;
+        }
+    };
+
+    /*
+     * Class:     com_jme3_bullet_objects_PhysicsGhostObject
+     * Method:    getOverlappingObjects
+     * Signature: (J)V
+     */
+    JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getOverlappingObjects
+      (JNIEnv *env, jobject object, jlong objectId) {
+        btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
+        if (ghost == NULL) {
+            jclass newExc = env->FindClass("java/lang/NullPointerException");
+            env->ThrowNew(newExc, "The native object does not exist.");
+            return;
+        }
+        btHashedOverlappingPairCache * pc = ghost->getOverlappingPairCache();
+        jmeGhostOverlapCallback cb(env, object);
+        pc -> processAllOverlappingPairs(&cb, NULL);
+    }
     /*
      * Class:     com_jme3_bullet_objects_PhysicsGhostObject
      * Method:    getOverlappingCount
index a3e18de..cf98e59 100644 (file)
@@ -107,6 +107,14 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysic
 
 /*
  * Class:     com_jme3_bullet_objects_PhysicsGhostObject
+ * Method:    getOverlappingObjects
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getOverlappingObjects
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     com_jme3_bullet_objects_PhysicsGhostObject
  * Method:    getOverlappingCount
  * Signature: (J)I
  */
index 4429df5..0ee7927 100644 (file)
@@ -54,6 +54,7 @@ extern "C" {
         btVector3 localInertia = btVector3();
         shape->calculateLocalInertia(mass, localInertia);
         btRigidBody* body = new btRigidBody(mass, motionState, shape, localInertia);
+        body->setUserPointer(NULL);
         return (long) body;
     }
 
index c9e652e..254ef9d 100644 (file)
 jclass jmeClasses::PhysicsSpace;
 jmethodID jmeClasses::PhysicsSpace_preTick;
 jmethodID jmeClasses::PhysicsSpace_postTick;
+jmethodID jmeClasses::PhysicsSpace_addCollisionEvent;
+
+jclass jmeClasses::PhysicsGhostObject;
+jmethodID jmeClasses::PhysicsGhostObject_addOverlappingObject;
 
 jclass jmeClasses::Vector3f;
 jmethodID jmeClasses::Vector3f_set;
@@ -106,6 +110,18 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
 
     PhysicsSpace_preTick = env->GetMethodID(PhysicsSpace, "preTick_native", "(F)V");
     PhysicsSpace_postTick = env->GetMethodID(PhysicsSpace, "postTick_native", "(F)V");
+    PhysicsSpace_addCollisionEvent = env->GetMethodID(PhysicsSpace, "addCollisionEvent_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;J)V");
+    if (env->ExceptionCheck()) {
+        env->Throw(env->ExceptionOccurred());
+        return;
+    }
+
+    PhysicsGhostObject = env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject");
+    if (env->ExceptionCheck()) {
+        env->Throw(env->ExceptionOccurred());
+        return;
+    }
+    PhysicsGhostObject_addOverlappingObject = env->GetMethodID(PhysicsGhostObject, "addOverlappingObject_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;)V");
     if (env->ExceptionCheck()) {
         env->Throw(env->ExceptionOccurred());
         return;
index b4cbef1..ef55e0c 100644 (file)
@@ -43,6 +43,9 @@ public:
     static jclass PhysicsSpace;
     static jmethodID PhysicsSpace_preTick;
     static jmethodID PhysicsSpace_postTick;
+    static jmethodID PhysicsSpace_addCollisionEvent;
+    static jclass PhysicsGhostObject;
+    static jmethodID PhysicsGhostObject_addOverlappingObject;
 
     static jclass Vector3f;
     static jmethodID Vector3f_set;
index c37e555..0c61f9b 100644 (file)
@@ -38,6 +38,7 @@
 
 jmeMotionState::jmeMotionState() {
     trans = new btTransform();
+    trans -> setIdentity();
     worldTransform = *trans;
     dirty = true;
 }
index 2ed23e2..634f7f3 100644 (file)
@@ -31,6 +31,8 @@
  */
 #include "jmePhysicsSpace.h"
 #include "jmeBulletUtil.h"
+#include "jmeUserPointer.h"
+#include <stdio.h>
 
 /**
  * Author: Normen Hansen
@@ -170,16 +172,33 @@ void jmePhysicsSpace::createPhysicsSpace(jfloat minX, jfloat minY, jfloat minZ,
         // return true when pairs need collision
 
         virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy * proxy1) const {
+            //            bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
+            //            collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
             bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
             collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
-
-            //add some additional logic here that modified 'collides'
+            if (collides) {
+                btCollisionObject* co0 = (btCollisionObject*) proxy0->m_clientObject;
+                btCollisionObject* co1 = (btCollisionObject*) proxy1->m_clientObject;
+                jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer();
+                jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
+                if (up0 != NULL && up1 != NULL) {
+                    collides = (up0->group & up1->groups) != 0;
+                    collides = collides && (up1->group & up0->groups);
+
+                    //add some additional logic here that modified 'collides'
+                    return collides;
+                }
+                return false;
+            }
             return collides;
         }
     };
     dynamicsWorld->getPairCache()->setOverlapFilterCallback(new jmeFilterCallback());
     dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::preTickCallback, static_cast<void *> (this), true);
     dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::postTickCallback, static_cast<void *> (this));
+    if (gContactProcessedCallback == NULL) {
+        gContactProcessedCallback = &jmePhysicsSpace::contactProcessedCallback;
+    }
 }
 
 void jmePhysicsSpace::preTickCallback(btDynamicsWorld *world, btScalar timeStep) {
@@ -202,6 +221,26 @@ void jmePhysicsSpace::postTickCallback(btDynamicsWorld *world, btScalar timeStep
     }
 }
 
+bool jmePhysicsSpace::contactProcessedCallback(btManifoldPoint &cp, void *body0, void *body1) {
+    //    printf("contactProcessedCallback %d %dn", body0, body1);
+    btCollisionObject* co0 = (btCollisionObject*) body0;
+    jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer();
+    btCollisionObject* co1 = (btCollisionObject*) body1;
+    jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
+    if (up0 != NULL) {
+        jmePhysicsSpace *dynamicsWorld = up0->space;
+        if (dynamicsWorld != NULL) {
+            JNIEnv* env = dynamicsWorld->getEnv();
+            env->CallVoidMethod(dynamicsWorld->getJavaPhysicsSpace(), jmeClasses::PhysicsSpace_addCollisionEvent, up0->javaCollisionObject, up1->javaCollisionObject, (jlong) & cp);
+            if (env->ExceptionCheck()) {
+                env->Throw(env->ExceptionOccurred());
+                return true;
+            }
+        }
+    }
+    return true;
+}
+
 btDynamicsWorld* jmePhysicsSpace::getDynamicsWorld() {
     return dynamicsWorld;
 }
index 932971e..7ba4c06 100644 (file)
@@ -46,6 +46,8 @@
 #include "BulletMultiThreaded/SpuCollisionTaskProcess.h"
 #include "BulletMultiThreaded/SequentialThreadSupport.h"
 #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
+#include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 
 /**
  * Author: Normen Hansen
@@ -70,4 +72,5 @@ public:
         JNIEnv* getEnv();
         static void preTickCallback(btDynamicsWorld*, btScalar);
         static void postTickCallback(btDynamicsWorld*, btScalar);
+        static bool contactProcessedCallback(btManifoldPoint &, void *, void *);
 };
\ No newline at end of file
diff --git a/engine/src/bullet/native/jmeUserPointer.h b/engine/src/bullet/native/jmeUserPointer.h
new file mode 100644 (file)
index 0000000..f7d058f
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _Included_jmeUserPointer
+#define _Included_jmeUserPointer
+#include <jni.h>
+class jmeUserPointer {
+public:
+    jobject javaCollisionObject;
+    jint group;
+    jint groups;
+    jmePhysicsSpace *space;
+};
+#endif
\ No newline at end of file