Search in sources :

Example 6 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent 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 7 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class CameraSystem method process.

@Override
protected void process(int entityId) {
    CameraComponent cameraComponent = cameraMapper.get(entityId);
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    Camera camera = cameraComponent.camera;
    camera.position.set(nodeComponent.getTranslation());
    camera.direction.rotate(camera.up, nodeComponent.getYRotationDelta());
    camera.up.rotate(camera.direction, nodeComponent.getZRotationDelta());
    vec.set(camera.direction).crs(camera.up).nor();
    camera.direction.rotate(vec, nodeComponent.getXRotationDelta());
    camera.update();
    if (!cameras.contains(camera, true)) {
        cameras.add(camera);
    }
}
Also used : NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) CameraComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent) Camera(com.badlogic.gdx.graphics.Camera)

Example 8 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class SceneJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    String name = jsonValue.getString("name");
    JsonValue entitiesJson = jsonValue.get("entities");
    output = new Scene(entities, "root");
    output.name = name;
    int rootEntity = output.sceneGraph.getRootEntity();
    if (entitiesJson != null) {
        for (JsonValue entity : entitiesJson) {
            EntityJson entityJson = new EntityJson(entities);
            entityJson.setSceneGraph(output.sceneGraph);
            entityJson.setParentEntity(rootEntity);
            entityJson.parse(entity);
        }
    }
    NodeComponent nodeComponent = entities.getComponent(rootEntity, NodeComponent.class);
    nodeComponent.applyTransforms();
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) Scene(io.github.voidzombie.nhglib.graphics.scenes.Scene)

Example 9 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class GraphicsSystem method process.

@Override
protected void process(int entityId) {
    ModelComponent modelComponent = modelMapper.get(entityId);
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    if (modelComponent.enabled) {
        if (modelComponent.animationController != null) {
            modelComponent.animationController.update(Gdx.graphics.getDeltaTime());
        }
        if (modelComponent.type == ModelComponent.Type.DYNAMIC && modelComponent.model != null) {
            modelComponent.model.transform.set(nodeComponent.getTransform());
            for (ModelCache modelCache : dynamicCaches) {
                modelCache.add(modelComponent.model);
            }
        }
    }
}
Also used : ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Example 10 with NodeComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.

the class SceneGraph method addSceneEntity.

public int addSceneEntity(int entity, int parentEntity) {
    NodeComponent nodeComponent = entities.getComponent(entity, NodeComponent.class);
    nodeComponent.id = entity;
    NodeComponent parentNodeComponent = entities.getComponent(parentEntity, NodeComponent.class);
    parentNodeComponent.node.addChild(nodeComponent.node);
    entitiesArray.add(entity);
    return entity;
}
Also used : NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Aggregations

NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)13 JsonValue (com.badlogic.gdx.utils.JsonValue)3 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)3 Message (io.github.voidzombie.nhglib.runtime.messaging.Message)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 Vector3 (com.badlogic.gdx.math.Vector3)2 Scene (io.github.voidzombie.nhglib.graphics.scenes.Scene)2 Bounds (io.github.voidzombie.nhglib.utils.data.Bounds)2 Camera (com.badlogic.gdx.graphics.Camera)1 FPSLogger (com.badlogic.gdx.graphics.FPSLogger)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelCache (com.badlogic.gdx.graphics.g3d.ModelCache)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 ImmediateModeRenderer20 (com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20)1 Quaternion (com.badlogic.gdx.math.Quaternion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Asset (io.github.voidzombie.nhglib.assets.Asset)1 GammaCorrectionAttribute (io.github.voidzombie.nhglib.graphics.shaders.attributes.GammaCorrectionAttribute)1