예제 #1
0
 /**
  * Removes all physics controls and joints in the given spatial from the physics space (e.g.
  * before saving to disk) - recursive if node
  *
  * @param spatial the rootnode containing the physics objects
  */
 public void removeAll(Spatial spatial) {
   if (spatial.getControl(RigidBodyControl.class) != null) {
     RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class);
     // remove joints with physicsNode as BodyA
     List<PhysicsJoint> joints = physicsNode.getJoints();
     for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext(); ) {
       PhysicsJoint physicsJoint = it1.next();
       if (physicsNode.equals(physicsJoint.getBodyA())) {
         removeJoint(physicsJoint);
         // remove(physicsJoint.getBodyB());
       }
     }
     remove(physicsNode);
   } else if (spatial.getControl(PhysicsControl.class) != null) {
     remove(spatial);
   }
   // recursion
   if (spatial instanceof Node) {
     List<Spatial> children = ((Node) spatial).getChildren();
     for (Iterator<Spatial> it = children.iterator(); it.hasNext(); ) {
       Spatial spat = it.next();
       removeAll(spat);
     }
   }
 }
예제 #2
0
 private void addJoint(PhysicsJoint joint) {
   if (physicsJoints.containsKey(joint.getObjectId())) {
     logger.log(Level.WARNING, "Joint {0} already exists in PhysicsSpace, cannot add.", joint);
     return;
   }
   logger.log(
       Level.FINE, "Adding Joint {0} to physics space.", Long.toHexString(joint.getObjectId()));
   physicsJoints.put(joint.getObjectId(), joint);
   addConstraintC(physicsSpaceId, joint.getObjectId(), !joint.isCollisionBetweenLinkedBodys());
   //        dynamicsWorld.addConstraint(joint.getObjectId(),
   // !joint.isCollisionBetweenLinkedBodys());
 }
예제 #3
0
 private void removeJoint(PhysicsJoint joint) {
   if (!physicsJoints.containsKey(joint.getObjectId())) {
     logger.log(Level.WARNING, "Joint {0} does not exist in PhysicsSpace, cannot remove.", joint);
     return;
   }
   logger.log(
       Level.FINE,
       "Removing Joint {0} from physics space.",
       Long.toHexString(joint.getObjectId()));
   physicsJoints.remove(joint.getObjectId());
   removeConstraint(physicsSpaceId, joint.getObjectId());
   //        dynamicsWorld.removeConstraint(joint.getObjectId());
 }