Example usage for com.badlogic.gdx.math Matrix4 setToLookAt

List of usage examples for com.badlogic.gdx.math Matrix4 setToLookAt

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Matrix4 setToLookAt.

Prototype

public Matrix4 setToLookAt(Vector3 direction, Vector3 up) 

Source Link

Document

Sets the matrix to a look at matrix with a direction and an up vector.

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.GameObject.java

License:Apache License

public void lookAt(Vector3 point) {
    Vector3 from = transform.getTranslation(new Vector3()).cpy();
    Vector3 to = point.cpy();//from  w  w  w. j av a 2 s .c o m
    Vector3 direction = to.sub(from).nor();
    direction.set(-direction.x, -direction.y, -direction.z);

    Quaternion quaternion = new Quaternion();
    Matrix4 instanceRotation = transform.cpy().mul(transform);

    instanceRotation.setToLookAt(direction, new Vector3(0, -1, 0));
    instanceRotation.rotate(0, 0, 1, 180);
    instanceRotation.getRotation(quaternion);

    transform.set(from, quaternion);
}