From 85059fd8a057fa4fab46b8077b97bc492436d1cd Mon Sep 17 00:00:00 2001 From: "Sha..om" Date: Mon, 26 Nov 2012 17:05:41 +0000 Subject: [PATCH] * 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 --- .../collision/shapes/ConeCollisionShape.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java b/engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java index 009db6ce9..36c9ced5d 100644 --- a/engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java +++ b/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);