Search in sources :

Example 1 with RigidBodyComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent in project nhglib by VoidZombie.

the class RigidBodyComponentJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    RigidBodyComponent rigidBodyComponent = entities.createComponent(entity, RigidBodyComponent.class);
    JsonValue shapeJson = jsonValue.get("shape");
    String activationStateString = jsonValue.getString("activationState", "wantsDeactivation");
    ActivationState activationStateJson = ActivationState.fromString(activationStateString);
    btCollisionShape collisionShape = getCollisionShape(shapeJson);
    int activationState = activationStateJson.state;
    float mass = jsonValue.getFloat("mass", 1.0f);
    float friction = jsonValue.getFloat("friction", 0.5f);
    float restitution = jsonValue.getFloat("restitution", 0f);
    rigidBodyComponent.build(collisionShape, activationState, mass, friction, restitution);
    output = rigidBodyComponent;
}
Also used : RigidBodyComponent(io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent) JsonValue(com.badlogic.gdx.utils.JsonValue) ActivationState(io.github.voidzombie.nhglib.data.models.serialization.physics.ActivationState) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape)

Example 2 with RigidBodyComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent in project nhglib by VoidZombie.

the class PhysicsSystem method process.

@Override
protected void process(int entityId) {
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    RigidBodyComponent bodyComponent = rigidBodyMapper.get(entityId);
    if (!bodyComponent.isAdded()) {
        Matrix4 initialTransform = new Matrix4();
        Vector3 trn = nodeComponent.getTranslation();
        Vector3 scl = new Vector3(1, 1, 1);
        Quaternion rtn = nodeComponent.getRotationQuaternion();
        initialTransform.set(trn, rtn, scl);
        bodyComponent.addToWorld(dynamicsWorld, initialTransform);
    } else {
        nodeComponent.setTranslation(bodyComponent.getTranslation());
        nodeComponent.setRotation(bodyComponent.getRotation());
        nodeComponent.applyTransforms();
    }
}
Also used : RigidBodyComponent(io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent) Quaternion(com.badlogic.gdx.math.Quaternion) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 3 with RigidBodyComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent in project nhglib by VoidZombie.

the class PhysicsSystem method dispose.

@Override
public void dispose() {
    IntBag entityIds = getEntityIds();
    for (int entity : entityIds.getData()) {
        RigidBodyComponent bodyComponent = rigidBodyMapper.get(entity);
        if (bodyComponent != null) {
            bodyComponent.dispose();
        }
    }
    dynamicsWorld.dispose();
    constraintSolver.dispose();
    collisionConfiguration.dispose();
    collisionDispatcher.dispose();
    dbvtBroadphase.dispose();
}
Also used : RigidBodyComponent(io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent) IntBag(com.artemis.utils.IntBag)

Aggregations

RigidBodyComponent (io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent)3 IntBag (com.artemis.utils.IntBag)1 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Quaternion (com.badlogic.gdx.math.Quaternion)1 Vector3 (com.badlogic.gdx.math.Vector3)1 com.badlogic.gdx.physics.bullet.collision.btCollisionShape (com.badlogic.gdx.physics.bullet.collision.btCollisionShape)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 ActivationState (io.github.voidzombie.nhglib.data.models.serialization.physics.ActivationState)1 NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)1