浏览代码

* Fix height = radius bug in ConeCollisionShape
* Added docs
* Added getter for height and axis

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

Sha..om 12 年之前
父节点
当前提交
85059fd8a0
共有 1 个文件被更改,包括 32 次插入2 次删除
  1. 32 2
      engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java

+ 32 - 2
engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java

@@ -43,6 +43,7 @@ import com.jme3.export.OutputCapsule;
 import java.io.IOException;
 
 /**
+ * Cone collision shape represents a 3D cone with a radius, height, and axis (X, Y or Z).
  *
  * @author normenhansen
  */
@@ -52,19 +53,38 @@ public class ConeCollisionShape extends CollisionShape {
     protected float height;
     protected int axis;
 
+    /**
+     * Serialization only, do not use.
+     */
     public ConeCollisionShape() {
     }
 
+    /**
+     * Creates a new cone collision shape with the given height, radius, and axis.
+     *
+     * @param radius The radius of the cone in world units.
+     * @param height The height of the cone in world units.
+     * @param The axis towards which the cone faces, see the PhysicsSpace.AXIS_* constants.
+     */
     public ConeCollisionShape(float radius, float height, int axis) {
         this.radius = radius;
-        this.height = radius;
+        this.height = height;
         this.axis = axis;
+        if (axis < PhysicsSpace.AXIS_X || axis > PhysicsSpace.AXIS_Z) {
+            throw new InvalidArgumentException("axis must be one of the PhysicsSpace.AXIS_* constants!");
+        }
         createShape();
     }
 
+    /**
+     * Creates a new cone collision shape with the given height, radius and default Y axis.
+     *
+     * @param radius The radius of the cone in world units.
+     * @param height The height of the cone in world units.
+     */
     public ConeCollisionShape(float radius, float height) {
         this.radius = radius;
-        this.height = radius;
+        this.height = height;
         this.axis = PhysicsSpace.AXIS_Y;
         createShape();
     }
@@ -72,6 +92,14 @@ public class ConeCollisionShape extends CollisionShape {
     public float getRadius() {
         return radius;
     }
+    
+    public float getHeight() {
+        return height;
+    }
+    
+    public int getAxis() {
+        return axis;
+    }
 
     public void write(JmeExporter ex) throws IOException {
         super.write(ex);
@@ -97,6 +125,8 @@ public class ConeCollisionShape extends CollisionShape {
             cShape = new ConeShape(radius, height);
         } else if (axis == PhysicsSpace.AXIS_Z) {
             cShape = new ConeShapeZ(radius, height);
+        } else {
+            throw new UnsupportedOperationException("Unexpected axis: " + axis);
         }
         cShape.setLocalScaling(Converter.convert(getScale()));
         cShape.setMargin(margin);