1/* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5package com.jme3.bullet.collision.shapes; 6 7import com.bulletphysics.collision.shapes.BU_Simplex1to4; 8import com.jme3.bullet.util.Converter; 9import com.jme3.export.InputCapsule; 10import com.jme3.export.JmeExporter; 11import com.jme3.export.JmeImporter; 12import com.jme3.export.OutputCapsule; 13import com.jme3.math.Vector3f; 14import java.io.IOException; 15 16/** 17 * A simple point, line, triangle or quad collisionShape based on one to four points- 18 * @author normenhansen 19 */ 20public class SimplexCollisionShape extends CollisionShape { 21 22 private Vector3f vector1, vector2, vector3, vector4; 23 24 public SimplexCollisionShape() { 25 } 26 27 public SimplexCollisionShape(Vector3f point1, Vector3f point2, Vector3f point3, Vector3f point4) { 28 vector1 = point1; 29 vector2 = point2; 30 vector3 = point3; 31 vector4 = point4; 32 createShape(); 33 } 34 35 public SimplexCollisionShape(Vector3f point1, Vector3f point2, Vector3f point3) { 36 vector1 = point1; 37 vector2 = point2; 38 vector3 = point3; 39 createShape(); 40 } 41 42 public SimplexCollisionShape(Vector3f point1, Vector3f point2) { 43 vector1 = point1; 44 vector2 = point2; 45 createShape(); 46 } 47 48 public SimplexCollisionShape(Vector3f point1) { 49 vector1 = point1; 50 createShape(); 51 } 52 53 public void write(JmeExporter ex) throws IOException { 54 super.write(ex); 55 OutputCapsule capsule = ex.getCapsule(this); 56 capsule.write(vector1, "simplexPoint1", null); 57 capsule.write(vector2, "simplexPoint2", null); 58 capsule.write(vector3, "simplexPoint3", null); 59 capsule.write(vector4, "simplexPoint4", null); 60 } 61 62 public void read(JmeImporter im) throws IOException { 63 super.read(im); 64 InputCapsule capsule = im.getCapsule(this); 65 vector1 = (Vector3f) capsule.readSavable("simplexPoint1", null); 66 vector2 = (Vector3f) capsule.readSavable("simplexPoint2", null); 67 vector3 = (Vector3f) capsule.readSavable("simplexPoint3", null); 68 vector4 = (Vector3f) capsule.readSavable("simplexPoint4", null); 69 createShape(); 70 } 71 72 protected void createShape() { 73 if (vector4 != null) { 74 cShape = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2), Converter.convert(vector3), Converter.convert(vector4)); 75 } else if (vector3 != null) { 76 cShape = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2), Converter.convert(vector3)); 77 } else if (vector2 != null) { 78 cShape = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2)); 79 } else { 80 cShape = new BU_Simplex1to4(Converter.convert(vector1)); 81 } 82 cShape.setLocalScaling(Converter.convert(getScale())); 83 cShape.setMargin(margin); 84 } 85} 86