Problem using glm::lookat
Posted
by
omikun
on Game Development
See other posts from Game Development
or by omikun
Published on 2013-06-28T03:23:59Z
Indexed on
2013/06/28
16:31 UTC
Read the original article
Hit count: 374
I am trying to rotate a sprite so it is always facing a 3D camera.
Object
GLfloat vertexData[] = {
// X Y Z U V
0.0f, 0.8f, 0.0f, 0.5f, 1.0f,
-0.8f,-0.8f, 0.0f, 0.0f, 0.0f,
0.8f,-0.8f, 0.0f, 1.0f, 0.0f,
};
Per frame transform
glm::mat4 newTransform = glm::lookAt(glm::vec3(0), gCamera.position(), gCamera.up());
shaders->setUniform("camera", gCamera.matrix());
shaders->setUniform("model", newTransform);
In the vertex shader:
gl_Position = camera * model * vec4(vert, 1);
The object will track the camera if I move the camera up or down, but if I move the camera left/right (spin the camera around the object's y axis), it will rotate in the other direction so I end up seeing its front twice and its back twice as I rotate around it 360.
If I use -gCamera.up() instead, it would track the camera side to side, but spin the opposite direction when I move the camera up/down.
What am I doing wrong?
© Game Development or respective owner