00001 #include "MercuryMessages.h"
00002 #include "MercuryObjectBase.h"
00003 #include "MercuryDisplay.h"
00004 #include "MercuryMath.h"
00005 #include "MercuryScreenManager.h"
00006
00007 MercuryObjectBase::MercuryObjectBase()
00008 :m_parentObject(NULL)
00009 {
00010 }
00011
00012 void MercuryObjectBase::Init()
00013 {
00014 m_rotMode = RM_NORMAL;
00015 m_scale.SetX(1);
00016 m_scale.SetY(1);
00017 m_scale.SetZ(1);
00018 m_fVisRadius = -1;
00019 m_taintedMatrix = true;
00020 m_drawOrder = 0;
00021 m_xalign = m_yalign = 0;
00022 }
00023
00024 MercuryPoint MercuryObjectBase::GetGlobalPosition() const
00025 {
00026 if ( !m_parentObject )
00027 return m_position;
00028 return m_parentObject->GetGlobalPosition() + m_position;
00029 }
00030
00031 void MercuryObjectBase::CalculateMatrices()
00032 {
00033 if ( m_taintedMatrix || (m_rotMode == RM_BILLBOARD) )
00034 {
00035 m_localMatrix.Identity();
00036
00037 if( m_rotMode == RM_NORMAL )
00038 {
00039 m_localMatrix.Transotale( m_position.x, m_position.y, m_position.z,
00040 m_rotation.x, m_rotation.y, m_rotation.z,
00041 m_scale.x, m_scale.y, m_scale.z );
00042
00043
00044 if ((m_xalign != 0) || (m_yalign != 0))
00045 m_localMatrix.Translate(m_xalign, m_yalign, 0);
00046 m_taintedMatrix = false;
00047 }
00048 else
00049 {
00050
00051 m_localMatrix.Translate(m_position.x, m_position.y, m_position.z);
00052
00053 switch ( m_rotMode )
00054 {
00055 case RM_OFF:
00056 break;
00057 case RM_BILLBOARD:
00058 {
00059 MercuryPoint up(0,0,1);
00060 static MercuryPoint directionProj;
00061 static float angle;
00062 static MercuryPoint axis;
00063 static MercuryMatrix world;
00064
00065
00066 MercuryPoint gp(GetGlobalPosition());
00067 MercuryPoint lcp;
00068
00069 MercuryScreen* screen = SCREENMAN->GetCurrentScreen();
00070 if (screen)
00071 {
00072 MercuryCamera* camera = screen->GetCamera();
00073 if (camera)
00074 {
00075 lcp = camera->GetPosition();
00076
00077 }
00078 }
00079
00080 directionProj = GetGlobalPosition() - lcp;
00081 directionProj.NormalizeSelf();
00082
00083 axis = up.CrossProduct(directionProj);
00084 angle = ACOS(DotProduct(up, directionProj));
00085
00086
00087 world.RotateAngAxis(angle*RADDEG, axis.x, axis.y, axis.z);
00088 m_localMatrix *= world;
00089 }
00090 break;
00091 case RM_MATRIX:
00092 m_localMatrix *= m_matrix;
00093 break;
00094 case RM_QUATERNION:
00095 {
00096 MercuryMatrix m;
00097 m_rotQuat.toMatrix4(m);
00098 m_localMatrix *= m;
00099 }
00100 break;
00101 default:
00102 break;
00103 };
00104
00105 m_localMatrix.Scale(m_scale.x, m_scale.y, m_scale.z);
00106 if ((m_xalign != 0) || (m_yalign != 0))
00107 m_localMatrix.Translate(m_xalign, m_yalign, 0);
00108 m_taintedMatrix = false;
00109 }
00110 }
00111
00112 m_finalMatrix = WorldStack.GetTop() *= m_localMatrix;
00113 }
00114
00115 MercuryPoint MercuryObjectBase::GetTruePosition() const
00116 {
00117 MercuryPoint pOut;
00118 MercuryMatrix copy( m_finalMatrix );
00119 VectorMultiply( copy, gpZero, pOut );
00120 return pOut;
00121 }
00122
00123 bool MercuryObjectBase::IsHidden() const
00124 {
00125 if (m_parentObject)
00126 return m_parentObject->IsHidden()||m_hidden;
00127
00128 return m_hidden;
00129 }
00130
00131 #include "MercuryObjectFactory.h"
00132
00133 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetX, (float), float );
00134 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetY, (float), float );
00135 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetZ, (float), float );
00136 CLASS_FUNCTION_NOARGS( MercuryObject, GetX, float );
00137 CLASS_FUNCTION_NOARGS( MercuryObject, GetY, float );
00138 CLASS_FUNCTION_NOARGS( MercuryObject, GetZ, float );
00139 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveX, (float), float );
00140 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveY, (float), float );
00141 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveZ, (float), float );
00142 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetRotX, (float), float );
00143 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetRotY, (float), float );
00144 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetRotZ, (float), float );
00145 CLASS_FUNCTION_NOARGS( MercuryObject, GetRotX, float );
00146 CLASS_FUNCTION_NOARGS( MercuryObject, GetRotY, float );
00147 CLASS_FUNCTION_NOARGS( MercuryObject, GetRotZ, float );
00148 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveRotX, (float), float );
00149 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveRotY, (float), float );
00150 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveRotZ, (float), float );
00151
00152 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetScaleX, (float), float );
00153 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetScaleY, (float), float );
00154 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetScaleZ, (float), float );
00155 CLASS_FUNCTION_NOARGS( MercuryObject, GetScaleX, float );
00156 CLASS_FUNCTION_NOARGS( MercuryObject, GetScaleY, float );
00157 CLASS_FUNCTION_NOARGS( MercuryObject, GetScaleZ, float );
00158 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveScaleX, (float), float );
00159 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveScaleY, (float), float );
00160 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, MoveScaleZ, (float), float );
00161
00162 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetRotationMode, (RotationMode) (int), int );
00163
00164 CLASS_FUNCTION_NOARGS( MercuryObject, GetParentObject, void* );
00165 CLASS_FUNCTION_NOARGS( MercuryObject, GetHide, bool );
00166 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetHide, (bool), bool );
00167
00168 CLASS_FUNCTION_NOARGS( MercuryObject, GetDrawOrder, int );
00169 CLASS_FUNCTION_VOID_ONEARG( MercuryObject, SetDrawOrder, (int), int );
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197