use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.
the class Main method onKeyInput.
@Override
public void onKeyInput(NhgInput input) {
if (scene != null) {
NodeComponent nodeComponent = cameraNode;
switch(input.getName()) {
case "strafeRight":
nodeComponent.translate(0.1f * Gdx.graphics.getDeltaTime(), 0, 0);
break;
case "strafeLeft":
nodeComponent.translate(-0.1f * Gdx.graphics.getDeltaTime(), 0, 0);
break;
case "forward":
nodeComponent.translate(0, 0, -0.1f * Gdx.graphics.getDeltaTime());
break;
case "backward":
nodeComponent.translate(0, 0, 0.1f * Gdx.graphics.getDeltaTime());
break;
case "jump":
cameraNode.rotate(0, 0, 0.1f);
break;
case "sprint":
cameraNode.rotate(0, 0, -0.1f);
break;
case "exit":
nhg.messaging.send(new Message(Strings.Events.engineDestroy));
break;
}
nodeComponent.applyTransforms();
}
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.
the class TestNodeSystem method process.
@Override
protected void process(int entityId) {
NodeComponent nodeComponent = nodeMapper.get(entityId);
MessageComponent messageComponent = messageMapper.get(entityId);
Array<Message> messages = messageComponent.getMessages();
for (Message message : messages) {
if (message.is("printNode")) {
Logger.log(this, "id: %d, x: %f, y: %f, z: %f", nodeComponent.id, nodeComponent.getX(), nodeComponent.getY(), nodeComponent.getZ());
messageComponent.consume(message);
}
}
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.
the class EntityJson method parse.
@Override
public void parse(JsonValue jsonValue) {
String id = jsonValue.getString("id");
int entity = sceneGraph.addSceneEntity(id, parentEntity);
JsonValue componentsJson = jsonValue.get("components");
for (JsonValue componentJsonValue : componentsJson) {
String type = componentJsonValue.getString("type");
ComponentJson componentJson = SceneUtils.componentJsonFromType(type);
if (componentJson != null) {
componentJson.entity = entity;
componentJson.entities = entities;
componentJson.parse(componentJsonValue);
}
}
JsonValue entitiesJson = jsonValue.get("entities");
if (entitiesJson != null) {
for (JsonValue entityJsonValue : entitiesJson) {
EntityJson entityJson = new EntityJson(entities);
entityJson.sceneGraph = sceneGraph;
entityJson.parentEntity = entity;
entityJson.parse(entityJsonValue);
}
}
TransformJson transformJson = new TransformJson();
transformJson.parse(jsonValue.get("transform"));
NodeComponent nodeComponent = entities.getComponent(entity, NodeComponent.class);
nodeComponent.setTransform(transformJson.position, transformJson.rotation, transformJson.scale);
output = entity;
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.
the class LargeWorldStrategy method update.
@Override
public void update(Scene scene, Bounds bounds, NodeComponent referenceNodeComponent) {
if (referenceNodeComponent != null) {
Bounds.Info boundsInfo = bounds.boundsInfo(referenceNodeComponent.getTranslation());
if (!boundsInfo.inBounds) {
NodeComponent rootNodeComponent = entities.getComponent(scene.sceneGraph.getRootEntity(), NodeComponent.class);
float xTranslation = bounds.getWidth() * boundsInfo.widthSide;
float yTranslation = bounds.getHeight() * boundsInfo.heightSide;
float zTranslation = bounds.getDepth() * boundsInfo.depthSide;
rootNodeComponent.translate(-xTranslation, -yTranslation, -zTranslation, true);
}
}
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent in project nhglib by VoidZombie.
the class SceneManager method unloadScene.
public void unloadScene(final Scene scene) {
Observable.fromIterable(scene.sceneGraph.getEntities()).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer entity) throws Exception {
return modelMapper.has(entity);
}
}).doFinally(new Action() {
@Override
public void run() throws Exception {
int rootEntity = scene.sceneGraph.getRootEntity();
NodeComponent nodeComponent = nodeMapper.get(rootEntity);
nodeComponent.setTranslation(0, 0, 0);
nodeComponent.setRotation(0, 0, 0);
nodeComponent.setScale(1, 1, 1);
nodeComponent.applyTransforms();
}
}).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
ModelComponent modelComponent = modelMapper.get(integer);
assets.unloadAsset(modelComponent.asset);
}
});
}
Aggregations