1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 package com.jme3.bullet.collision.shapes; 6 7 import com.jme3.bullet.PhysicsSpace; 8 import com.jme3.export.InputCapsule; 9 import com.jme3.export.JmeExporter; 10 import com.jme3.export.JmeImporter; 11 import com.jme3.export.OutputCapsule; 12 import java.io.IOException; 13 import java.util.logging.Level; 14 import java.util.logging.Logger; 15 16 /** 17 * 18 * @author normenhansen 19 */ 20 public class ConeCollisionShape extends CollisionShape { 21 22 protected float radius; 23 protected float height; 24 protected int axis; 25 26 public ConeCollisionShape() { 27 } 28 29 public ConeCollisionShape(float radius, float height, int axis) { 30 this.radius = radius; 31 this.height = radius; 32 this.axis = axis; 33 createShape(); 34 } 35 36 public ConeCollisionShape(float radius, float height) { 37 this.radius = radius; 38 this.height = radius; 39 this.axis = PhysicsSpace.AXIS_Y; 40 createShape(); 41 } 42 43 public float getRadius() { 44 return radius; 45 } 46 47 public void write(JmeExporter ex) throws IOException { 48 super.write(ex); 49 OutputCapsule capsule = ex.getCapsule(this); 50 capsule.write(radius, "radius", 0.5f); 51 capsule.write(height, "height", 0.5f); 52 capsule.write(axis, "axis", 0.5f); 53 } 54 55 public void read(JmeImporter im) throws IOException { 56 super.read(im); 57 InputCapsule capsule = im.getCapsule(this); 58 radius = capsule.readFloat("radius", 0.5f); 59 radius = capsule.readFloat("height", 0.5f); 60 radius = capsule.readFloat("axis", 0.5f); 61 createShape(); 62 } 63 64 protected void createShape() { 65 objectId = createShape(axis, radius, height); 66 Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Shape {0}", Long.toHexString(objectId)); 67 // if (axis == PhysicsSpace.AXIS_X) { 68 // objectId = new ConeShapeX(radius, height); 69 // } else if (axis == PhysicsSpace.AXIS_Y) { 70 // objectId = new ConeShape(radius, height); 71 // } else if (axis == PhysicsSpace.AXIS_Z) { 72 // objectId = new ConeShapeZ(radius, height); 73 // } 74 // objectId.setLocalScaling(Converter.convert(getScale())); 75 // objectId.setMargin(margin); 76 setScale(scale); 77 setMargin(margin); 78 } 79 80 private native long createShape(int axis, float radius, float height); 81 } 82