Billboard with math

放肆的年华 提交于 2020-01-05 17:03:13

问题


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.

来源:https://stackoverflow.com/questions/25913417/billboard-with-math

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!