use of com.jme3.bullet.joints.PhysicsJoint in project jmonkeyengine by jMonkeyEngine.
the class TestRagDoll method join.
private PhysicsJoint join(Node A, Node B, Vector3f connectionPoint) {
Vector3f pivotA = A.worldToLocal(connectionPoint, new Vector3f());
Vector3f pivotB = B.worldToLocal(connectionPoint, new Vector3f());
ConeJoint joint = new ConeJoint(A.getControl(RigidBodyControl.class), B.getControl(RigidBodyControl.class), pivotA, pivotB);
joint.setLimit(1f, 1f, 0);
return joint;
}
use of com.jme3.bullet.joints.PhysicsJoint in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method removeAll.
/**
* 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);
}
}
}
use of com.jme3.bullet.joints.PhysicsJoint in project jmonkeyengine by jMonkeyEngine.
the class BulletDebugAppState method updateJoints.
private void updateJoints() {
HashMap<PhysicsJoint, Spatial> oldObjects = joints;
joints = new HashMap<PhysicsJoint, Spatial>();
Collection<PhysicsJoint> current = space.getJointList();
//create new map
for (Iterator<PhysicsJoint> it = current.iterator(); it.hasNext(); ) {
PhysicsJoint physicsObject = it.next();
//copy existing spatials
if (oldObjects.containsKey(physicsObject)) {
Spatial spat = oldObjects.get(physicsObject);
joints.put(physicsObject, spat);
oldObjects.remove(physicsObject);
} else {
if (filter == null || filter.displayObject(physicsObject)) {
logger.log(Level.FINE, "Create new debug Joint");
//create new spatial
Node node = new Node(physicsObject.toString());
node.addControl(new BulletJointDebugControl(this, physicsObject));
joints.put(physicsObject, node);
physicsDebugRootNode.attachChild(node);
}
}
}
//remove leftover spatials
for (Map.Entry<PhysicsJoint, Spatial> entry : oldObjects.entrySet()) {
PhysicsJoint object = entry.getKey();
Spatial spatial = entry.getValue();
spatial.removeFromParent();
}
}
use of com.jme3.bullet.joints.PhysicsJoint in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method addAll.
/**
* adds all physics controls and joints in the given spatial node to the physics space
* (e.g. after loading from disk) - recursive if node
* @param spatial the rootnode containing the physics objects
*/
public void addAll(Spatial spatial) {
if (spatial.getControl(RigidBodyControl.class) != null) {
RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class);
add(physicsNode);
//add 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())) {
//add(physicsJoint.getBodyB());
add(physicsJoint);
}
}
} else {
add(spatial);
}
//recursion
if (spatial instanceof Node) {
List<Spatial> children = ((Node) spatial).getChildren();
for (Iterator<Spatial> it = children.iterator(); it.hasNext(); ) {
Spatial spat = it.next();
addAll(spat);
}
}
}
Aggregations