Search in sources :

Example 56 with Vector3

use of com.badlogic.gdx.math.Vector3 in project Entitas-Java by Rubentxu.

the class ActuatorEntity method addCameraActuator.

public ActuatorEntity addCameraActuator(Camera camera, short height, float damping, float minDistanceX, float minDistanceY, String followTagEntity) {
    CameraActuator component = (CameraActuator) recoverComponent(ActuatorComponentsLookup.CameraActuator);
    if (component == null) {
        component = new CameraActuator(camera, height, damping, minDistanceX, minDistanceY, followTagEntity);
    } else {
        component.actuator = (indexOwner) -> {
            Set<GameEntity> followEntities = Indexed.getTagEntities(followTagEntity);
            for (GameEntity followEntity : followEntities) {
                RigidBody rc = followEntity.getRigidBody();
                Transform transform = rc.body.getTransform();
                Vector3 position = camera.position;
                position.x += (transform.getPosition().x + minDistanceX - position.x) * damping;
                position.y += (transform.getPosition().y + minDistanceY - position.y) * height;
            }
        };
    }
    addComponent(ActuatorComponentsLookup.CameraActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) CameraActuator(ilargia.egdx.logicbricks.component.actuator.CameraActuator) Vector3(com.badlogic.gdx.math.Vector3) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) Transform(com.badlogic.gdx.physics.box2d.Transform)

Example 57 with Vector3

use of com.badlogic.gdx.math.Vector3 in project nhglib by VoidZombie.

the class NhgG3dModelLoader method parseNodesRecursively.

private ModelNode parseNodesRecursively(JsonValue json) {
    ModelNode jsonNode = new ModelNode();
    String id = json.getString("id", null);
    if (id == null)
        throw new GdxRuntimeException("Node id missing.");
    jsonNode.id = id;
    JsonValue translation = json.get("translation");
    if (translation != null && translation.size != 3)
        throw new GdxRuntimeException("Node translation incomplete");
    jsonNode.translation = translation == null ? null : new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2));
    JsonValue rotation = json.get("rotation");
    if (rotation != null && rotation.size != 4)
        throw new GdxRuntimeException("Node rotation incomplete");
    jsonNode.rotation = rotation == null ? null : new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3));
    JsonValue scale = json.get("scale");
    if (scale != null && scale.size != 3)
        throw new GdxRuntimeException("Node scale incomplete");
    jsonNode.scale = scale == null ? null : new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2));
    String meshId = json.getString("mesh", null);
    if (meshId != null)
        jsonNode.meshId = meshId;
    JsonValue materials = json.get("parts");
    if (materials != null) {
        jsonNode.parts = new ModelNodePart[materials.size];
        int i = 0;
        for (JsonValue material = materials.child; material != null; material = material.next, i++) {
            ModelNodePart nodePart = new ModelNodePart();
            String meshPartId = material.getString("meshpartid", null);
            String materialId = material.getString("materialid", null);
            if (meshPartId == null || materialId == null) {
                throw new GdxRuntimeException("Node " + id + " part is missing meshPartId or materialId");
            }
            nodePart.materialId = materialId;
            nodePart.meshPartId = meshPartId;
            JsonValue bones = material.get("bones");
            if (bones != null) {
                nodePart.bones = new ArrayMap<String, Matrix4>(true, bones.size, String.class, Matrix4.class);
                int j = 0;
                for (JsonValue bone = bones.child; bone != null; bone = bone.next, j++) {
                    String nodeId = bone.getString("node", null);
                    if (nodeId == null)
                        throw new GdxRuntimeException("Bone node ID missing");
                    Matrix4 transform = new Matrix4();
                    JsonValue val = bone.get("translation");
                    if (val != null && val.size >= 3)
                        transform.translate(val.getFloat(0), val.getFloat(1), val.getFloat(2));
                    val = bone.get("rotation");
                    if (val != null && val.size >= 4)
                        transform.rotate(tempQ.set(val.getFloat(0), val.getFloat(1), val.getFloat(2), val.getFloat(3)));
                    val = bone.get("scale");
                    if (val != null && val.size >= 3)
                        transform.scale(val.getFloat(0), val.getFloat(1), val.getFloat(2));
                    nodePart.bones.put(nodeId, transform);
                }
            }
            jsonNode.parts[i] = nodePart;
        }
    }
    JsonValue children = json.get("children");
    if (children != null) {
        jsonNode.children = new ModelNode[children.size];
        int i = 0;
        for (JsonValue child = children.child; child != null; child = child.next, i++) {
            jsonNode.children[i] = parseNodesRecursively(child);
        }
    }
    return jsonNode;
}
Also used : Quaternion(com.badlogic.gdx.math.Quaternion) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 58 with Vector3

use of com.badlogic.gdx.math.Vector3 in project nhglib by VoidZombie.

the class NodeComponent method getTranslationDelta.

public Vector3 getTranslationDelta() {
    Vector3 res = temp.set(translationDelta);
    translationDelta.set(Vector3.Zero);
    return res;
}
Also used : Vector3(com.badlogic.gdx.math.Vector3)

Example 59 with Vector3

use of com.badlogic.gdx.math.Vector3 in project nhglib by VoidZombie.

the class NodeComponent method setTransform.

public void setTransform(Matrix4 transform) {
    if (transform != null) {
        Vector3 translation = VectorPool.getVector3();
        Vector3 scale = VectorPool.getVector3();
        Quaternion rotation = QuaternionPool.getQuaternion();
        transform.getTranslation(translation);
        transform.getRotation(rotation);
        transform.getScale(scale);
        setTranslation(translation);
        setRotation(rotation);
        setScale(scale);
        VectorPool.freeVector3(translation, scale);
        QuaternionPool.freeQuaternion(rotation);
    }
}
Also used : Quaternion(com.badlogic.gdx.math.Quaternion) Vector3(com.badlogic.gdx.math.Vector3)

Example 60 with Vector3

use of com.badlogic.gdx.math.Vector3 in project AmazingMaze by TheVirtualMachine.

the class MazeScreen method render.

@Override
public void render(float delta) {
    // Update the game state
    if (!paused) {
        update(delta);
        hud.act();
    } else {
        pauseMenu.act();
    }
    // Do the rendering.
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Vector3 target = new Vector3(player.getX(), mapHeight / 2, 0);
    target.x = Math.min(player.getX(), mapWidth - viewport.getWorldWidth() / 2);
    target.x = Math.max(viewport.getWorldWidth() / 2, target.x);
    camera.position.lerp(target, 0.25f);
    camera.update();
    mapRenderer.setView(camera);
    mapRenderer.render();
    game.batch.begin();
    player.draw(game.batch);
    game.batch.end();
    hud.draw();
    if (paused) {
        pauseMenu.draw();
    }
}
Also used : Vector3(com.badlogic.gdx.math.Vector3)

Aggregations

Vector3 (com.badlogic.gdx.math.Vector3)64 Matrix4 (com.badlogic.gdx.math.Matrix4)10 Quaternion (com.badlogic.gdx.math.Quaternion)9 Vector2 (com.badlogic.gdx.math.Vector2)6 Node (com.badlogic.gdx.graphics.g3d.model.Node)5 Texture (com.badlogic.gdx.graphics.Texture)4 Model (com.badlogic.gdx.graphics.g3d.Model)4 NodeKeyframe (com.badlogic.gdx.graphics.g3d.model.NodeKeyframe)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)4 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)3 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)3 Mesh (com.badlogic.gdx.graphics.Mesh)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)2 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)2 NodeAnimation (com.badlogic.gdx.graphics.g3d.model.NodeAnimation)2