Line | |
---|
1 | #include "Transform3.h"
|
---|
2 | #include "RenderState.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | namespace CHCDemoEngine
|
---|
6 | {
|
---|
7 |
|
---|
8 | CGparameter Transform3::sModelMatrixParam;
|
---|
9 |
|
---|
10 |
|
---|
11 | Transform3::Transform3(const Matrix4x4 &trafo): mMatrix(trafo)
|
---|
12 | {
|
---|
13 | mIsIdentity = false;
|
---|
14 | }
|
---|
15 |
|
---|
16 |
|
---|
17 | Transform3::Transform3()
|
---|
18 | {
|
---|
19 | Reset();
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | void Transform3::Load(RenderState *state)
|
---|
24 | {
|
---|
25 | if (mIsIdentity) return;
|
---|
26 |
|
---|
27 | // note: would not need to pass the model matrix,
|
---|
28 | // as all required information is avaiabl in the glstate
|
---|
29 | // however, we require it compute the word positions,
|
---|
30 | // as computing the world position by use the inverse of the viewprojection
|
---|
31 | // matrix turned out to be too inaccurate for temporal reprojection
|
---|
32 |
|
---|
33 | if (state->GetRenderPassType() == RenderState::DEFERRED)
|
---|
34 | {
|
---|
35 | cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x);
|
---|
36 | }
|
---|
37 |
|
---|
38 | glPushMatrix();
|
---|
39 | glMultMatrixf((float *)mMatrix.x);
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | void Transform3::Unload(RenderState *state)
|
---|
44 | {
|
---|
45 | if (mIsIdentity) return;
|
---|
46 |
|
---|
47 | // reset model matrix
|
---|
48 | if (state->GetRenderPassType() == RenderState::DEFERRED)
|
---|
49 | {
|
---|
50 | static Matrix4x4 identity = IdentityMatrix();
|
---|
51 | cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x);
|
---|
52 | }
|
---|
53 |
|
---|
54 | glPopMatrix();
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | void Transform3::MultMatrix(const Matrix4x4 &trafo)
|
---|
59 | {
|
---|
60 | mIsIdentity = false;
|
---|
61 | mMatrix = mMatrix * trafo;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | void Transform3::Reset()
|
---|
66 | {
|
---|
67 | mIsIdentity = true;
|
---|
68 | mMatrix = IdentityMatrix();
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.