stk-code_catmod/data/shaders/utils/getworldmatrix.vert

39 lines
1.1 KiB
GLSL
Raw Normal View History

2014-03-28 21:04:20 -04:00
const float DEG2GRAD = 3.14 / 180.;
2014-03-28 20:22:08 -04:00
mat4 getMatrixFromRotation(vec3 rotation)
{
// from irrlicht
2014-03-28 21:04:20 -04:00
float cr = cos(DEG2GRAD * rotation.x );
float sr = sin(DEG2GRAD * rotation.x );
float cp = cos(DEG2GRAD * rotation.y );
float sp = sin(DEG2GRAD * rotation.y );
float cy = cos(DEG2GRAD * rotation.z );
float sy = sin(DEG2GRAD * rotation.z );
2014-03-28 20:22:08 -04:00
float srsp = sr*sp;
float crsp = cr*sp;
2014-03-28 21:19:08 -04:00
return transpose(mat4(
2014-03-28 20:22:08 -04:00
vec4(cp * cy, srsp * cy - cr * sy, crsp * cy + sr * sy, 0.),
vec4(cp * sy, srsp * sy + cr * cy, crsp * sy - sr * cy, 0.),
vec4(-sp, sr * cp, cr * cp, 0.),
2014-03-28 21:19:08 -04:00
vec4(0., 0., 0., 1.)));
2014-03-28 20:22:08 -04:00
}
mat4 getWorldMatrix(vec3 translation, vec3 rotation)
{
mat4 result = getMatrixFromRotation(rotation);
// translation
result[3].xyz += translation;
return result;
}
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation)
{
mat4 result = transpose(getMatrixFromRotation(rotation));
// FIXME: it's wrong but the fourth column is not used
result[3].xyz -= translation;
return result;
}