OSDN Git Service

Prep work for generalization of collision booleans to bitmasks
authorblaine.dev <blaine.dev@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 28 Aug 2009 21:26:16 +0000 (21:26 +0000)
committerblaine.dev <blaine.dev@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 28 Aug 2009 21:26:16 +0000 (21:26 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@4638 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

src/com/jme/scene/Geometry.java
src/com/jme/scene/Node.java
src/com/jme/scene/Spatial.java
src/com/jme/scene/SwitchNode.java
src/com/jme/scene/TriMesh.java

index dcb9000..842d911 100644 (file)
@@ -642,7 +642,7 @@ public abstract class Geometry extends Spatial implements Serializable, Savable
      */
     @Override
     public void findPick(Ray ray, PickResults results) {
-        if (getWorldBound() == null || !isCollidable) {
+        if (getWorldBound() == null || !isCollidable()) {
             return;
         }
         if (getWorldBound().intersects(ray)) {
index ab46405..771cf93 100644 (file)
@@ -579,7 +579,7 @@ public class Node extends Spatial implements Serializable, Savable {
 
     @Override
     public void findCollisions(Spatial scene, CollisionResults results) {
-        if (getWorldBound() != null && isCollidable && scene.isCollidable()) {
+        if (getWorldBound() != null && isCollidable() && scene.isCollidable()) {
             if (getWorldBound().intersects(scene.getWorldBound())) {
                 // further checking needed.
                 for (int i = 0; i < getQuantity(); i++) {
@@ -592,7 +592,7 @@ public class Node extends Spatial implements Serializable, Savable {
     @Override
     public boolean hasCollision(Spatial scene, boolean checkTriangles) {
         if (this == scene) return false;  // No Collision with "self"
-        if (getWorldBound() != null && isCollidable && scene.isCollidable()) {
+        if (getWorldBound() != null && isCollidable() && scene.isCollidable()) {
             if (getWorldBound().intersects(scene.getWorldBound())) {
                 if(children == null && !checkTriangles) {
                     return true;
@@ -614,7 +614,7 @@ public class Node extends Spatial implements Serializable, Savable {
         if(children == null) {
             return;
         }
-        if (getWorldBound() != null && isCollidable) {
+        if (getWorldBound() != null && isCollidable()) {
             if (getWorldBound().intersects(toTest)) {
                 // further checking needed.
                 for (int i = 0; i < getQuantity(); i++) {
index 720d095..8bcf88c 100644 (file)
@@ -241,7 +241,7 @@ public abstract class Spatial implements Serializable, Savable {
      * Defines if this spatial will be used in intersection operations or not.
      * Default is true
      */
-    protected boolean isCollidable = true;
+    protected int collisionBits = 1;
 
     public transient float queueDistance = Float.NEGATIVE_INFINITY;
 
@@ -1023,7 +1023,7 @@ public abstract class Spatial implements Serializable, Savable {
     public void write(JMEExporter ex) throws IOException {
         OutputCapsule capsule = ex.getCapsule(this);
         capsule.write(name, "name", null);
-        capsule.write(isCollidable, "isCollidable", true);
+        capsule.write(collisionBits, "collisionBits", 1);
         capsule.write(cullHint, "cullMode", CullHint.Inherit);
 
         capsule.write(renderQueueMode, "renderQueueMode",
@@ -1056,7 +1056,17 @@ public abstract class Spatial implements Serializable, Savable {
          * for compatibility, this should be dropped.
          */
         if (name == null) name = "";
-        isCollidable = capsule.readBoolean("isCollidable", true);
+        boolean collisionBoolean = capsule.readBoolean("isCollidable", true);
+        collisionBits = capsule.readInt("collisionBits", 1);
+
+        // Handle legacy model files that have stored 'isCollidable' instead of
+        // 'collisionBits'.
+        if (!collisionBoolean && collisionBits == 1) collisionBits = 0;
+        /* Our exporter routines do not allow us to always detect whether
+         * 'isCollidable' was actually persisted.
+         * However, if 'isCollidable' has a non-default val and 'collisionBits'
+         * has default val, we know that legacy value was stored.  */
+
         cullHint = capsule.readEnum("cullMode", CullHint.class,
                 CullHint.Inherit);
 
@@ -1123,13 +1133,17 @@ public abstract class Spatial implements Serializable, Savable {
     /**
      * Sets if this Spatial is to be used in intersection (collision and
      * picking) calculations. By default this is true.
+     *
+     * Turns on or off the first (least significant) bit in the collision bit
+     * set.
      * 
      * @param isCollidable
      *            true if this Spatial is to be used in intersection
      *            calculations, false otherwise.
      */
     public void setIsCollidable(boolean isCollidable) {
-        this.isCollidable = isCollidable;
+        collisionBits = isCollidable ? (collisionBits | 1)
+                                     : (collisionBits & (~1));
     }
 
     /**
@@ -1140,7 +1154,7 @@ public abstract class Spatial implements Serializable, Savable {
      *         false otherwise.
      */
     public boolean isCollidable() {
-        return this.isCollidable;
+        return (collisionBits & 1) != 0;
     }
 
     /**
index 625d00c..fefb9c5 100644 (file)
@@ -160,7 +160,7 @@ public class SwitchNode extends Node {
      */
     @Override
     public void findCollisions(Spatial scene, CollisionResults results) {
-        if (this == scene || !isCollidable || !scene.isCollidable()) {
+        if (this == scene || !isCollidable() || !scene.isCollidable()) {
             return;
         }
 
@@ -176,7 +176,7 @@ public class SwitchNode extends Node {
      */
     @Override
     public boolean hasCollision(Spatial scene, boolean checkTriangles) {
-        if (this == scene || !isCollidable || !scene.isCollidable()) {
+        if (this == scene || !isCollidable() || !scene.isCollidable()) {
             return false;
         }
 
@@ -210,4 +210,4 @@ public class SwitchNode extends Node {
         activeChild = capsule.readInt("activeChild", 0);
         activeChildData = (Spatial)capsule.readSavable("activeChildData", null);
     }
-}
\ No newline at end of file
+}
index 15f2dee..4ad8506 100644 (file)
@@ -254,7 +254,7 @@ public class TriMesh extends Geometry implements Serializable {
      * if it has true is returned, otherwise false is returned.
      */
     public boolean hasCollision(Spatial scene, boolean checkTriangles) {
-        if (this == scene || !isCollidable || !scene.isCollidable()) {
+        if (this == scene || !isCollidable() || !scene.isCollidable()) {
             return false;
         }
         if (getWorldBound().intersects(scene.getWorldBound())) {
@@ -286,7 +286,7 @@ public class TriMesh extends Geometry implements Serializable {
      * hit.
      */
     public void findCollisions(Spatial scene, CollisionResults results) {
-        if (this == scene || !isCollidable || !scene.isCollidable()) {
+        if (this == scene || !isCollidable() || !scene.isCollidable()) {
             return;
         }
 
@@ -316,7 +316,7 @@ public class TriMesh extends Geometry implements Serializable {
         CollisionTree checkCT = CollisionTreeManager.getInstance()
                 .getCollisionTree(toCheck);
 
-        if (thisCT == null || checkCT == null || !isCollidable
+        if (thisCT == null || checkCT == null || !isCollidable()
                 || !toCheck.isCollidable()) {
             return false;
         }
@@ -409,7 +409,7 @@ public class TriMesh extends Geometry implements Serializable {
      *            the indices to the triangles.
      */
     public void findTrianglePick(Ray toTest, ArrayList<Integer> results) {
-        if (worldBound == null || !isCollidable) {
+        if (worldBound == null || !isCollidable()) {
             return;
         }
 
@@ -631,4 +631,4 @@ public class TriMesh extends Geometry implements Serializable {
         recalcTriangleQuantity();
         mode = (Mode) capsule.readEnum("mode", Mode.class, Mode.Triangles);
     }
-}
\ No newline at end of file
+}