Mat4x4 Anubis::CreateOrthoProjectionLH( const AREAL width, const AREAL height, const AREAL nearZ, const AREAL farZ) { Mat4x4 mat; mat.Init( Vector( 2.0f / width, 0, 0, 0), Vector( 0, 2.0f / height, 0, 0), Vector( 0, 0, 1.0f / (farZ - nearZ), 0), Vector( 0, 0, nearZ / (nearZ - farZ), 1) ); return mat; }
/* ====================================== Matrices ========================================= */ Mat4x4 Anubis::CreateViewMatrixLH(const Vec & pos, const Vec & lookDir, const Vec & up) { Mat4x4 mat; Vec & zaxis = Normalize(lookDir); Vec & xaxis = Normalize(cross(up, zaxis)); Vec & yaxis = cross(zaxis, xaxis); mat.Init( Vector( getx(xaxis), getx(yaxis), getx(zaxis), 0), Vector( gety(xaxis), gety(yaxis), gety(zaxis), 0), Vector( getz(xaxis), getz(yaxis), getz(zaxis), 0), Vector( -Dot(xaxis, pos), -Dot(yaxis, pos), -Dot(zaxis, pos), 1) ); return mat; }
Mat4x4 Anubis::CreatePerspectiveProjectionLH( const AREAL fov, const AREAL aspect, const AREAL nearZ, const AREAL farZ ) { Mat4x4 mat; //AREAL yscale = CtgR32(fov / 2); //AREAL xscale = yscale / aspect; AREAL SinFov = Sin(fov * 0.5f); AREAL CosFov = Cos(fov * 0.5f); AREAL height = CosFov / SinFov; AREAL width = height / aspect; mat.Init( Vector(width, 0, 0, 0), Vector(0, height, 0, 0), Vector(0, 0, farZ/(farZ-nearZ), 1), Vector(0, 0, -nearZ*farZ/(farZ-nearZ), 0) ); return mat; }