GLSL ROTATION ABOUT AN ARBITRARY AXIS

mat4 rotationMatrix(vec3 axis, float angle){
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;

return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);

}


mat4 rotationMatrix(vec3 axis, float angle) {
vec3 a = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 – c;
float sx = s * a.x;
float sy = s * a.y;
float sz = s * a.z;
float ocx = oc * a.x;
float ocy = oc * a.y;
float ocz = oc * a.z;
float ocxx = ocx * a.x;
float ocxy = ocx * a.y;
float ocxz = ocx * a.z;
float ocyy = ocy * a.y;
float ocyz = ocy * a.z;
float oczz = ocz * a.z;
return mat4(
vec4(ocxx + c, ocxy – sz, ocxz + sy, 0.0),
vec4(ocxy + sz, ocyy + c, ocyz – sx, 0.0),
vec4(ocxz – sy, ocyz + sx, oczz + c, 0.0),
vec4( 0.0, 0.0, 0.0, 1.0)
);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章