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;
}
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();
}
}
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();
}
Aggregations