Example #1
0
 private CollisionShape rotate(CollisionShape shape, Quat4f rot) {
   if (shape instanceof BoxShape) {
     BoxShape box = (BoxShape) shape;
     javax.vecmath.Vector3f extents = box.getHalfExtentsWithMargin(new javax.vecmath.Vector3f());
     com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), extents, extents);
     extents.absolute();
     return new BoxShape(extents);
   } else if (shape instanceof CompoundShape) {
     CompoundShape compound = (CompoundShape) shape;
     CompoundShape newShape = new CompoundShape();
     for (CompoundShapeChild child : compound.getChildList()) {
       CollisionShape rotatedChild = rotate(child.childShape, rot);
       javax.vecmath.Vector3f offset =
           com.bulletphysics.linearmath.QuaternionUtil.quatRotate(
               VecMath.to(rot), child.transform.origin, new javax.vecmath.Vector3f());
       newShape.addChildShape(
           new Transform(
               new javax.vecmath.Matrix4f(VecMath.to(Rotation.none().getQuat4f()), offset, 1.0f)),
           rotatedChild);
     }
     return newShape;
   } else if (shape instanceof ConvexHullShape) {
     ConvexHullShape convexHull = (ConvexHullShape) shape;
     ObjectArrayList<javax.vecmath.Vector3f> transformedVerts = new ObjectArrayList<>();
     for (javax.vecmath.Vector3f vert : convexHull.getPoints()) {
       transformedVerts.add(
           com.bulletphysics.linearmath.QuaternionUtil.quatRotate(
               VecMath.to(rot), vert, new javax.vecmath.Vector3f()));
     }
     return new ConvexHullShape(transformedVerts);
   }
   return shape;
 }