@@ -0,0 +1,2251 @@
+package org.terasology.physics.bullet;%0A%0Aimport java.util.HashMap;%0A%0Aimport javax.vecmath.Vector2f;%0Aimport javax.vecmath.Vector3f;%0A%0Aimport com.bulletphysics.collision.shapes.BoxShape;%0Aimport com.bulletphysics.collision.shapes.CapsuleShape;%0Aimport com.bulletphysics.collision.shapes.ConvexHullShape;%0Aimport com.bulletphysics.collision.shapes.CylinderShape;%0Aimport com.bulletphysics.collision.shapes.SphereShape;%0Aimport com.bulletphysics.util.ObjectArrayList;%0A%0A/**%0A * Flyweight factory (for shapes used in BulletPhysics' getShapeFor method).%0A *%0A * @author FrancoPinoC%0A */%0A%0A%0Apublic class ShapeFactory %7B%0A%09private HashMap%3CVector3f, BoxShape%3E boxPool = new HashMap%3CVector3f, BoxShape%3E();%0A%09private HashMap%3CFloat, SphereShape%3E spherePool = new HashMap%3CFloat, SphereShape%3E();%0A%09private HashMap%3CVector2f, CapsuleShape%3E capsulePool = new HashMap%3CVector2f, CapsuleShape%3E();%0A%09private HashMap%3CVector3f, CylinderShape%3E cylinderPool = new HashMap%3CVector3f, CylinderShape%3E();%0A%09private HashMap%3CObjectArrayList%3CVector3f%3E, ConvexHullShape%3E convexHullPool =%0A%09%09%09new HashMap%3CObjectArrayList%3CVector3f%3E, ConvexHullShape%3E();%0A%09%0A%09public BoxShape getBoxShape(Vector3f scaleVector)%7B%0A%09%09BoxShape ret = boxPool.get(scaleVector);%0A%09%09if(ret==null)%7B%0A%09%09%09ret = new BoxShape(scaleVector);%0A%09%09%09boxPool.put(scaleVector, ret);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09public SphereShape getSphereShape(float radius)%7B%0A%09%09SphereShape ret = spherePool.get(radius);%0A%09%09if(ret==null)%7B%0A%09%09%09ret = new SphereShape(radius);%0A%09%09%09spherePool.put(radius, ret);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09public CapsuleShape getCapsuleShape(float radius, float height)%7B%0A%09%09Vector2f key = new Vector2f(radius, height);%0A%09%09CapsuleShape ret = capsulePool.get(key);%0A%09%09if(ret==null)%7B%0A%09%09%09ret = new CapsuleShape(radius, height);%0A%09%09%09capsulePool.put(key, ret);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09public CylinderShape getCylinderShape(Vector3f scalesVector)%7B%0A%09%09CylinderShape ret = cylinderPool.get(scalesVector);%0A%09%09if(ret==null)%7B%0A%09%09%09ret = new CylinderShape(scalesVector);%0A%09%09%09cylinderPool.put(scalesVector, ret);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09public ConvexHullShape getConvexHullShape(ObjectArrayList%3CVector3f%3E verts)%7B%0A%09%09ConvexHullShape ret = convexHullPool.get(verts);%0A%09%09if(ret==null)%7B%0A%09%09%09ret = new ConvexHullShape(verts);%0A%09%09%09convexHullPool.put(verts, ret);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%7D%0A

Create ShapeFactory.java