use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method boneRecursion.
protected void boneRecursion(Spatial model, Bone bone, PhysicsRigidBody parent, int reccount, Map<Integer, List<Float>> pointsMap) {
PhysicsRigidBody parentShape = parent;
if (boneList.isEmpty() || boneList.contains(bone.getName())) {
PhysicsBoneLink link = new PhysicsBoneLink();
link.bone = bone;
//creating the collision shape
HullCollisionShape shape = null;
if (pointsMap != null) {
//build a shape for the bone, using the vertices that are most influenced by this bone
shape = RagdollUtils.makeShapeFromPointMap(pointsMap, RagdollUtils.getBoneIndices(link.bone, skeleton, boneList), initScale, link.bone.getModelSpacePosition());
} else {
//build a shape for the bone, using the vertices associated with this bone with a weight above the threshold
shape = RagdollUtils.makeShapeFromVerticeWeights(model, RagdollUtils.getBoneIndices(link.bone, skeleton, boneList), initScale, link.bone.getModelSpacePosition(), weightThreshold);
}
PhysicsRigidBody shapeNode = new PhysicsRigidBody(shape, rootMass / (float) reccount);
shapeNode.setKinematic(mode == Mode.Kinematic);
totalMass += rootMass / (float) reccount;
link.rigidBody = shapeNode;
link.initalWorldRotation = bone.getModelSpaceRotation().clone();
if (parent != null) {
//get joint position for parent
Vector3f posToParent = new Vector3f();
if (bone.getParent() != null) {
bone.getModelSpacePosition().subtract(bone.getParent().getModelSpacePosition(), posToParent).multLocal(initScale);
}
SixDofJoint joint = new SixDofJoint(parent, shapeNode, posToParent, new Vector3f(0, 0, 0f), true);
preset.setupJointForBone(bone.getName(), joint);
link.joint = joint;
joint.setCollisionBetweenLinkedBodys(false);
}
boneLinks.put(bone.getName(), link);
shapeNode.setUserObject(link);
parentShape = shapeNode;
}
for (Iterator<Bone> it = bone.getChildren().iterator(); it.hasNext(); ) {
Bone childBone = it.next();
boneRecursion(model, childBone, parentShape, reccount + 1, pointsMap);
}
}
use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.
the class PhysicsRigidBody method getAngularVelocity.
/**
* Get the current angular velocity of this PhysicsRigidBody
* @return the current linear velocity
*/
public Vector3f getAngularVelocity() {
Vector3f vec = new Vector3f();
getAngularVelocity(objectId, vec);
return vec;
}
use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.
the class PhysicsRigidBody method getLinearVelocity.
/**
* Get the current linear velocity of this PhysicsRigidBody
* @return the current linear velocity
*/
public Vector3f getLinearVelocity() {
Vector3f vec = new Vector3f();
getLinearVelocity(objectId, vec);
return vec;
}
use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.
the class BetterCharacterControl method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule in = im.getCapsule(this);
this.radius = in.readFloat("radius", 1);
this.height = in.readFloat("height", 2);
this.mass = in.readFloat("mass", 80);
this.physicsDamping = in.readFloat("physicsDamping", 0.9f);
this.jumpForce.set((Vector3f) in.readSavable("jumpForce", new Vector3f(0, mass * 5, 0)));
rigidBody = new PhysicsRigidBody(getShape(), mass);
jumpForce.set(new Vector3f(0, mass * 5, 0));
rigidBody.setAngularFactor(0);
}
use of com.jme3.bullet.objects.PhysicsRigidBody in project jmonkeyengine by jMonkeyEngine.
the class BulletDebugAppState method updateRigidBodies.
private void updateRigidBodies() {
HashMap<PhysicsRigidBody, Spatial> oldObjects = bodies;
bodies = new HashMap<PhysicsRigidBody, Spatial>();
Collection<PhysicsRigidBody> current = space.getRigidBodyList();
//create new map
for (Iterator<PhysicsRigidBody> it = current.iterator(); it.hasNext(); ) {
PhysicsRigidBody physicsObject = it.next();
//copy existing spatials
if (oldObjects.containsKey(physicsObject)) {
Spatial spat = oldObjects.get(physicsObject);
bodies.put(physicsObject, spat);
oldObjects.remove(physicsObject);
} else {
if (filter == null || filter.displayObject(physicsObject)) {
logger.log(Level.FINE, "Create new debug RigidBody");
//create new spatial
Node node = new Node(physicsObject.toString());
node.addControl(new BulletRigidBodyDebugControl(this, physicsObject));
bodies.put(physicsObject, node);
physicsDebugRootNode.attachChild(node);
}
}
}
//remove leftover spatials
for (Map.Entry<PhysicsRigidBody, Spatial> entry : oldObjects.entrySet()) {
PhysicsRigidBody object = entry.getKey();
Spatial spatial = entry.getValue();
spatial.removeFromParent();
}
}
Aggregations