1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_CalculatedTransform.cpp
4
5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Revision: 24123 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/gfx/gfx_CalculatedTransform.h>
19 #include <nw/gfx/res/gfx_ResSkeleton.h>
20
21 namespace nw
22 {
23 namespace gfx
24 {
25
26 //----------------------------------------
27 void
Setup(const ResBone bone)28 CalculatedTransform::Setup(const ResBone bone)
29 {
30 bool translateZeroFlag = false;
31 bool rotateZeroFlag = false;
32
33 this->SetTransform(bone.GetTransform());
34 if ( ut::CheckFlag(bone.GetFlags(), ResBoneData::FLAG_IS_IDENTITY) )
35 {
36 this->EnableFlags(CalculatedTransform::FLAG_IS_IDENTITY);
37 }
38 if ( ut::CheckFlag(bone.GetFlags(), ResBoneData::FLAG_IS_TRANSLATE_ZERO) )
39 {
40 this->EnableFlags(CalculatedTransform::FLAG_IS_TRANSLATE_ZERO);
41 translateZeroFlag = true;
42 }
43 if ( ut::CheckFlag(bone.GetFlags(), ResBoneData::FLAG_IS_ROTATE_ZERO) )
44 {
45 this->EnableFlags(CalculatedTransform::FLAG_IS_ROTATE_ZERO);
46 rotateZeroFlag = true;
47 }
48 if ( ut::CheckFlag(bone.GetFlags(), ResBoneData::FLAG_IS_SCALE_ONE) )
49 {
50 this->EnableFlags(CalculatedTransform::FLAG_IS_SCALE_ONE);
51 }
52 if ( ut::CheckFlag(bone.GetFlags(), ResBoneData::FLAG_IS_UNIFORM_SCALE) )
53 {
54 this->EnableFlags(CalculatedTransform::FLAG_IS_UNIFORM_SCALE);
55 }
56 if ( translateZeroFlag && rotateZeroFlag )
57 {
58 this->EnableFlags(CalculatedTransform::FLAG_IS_ROTATE_TRANSLATE_ZERO);
59 }
60 }
61
62 //----------------------------------------
63 void
UpdateFlags()64 CalculatedTransform::UpdateFlags()
65 {
66 UpdateScaleFlags();
67 UpdateRotateFlags();
68 UpdateTranslateFlags();
69 UpdateCompositeFlags();
70 }
71
72 //----------------------------------------
73 void
UpdateRotateFlags()74 CalculatedTransform::UpdateRotateFlags()
75 {
76 if (this->IsEnabledFlags(FLAG_IS_IGNORE_ROTATE))
77 {
78 return;
79 }
80
81 const math::MTX34& mtx = this->m_TransformMatrix;
82 // 回転行列はノルム 1 なので、対角要素を 2 つ判断すればよい。
83 if (mtx.f._00 == 1.0f && mtx.f._11 == 1.0f)
84 {
85 this->EnableFlags(FLAG_IS_ROTATE_ZERO);
86 }
87 else
88 {
89 this->DisableFlags(FLAG_IS_ROTATE_ZERO);
90 }
91 }
92
93 //----------------------------------------
94 void
UpdateTranslateFlags()95 CalculatedTransform::UpdateTranslateFlags()
96 {
97 if (this->IsEnabledFlags(FLAG_IS_IGNORE_TRANSLATE))
98 {
99 return;
100 }
101
102 const math::MTX34& mtx = this->m_TransformMatrix;
103 if (mtx.f._03 == 0.0f && mtx.f._13 == 0.0f && mtx.f._23 == 0.0f)
104 {
105 this->EnableFlags(FLAG_IS_TRANSLATE_ZERO);
106 }
107 else
108 {
109 this->DisableFlags(FLAG_IS_TRANSLATE_ZERO);
110 }
111 }
112
113 //----------------------------------------
114 void
UpdateCompositeFlags()115 CalculatedTransform::UpdateCompositeFlags()
116 {
117 this->DisableFlags(FLAG_IS_ROTATE_TRANSLATE_ZERO | FLAG_IS_IDENTITY);
118
119 if (this->IsEnabledFlags(FLAG_IS_ROTATE_ZERO | FLAG_IS_TRANSLATE_ZERO))
120 {
121 this->EnableFlags(FLAG_IS_ROTATE_TRANSLATE_ZERO);
122
123 if (this->IsEnabledFlags(FLAG_IS_SCALE_ONE))
124 {
125 this->EnableFlags(FLAG_IS_IDENTITY);
126 }
127 }
128 }
129
130 } // namespace gfx
131 } // namespace nw
132