1

I'm trying to draw an element always facing camera. I've read some articles about billboard in shaders, the problem is that I need to compute rotation out of shaders and with different objects (circles, square, mesh, …).

So, I'm trying to compute model's rotation only (not matrix, something similar to Transform.LookAt in Unity engine) but I don't know how to do, here is what I've got:

// Camera data
mat4 viewMatrix     = camera->getMatrix();
vec3 up             = {viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]};

// Compute useful data.
vec3 look           = normalize(camera->getPosition() - model->getPosition());
vec3 right          = cross(up, look);
vec3 up2            = cross(look, right);

// Default: Compute matrix.
mat4 transform;
transform[0] = vec4(right, 0);
transform[1] = vec4(up2, 0);
transform[2] = vec4(look, 0);
transform[3] = vec4(position, 1);

// What I want : Compute rotation from look, right, up data and remove "Default: Compute matrix" part.
// ???

My framework compute model's matrix from his attributes (position, scale, rotation), so I can't override it, I just want to compute rotation.

genpfault
  • 51,148
  • 11
  • 85
  • 139
user30088
  • 497
  • 1
  • 6
  • 14
  • see lookat method in GLM math library – Michael IV Sep 18 '14 at 15:11
  • or draw billboards with unit rotation matrix inside mode/camera matrixes instead (or do not use them in vertex shader) just use only position and projection part of the matrices – Spektre Sep 19 '14 at 06:13

0 Answers0