3차원 회전에 대한 각 축별 회전행렬(Rotation Matrix)도 같은 원리로 도출할 수 있다. 회전방향은 마찬가지로 기준이 되는 축에 대해 반시계 방향이다.
(위 식을 보면 2차원 회전행렬과 3차원 z축 기준 회전행렬이 거의 유사함을 볼 수 있다)
void Matrix4x4::SetRotation(float flAngle, const Vector& v)
{
// Normalize beforehand
TAssert(fabs(v.LengthSqr() - 1) < 0.000001f);
// c = cos(angle), s = sin(angle), t = (1-c)
// [ xxt+c xyt-zs xzt+ys ]
// [ yxt+zs yyt+c yzt-xs ]
// [ zxt-ys zyt+xs zzt+c ]
float x = v.x;
float y = v.y;
float z = v.z;
float c = cos(flAngle*(float)M_PI/180);
float s = sin(flAngle*(float)M_PI/180);
float t = 1-c;
m[0][0] = x*x*t + c;
m[1][0] = x*y*t - z*s;
m[2][0] = x*z*t + y*s;
m[0][1] = y*x*t + z*s;
m[1][1] = y*y*t + c;
m[2][1] = y*z*t - x*s;
m[0][2] = z*x*t - y*s;
m[1][2] = z*y*t + x*s;
m[2][2] = z*z*t + c;
}
'mathematics > game mathematics' 카테고리의 다른 글
[Mathematics] 12. TRS Matrix (0) | 2022.02.21 |
---|---|
[Mathematics] 11. Translation (0) | 2022.02.21 |
[Mathematics] 9. Scaling (0) | 2022.02.07 |
[Mathematics] 8. 좌표계 변환 (0) | 2022.02.06 |
[Mathematics] 7. Billboarding (0) | 2022.02.01 |