#include "Transform3.h" #include "RenderState.h" namespace CHCDemoEngine { CGparameter Transform3::sModelMatrixParam; Transform3::Transform3(const Matrix4x4 &trafo): mMatrix(trafo) { mIsIdentity = false; } Transform3::Transform3() { Reset(); } void Transform3::Load(RenderState *state) { if (mIsIdentity) return; // note: would not need to pass the model matrix, // as all required information is avaiabl in the glstate // however, we require it compute the word positions, // as computing the world position by use the inverse of the viewprojection // matrix turned out to be too inaccurate for temporal reprojection if (state->GetRenderPassType() == RenderState::DEFERRED) { cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x); } glPushMatrix(); glMultMatrixf((float *)mMatrix.x); } void Transform3::Unload(RenderState *state) { if (mIsIdentity) return; // reset model matrix if (state->GetRenderPassType() == RenderState::DEFERRED) { static Matrix4x4 identity = IdentityMatrix(); cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); } glPopMatrix(); } void Transform3::MultMatrix(const Matrix4x4 &trafo) { mIsIdentity = false; mMatrix = mMatrix * trafo; } void Transform3::Reset() { mIsIdentity = true; mMatrix = IdentityMatrix(); } }