* 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
3.0
Sha..om 12 years ago
parent eea91e0b20
commit 85059fd8a0
  1. 34
      engine/src/jbullet/com/jme3/bullet/collision/shapes/ConeCollisionShape.java

@ -43,6 +43,7 @@ import com.jme3.export.OutputCapsule;
import java.io.IOException; import java.io.IOException;
/** /**
* Cone collision shape represents a 3D cone with a radius, height, and axis (X, Y or Z).
* *
* @author normenhansen * @author normenhansen
*/ */
@ -52,19 +53,38 @@ public class ConeCollisionShape extends CollisionShape {
protected float height; protected float height;
protected int axis; protected int axis;
/**
* Serialization only, do not use.
*/
public ConeCollisionShape() { 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) { public ConeCollisionShape(float radius, float height, int axis) {
this.radius = radius; this.radius = radius;
this.height = radius; this.height = height;
this.axis = axis; 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(); 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) { public ConeCollisionShape(float radius, float height) {
this.radius = radius; this.radius = radius;
this.height = radius; this.height = height;
this.axis = PhysicsSpace.AXIS_Y; this.axis = PhysicsSpace.AXIS_Y;
createShape(); createShape();
} }
@ -73,6 +93,14 @@ public class ConeCollisionShape extends CollisionShape {
return radius; return radius;
} }
public float getHeight() {
return height;
}
public int getAxis() {
return axis;
}
public void write(JmeExporter ex) throws IOException { public void write(JmeExporter ex) throws IOException {
super.write(ex); super.write(ex);
OutputCapsule capsule = ex.getCapsule(this); OutputCapsule capsule = ex.getCapsule(this);
@ -97,6 +125,8 @@ public class ConeCollisionShape extends CollisionShape {
cShape = new ConeShape(radius, height); cShape = new ConeShape(radius, height);
} else if (axis == PhysicsSpace.AXIS_Z) { } else if (axis == PhysicsSpace.AXIS_Z) {
cShape = new ConeShapeZ(radius, height); cShape = new ConeShapeZ(radius, height);
} else {
throw new UnsupportedOperationException("Unexpected axis: " + axis);
} }
cShape.setLocalScaling(Converter.convert(getScale())); cShape.setLocalScaling(Converter.convert(getScale()));
cShape.setMargin(margin); cShape.setMargin(margin);

Loading…
Cancel
Save