Search in sources :

Example 1 with RigidBodyConstructionInfo

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);
    }
}
Also used : RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) Vector3f(javax.vecmath.Vector3f) ConvexShape(com.bulletphysics.collision.shapes.ConvexShape) LocationComponent(org.terasology.logic.location.LocationComponent) RigidBodyConstructionInfo(com.bulletphysics.dynamics.RigidBodyConstructionInfo)

Example 2 with RigidBodyConstructionInfo

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;
    }
}
Also used : RigidBodyConstructionInfo(com.bulletphysics.dynamics.RigidBodyConstructionInfo)

Aggregations

RigidBodyConstructionInfo (com.bulletphysics.dynamics.RigidBodyConstructionInfo)2 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)1 Vector3f (javax.vecmath.Vector3f)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 RigidBodyComponent (org.terasology.physics.components.RigidBodyComponent)1