use of com.bulletphysics.dynamics.RigidBodyConstructionInfo in project Terasology by MovingBlocks.
the class BulletPhysics method newRigidBody.
private RigidBody newRigidBody(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
RigidBodyComponent rigidBody = entity.getComponent(RigidBodyComponent.class);
ConvexShape shape = getShapeFor(entity);
if (location != null && rigidBody != null && shape != null) {
float scale = location.getWorldScale();
shape.setLocalScaling(new Vector3f(scale, scale, scale));
if (rigidBody.mass < 1) {
logger.warn("RigidBodyComponent.mass is set to less than 1.0, this can lead to strange behaviour, such as the objects moving through walls. " + "Entity: {}", entity);
}
Vector3f fallInertia = new Vector3f();
shape.calculateLocalInertia(rigidBody.mass, fallInertia);
RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(rigidBody.mass, new EntityMotionState(entity), shape, fallInertia);
BulletRigidBody collider = new BulletRigidBody(info);
collider.rb.setUserPointer(entity);
collider.rb.setAngularFactor(VecMath.to(rigidBody.angularFactor));
collider.rb.setLinearFactor(VecMath.to(rigidBody.linearFactor));
collider.rb.setFriction(rigidBody.friction);
collider.rb.setRestitution(rigidBody.restitution);
collider.collidesWith = combineGroups(rigidBody.collidesWith);
updateKinematicSettings(rigidBody, collider);
BulletRigidBody oldBody = entityRigidBodies.put(entity, collider);
addRigidBody(collider, Lists.<CollisionGroup>newArrayList(rigidBody.collisionGroup), rigidBody.collidesWith);
if (oldBody != null) {
removeRigidBody(oldBody);
}
collider.setVelocity(rigidBody.velocity, rigidBody.angularVelocity);
collider.setTransform(location.getWorldPosition(), location.getWorldRotation());
return collider;
} else {
throw new IllegalArgumentException("Can only create a new rigid body for entities with a LocationComponent," + " RigidBodyComponent and ShapeComponent, this entity misses at least one: " + entity);
}
}
use of com.bulletphysics.dynamics.RigidBodyConstructionInfo in project jmonkeyengine by jMonkeyEngine.
the class PhysicsRigidBody method preRebuild.
protected void preRebuild() {
collisionShape.calculateLocalInertia(mass, localInertia);
if (constructionInfo == null) {
constructionInfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape.getCShape(), localInertia);
} else {
constructionInfo.mass = mass;
constructionInfo.collisionShape = collisionShape.getCShape();
constructionInfo.motionState = motionState;
}
}
Aggregations