159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * To change this template, choose Tools | Templates 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * and open the template in the editor. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.bullet.collision.shapes; 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.PhysicsSpace; 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.InputCapsule; 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeExporter; 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeImporter; 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.OutputCapsule; 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.io.IOException; 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.logging.Level; 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.logging.Logger; 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class ConeCollisionShape extends CollisionShape { 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected float radius; 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected float height; 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected int axis; 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public ConeCollisionShape() { 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public ConeCollisionShape(float radius, float height, int axis) { 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.radius = radius; 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.height = radius; 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.axis = axis; 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta createShape(); 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public ConeCollisionShape(float radius, float height) { 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.radius = radius; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.height = radius; 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.axis = PhysicsSpace.AXIS_Y; 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta createShape(); 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public float getRadius() { 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return radius; 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void write(JmeExporter ex) throws IOException { 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.write(ex); 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta OutputCapsule capsule = ex.getCapsule(this); 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(radius, "radius", 0.5f); 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(height, "height", 0.5f); 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(axis, "axis", 0.5f); 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void read(JmeImporter im) throws IOException { 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.read(im); 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta InputCapsule capsule = im.getCapsule(this); 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta radius = capsule.readFloat("radius", 0.5f); 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta radius = capsule.readFloat("height", 0.5f); 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta radius = capsule.readFloat("axis", 0.5f); 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta createShape(); 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected void createShape() { 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta objectId = createShape(axis, radius, height); 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Shape {0}", Long.toHexString(objectId)); 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// if (axis == PhysicsSpace.AXIS_X) { 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// objectId = new ConeShapeX(radius, height); 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// } else if (axis == PhysicsSpace.AXIS_Y) { 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// objectId = new ConeShape(radius, height); 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// } else if (axis == PhysicsSpace.AXIS_Z) { 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// objectId = new ConeShapeZ(radius, height); 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// } 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// objectId.setLocalScaling(Converter.convert(getScale())); 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta// objectId.setMargin(margin); 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setScale(scale); 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setMargin(margin); 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native long createShape(int axis, float radius, float height); 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 82