To do what you want to do in your comment, you also need to know your player’s previous orientation. Actually, it is best to store all the data about the position and orientation of your player (and almost everything else in the game) in a 4x4 matrix. This is done by adding a fourth column and a fourth row to the 3x3 rotation matrix and using an additional column to store player position information. The math behind this (uniform coordinates) is quite simple and very important in both OpenGL and DirectX. I offer you this great tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ Now, to turn a player to an enemy using GLM, you can do this:
1) In the game and enemy classes, declare a matrix and a 3d vector for the position
glm::mat4 matrix; glm::vec3 position;
2) rotate against the enemy with
player.matrix = glm::LookAt( player.position,
3) to turn the enemy towards the player, do
enemy.matrix = glm::LookAt( enemy.position,
If you want to save everything in a matrix, do not declare the position as a variable, but as a function
vec3 position(){ return vec3(matrix[3][0],matrix[3][1],matrix[3][2]) }
and rotate with
player.matrix = glm::LookAt( player.position(),
darius
source share