我確定有一個更好的方法來計算我的四元數變換矩陣,但這是我現在所擁有的。我需要將16個值傳遞給着色器,但遇到問題。我不斷收到類型不兼容性錯誤。也有一次,我得到它在那裏,我必須做任何事情來把它擴大到我已有的東西?如何將4x4變換矩陣傳遞給使用glUniformMatrix4fv的vShader?
這是我的顯示器和Shader
void display()
{ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if (trackballMove)
{
glRotatef(angle, axis[0], axis[1], axis[2]);
}
//colorcube();
glUniform3fv(theta, 1, Theta);
float a = angle;
float b = axis[0];
float c = axis[1];
float d = axis[2];
float xform[16] = {(a*a+b*b-c*c-d*d),(2*b*c-2*a*d),(2*b*d+2*a*c),0.0,
(2*b*c+2*a*d),(a*a-b*b+c*c-d*d),(2*c*d-2*a*b),0.0,
(2*b*d-2*a*c),(2*c*d+2*a*b),(a*a-b*b-c*c+d*d),0.0,
0.0,0.0,0.0,1.0};
GLuint Transform = glGetUniformLocation(program, "vTransform");
glUniformMatrix4fv(Transform, xform);
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
glutSwapBuffers();
}
這裏是着色器
#version 150
in vec4 vPosition;
in vec4 vColor;
out vec4 color;
uniform vec3 theta;
uniform vec4 vTransform;
void main()
{
// Compute the sines and cosines of theta for each of
// the three axes in one computation.
vec3 angles = radians(theta);
vec3 c = cos(angles);
vec3 s = sin(angles);
// Remember: these matrices are column-major
mat4 rx = mat4(1.0, 0.0, 0.0, 0.0,
0.0, c.x, -s.x, 0.0,
0.0, s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0);
mat4 ry = mat4(c.y, 0.0, s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
-s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0);
mat4 rz = mat4(c.z, -s.z, 0.0, 0.0,
s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
color = vColor;
gl_Position = vTransform *(rx * ry * rz * vPosition);
}
所以...什麼是你的問題?它似乎很混亂。 –