Home | History | Annotate | Download | only in shapes
      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.bulletphysics.collision.shapes.ConeShape;
      8 import com.bulletphysics.collision.shapes.ConeShapeX;
      9 import com.bulletphysics.collision.shapes.ConeShapeZ;
     10 import com.jme3.bullet.PhysicsSpace;
     11 import com.jme3.bullet.util.Converter;
     12 import com.jme3.export.InputCapsule;
     13 import com.jme3.export.JmeExporter;
     14 import com.jme3.export.JmeImporter;
     15 import com.jme3.export.OutputCapsule;
     16 import java.io.IOException;
     17 
     18 /**
     19  *
     20  * @author normenhansen
     21  */
     22 public class ConeCollisionShape extends CollisionShape {
     23 
     24     protected float radius;
     25     protected float height;
     26     protected int axis;
     27 
     28     public ConeCollisionShape() {
     29     }
     30 
     31     public ConeCollisionShape(float radius, float height, int axis) {
     32         this.radius = radius;
     33         this.height = radius;
     34         this.axis = axis;
     35         createShape();
     36     }
     37 
     38     public ConeCollisionShape(float radius, float height) {
     39         this.radius = radius;
     40         this.height = radius;
     41         this.axis = PhysicsSpace.AXIS_Y;
     42         createShape();
     43     }
     44 
     45     public float getRadius() {
     46         return radius;
     47     }
     48 
     49     public void write(JmeExporter ex) throws IOException {
     50         super.write(ex);
     51         OutputCapsule capsule = ex.getCapsule(this);
     52         capsule.write(radius, "radius", 0.5f);
     53         capsule.write(height, "height", 0.5f);
     54         capsule.write(axis, "axis", 0.5f);
     55     }
     56 
     57     public void read(JmeImporter im) throws IOException {
     58         super.read(im);
     59         InputCapsule capsule = im.getCapsule(this);
     60         radius = capsule.readFloat("radius", 0.5f);
     61         radius = capsule.readFloat("height", 0.5f);
     62         radius = capsule.readFloat("axis", 0.5f);
     63         createShape();
     64     }
     65 
     66     protected void createShape() {
     67         if (axis == PhysicsSpace.AXIS_X) {
     68             cShape = new ConeShapeX(radius, height);
     69         } else if (axis == PhysicsSpace.AXIS_Y) {
     70             cShape = new ConeShape(radius, height);
     71         } else if (axis == PhysicsSpace.AXIS_Z) {
     72             cShape = new ConeShapeZ(radius, height);
     73         }
     74         cShape.setLocalScaling(Converter.convert(getScale()));
     75         cShape.setMargin(margin);
     76     }
     77 }
     78