159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * To change this template, choose Tools | Templates 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * and open the template in the editor. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.bullet.collision.shapes; 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.bulletphysics.collision.shapes.StaticPlaneShape; 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.util.Converter; 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.InputCapsule; 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeExporter; 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeImporter; 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.OutputCapsule; 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Plane; 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.io.IOException; 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class PlaneCollisionShape extends CollisionShape{ 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private Plane plane; 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PlaneCollisionShape() { 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Creates a plane Collision shape 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param plane the plane that defines the shape 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PlaneCollisionShape(Plane plane) { 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.plane = plane; 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta createShape(); 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public final Plane getPlane() { 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return plane; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void write(JmeExporter ex) throws IOException { 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.write(ex); 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta OutputCapsule capsule = ex.getCapsule(this); 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(plane, "collisionPlane", new Plane()); 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void read(JmeImporter im) throws IOException { 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.read(im); 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta InputCapsule capsule = im.getCapsule(this); 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta createShape(); 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected void createShape() { 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta cShape = new StaticPlaneShape(Converter.convert(plane.getNormal()),plane.getConstant()); 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta cShape.setLocalScaling(Converter.convert(getScale())); 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta cShape.setMargin(margin); 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 60