/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is enabled and added to a scene. Should be * invoked only by a subclass or by AbstractControl. * * @param tpf the time interval between frames (in seconds, ≥0) */ @Override protected void controlUpdate(float tpf) { body.getBodyA().getPhysicsLocation(a.getTranslation()); body.getBodyA().getPhysicsRotation(a.getRotation()); body.getBodyB().getPhysicsLocation(b.getTranslation()); body.getBodyB().getPhysicsRotation(b.getRotation()); geomA.setLocalTransform(a); geomB.setLocalTransform(b); arrowA.setArrowExtent(body.getPivotA()); arrowB.setArrowExtent(body.getPivotB()); }
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.", joint.getObjectId()); physicsJoints.put(joint.getObjectId(), joint); dynamicsWorld.addConstraint(joint.getObjectId(), !joint.isCollisionBetweenLinkedBodys()); }
@Override public void read(JmeImporter im) throws IOException { super.read(im); createJoint(); InputCapsule cap=im.getCapsule(this); setDamping(cap.readFloat("damping", 1.0f)); setDamping(cap.readFloat("tau", 0.3f)); setDamping(cap.readFloat("impulseClamp", 0f)); }
@Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule cap = ex.getCapsule(this); cap.write(getDamping(), "damping", 1.0f); cap.write(getTau(), "tau", 0.3f); cap.write(getImpulseClamp(), "impulseClamp", 0f); }
@Override protected Spatial getDebugShape() { //add joints Spatial shape = super.getDebugShape(); Node node = null; if (shape instanceof Node) { node = (Node) shape; } else { node = new Node("DebugShapeNode"); node.attachChild(shape); } int i = 0; for (Iterator<PhysicsJoint> it = joints.iterator(); it.hasNext();) { PhysicsJoint physicsJoint = it.next(); Vector3f pivot = null; if (physicsJoint.getBodyA() == this) { pivot = physicsJoint.getPivotA(); } else { pivot = physicsJoint.getPivotB(); } Arrow arrow = new Arrow(pivot); Geometry geom = new Geometry("DebugBone" + i, arrow); geom.setMaterial(debugMaterialGreen); node.attachChild(geom); i++; } return node; }
/** * 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(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); } } }
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.", joint.getObjectId()); physicsJoints.remove(joint.getObjectId()); dynamicsWorld.removeConstraint(joint.getObjectId()); }
/** * Finalize this physics joint just before it is destroyed. Should be * invoked only by a subclass or by the garbage collector. * * @throws Throwable ignored by the garbage collector */ @Override protected void finalize() throws Throwable { super.finalize(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Joint {0}", Long.toHexString(objectId)); finalizeNative(objectId); }
private native float getAppliedImpulse(long objectId);
/** * Serialize this joint, for example when saving to a J3O file. * * @param ex exporter (not null) * @throws IOException from exporter */ @Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule cap = ex.getCapsule(this); cap.write(getDamping(), "damping", 1.0f); cap.write(getTau(), "tau", 0.3f); cap.write(getImpulseClamp(), "impulseClamp", 0f); }
/** * Add all collision objects and joints in the specified subtree of the * scene graph to this space (e.g. after loading from disk). Note: * recursive! * * @param spatial the root of the subtree (not null) */ public void addAll(Spatial spatial) { add(spatial); if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); //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); } } } //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); } } }
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()); }
@Override protected void finalize() throws Throwable { super.finalize(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Joint {0}", Long.toHexString(objectId)); finalizeNative(objectId); }
private native float getAppliedImpulse(long objectId);
/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is enabled and added to a scene. Should be * invoked only by a subclass or by AbstractControl. * * @param tpf the time interval between frames (in seconds, ≥0) */ @Override protected void controlUpdate(float tpf) { body.getBodyA().getPhysicsLocation(a.getTranslation()); body.getBodyA().getPhysicsRotation(a.getRotation()); body.getBodyB().getPhysicsLocation(b.getTranslation()); body.getBodyB().getPhysicsRotation(b.getRotation()); geomA.setLocalTransform(a); geomB.setLocalTransform(b); arrowA.setArrowExtent(body.getPivotA()); arrowB.setArrowExtent(body.getPivotB()); }
/** * De-serialize this joint, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ @Override public void read(JmeImporter im) throws IOException { super.read(im); createJoint(); InputCapsule cap = im.getCapsule(this); setDamping(cap.readFloat("damping", 1.0f)); setDamping(cap.readFloat("tau", 0.3f)); setDamping(cap.readFloat("impulseClamp", 0f)); }
@Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); capsule.write(rotA, "rotA", new Matrix3f()); capsule.write(rotB, "rotB", new Matrix3f()); capsule.write(angularOnly, "angularOnly", false); capsule.write(swingSpan1, "swingSpan1", 1e30f); capsule.write(swingSpan2, "swingSpan2", 1e30f); capsule.write(twistSpan, "twistSpan", 1e30f); }