Esempio n. 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;
 }
Esempio n. 2
0
  public void parent(GameObject p, boolean compound) {
    CompoundShape compShapeOld = null;

    if (parent != null) {
      parent.children.remove(this);

      if (compound) {
        compShapeOld = parent.compoundShape();
        if (compShapeOld != null) {
          scene.world.removeRigidBody(parent.body);
          compShapeOld.removeChildShape(body.getCollisionShape());
          scene.world.addRigidBody(parent.body);
        }
      }

    } else if (p == null) {
      return;
    }

    parent = p;

    if (parent != null) {

      parent.children.add(this);

      updateLocalTransform();
      updateLocalScale();

      if (compound) {
        CompoundShape compShape = parent.compoundShape();
        if (compShape != null) {
          scene.world.removeRigidBody(body);
          compShape.addChildShape(new Transform(localTransform), body.getCollisionShape());
        }
      } else {
        dynamics(false);
      }

    } else if (currBodyType.equals("STATIC") || currBodyType.equals("SENSOR")) {
      if (compound && compShapeOld != null) scene.world.addRigidBody(body);

    } else {
      dynamics(true);
    }
  }