Search in sources :

Example 1 with CameraComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent 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 2 with CameraComponent

use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent in project nhglib by VoidZombie.

the class CameraComponentJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    CameraComponent cameraComponent = entities.createComponent(entity, CameraComponent.class);
    Camera camera;
    float nearPlane = jsonValue.getFloat("nearPlane");
    float farPlane = jsonValue.getFloat("farPlane");
    CameraComponent.Type type = CameraComponent.Type.fromString(jsonValue.getString("cameraType"));
    switch(type) {
        default:
        case PERSPECTIVE:
            float fieldOfView = jsonValue.getFloat("fieldOfView");
            camera = new PerspectiveCamera(fieldOfView, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            break;
        case ORTHOGRAPHIC:
            camera = new OrthographicCamera();
            break;
    }
    camera.near = nearPlane;
    camera.far = farPlane;
    cameraComponent.camera = camera;
    cameraComponent.type = type;
    output = cameraComponent;
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) CameraComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent) Camera(com.badlogic.gdx.graphics.Camera) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Aggregations

Camera (com.badlogic.gdx.graphics.Camera)2 CameraComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 NodeComponent (io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)1