00001
00002 #include "SG_Node.h"
00003 #include "SG_Spatial.h"
00004 #include "SG_Controller.h"
00005
00006 SG_Spatial::SG_Spatial(void* clientobj,void* clientinfo,SG_Callbacks callbacks) :
00007 SG_IObject(clientobj,clientinfo,callbacks),
00008 m_localPosition(MT_Point3(0,0,0)),
00009 m_localScaling(MT_Vector3(1.f,1.f,1.f)),
00010 m_localRotation(1,0,0,0,1,0,0,0,1),
00011 m_SGparent(NULL),
00012 m_vertexparent(false)
00013 {
00014 }
00015
00016 SG_Spatial::~SG_Spatial()
00017 {
00018
00019 }
00020
00021 SG_IObject* SG_Spatial::GetSGReplica()
00022 {
00023 return NULL;
00024 }
00025
00026 void SG_Spatial::ProcessSGReplica(SG_IObject* replica)
00027 {
00028 SG_IObject::ProcessSGReplica(replica);
00029 }
00030
00031 void SG_Spatial::Destruct()
00032 {
00033 SG_IObject::Destruct();
00034 }
00035
00041 void SG_Spatial::UpdateGS(double time,bool bInitiator)
00042 {
00043
00044 UpdateWorldData(time);
00045
00046
00047
00048
00049 }
00050
00055
00056 void SG_Spatial::UpdateWorldData(double time)
00057 {
00058
00059
00060
00061
00062 bool bComputesWorldTransform = false;
00063
00064
00065 for (SGControllerList::iterator cit = m_SGcontrollers.begin();!(cit==m_SGcontrollers.end());++cit)
00066 {
00067 bComputesWorldTransform = (*cit)->Update(time);
00068 }
00069
00070
00071 if ( !bComputesWorldTransform )
00072 {
00076 if ( GetSGParent())
00077 {
00078
00079
00080 if (m_vertexparent)
00081 {
00082
00083 m_worldScaling = m_localScaling;
00084 m_worldRotation = m_localRotation;
00085 m_worldPosition = GetSGParent()->m_worldPosition +(m_localPosition);
00086
00087
00088
00089
00090 } else
00091 {
00092 m_worldScaling = GetSGParent()->m_worldScaling * m_localScaling;
00093 m_worldRotation = GetSGParent()->m_worldRotation*m_localRotation;
00094 m_worldPosition = GetSGParent()->m_worldPosition +
00095 GetSGParent()->m_worldScaling*(GetSGParent()->m_worldRotation * m_localPosition);
00096 }
00097
00098
00099
00100 }
00101 else
00102 {
00103 m_worldScaling = m_localScaling;
00104 m_worldRotation = m_localRotation;
00105 m_worldPosition = m_localPosition;
00106 }
00107 }
00108 }
00109
00110
00111
00112 void SG_Spatial::RelativeTranslate(const MT_Vector3& trans,bool local)
00113 {
00114 m_localPosition += ( local ? trans : GetWorldOrientation().inverse() * trans) ;
00115 }
00116
00117 void SG_Spatial::SetLocalPosition(const MT_Point3& trans)
00118 {
00119 m_localPosition = trans;
00120 }
00121
00122 void SG_Spatial::RelativeScale(const MT_Vector3& scale)
00123 {
00124 m_localScaling = m_localScaling * scale;
00125 }
00126
00127 void SG_Spatial::SetLocalScale(const MT_Vector3& scale)
00128 {
00129 m_localScaling = scale;
00130 }
00131
00132 void SG_Spatial::RelativeRotate(const MT_Matrix3x3& rot,bool local)
00133 {
00134 m_localRotation = m_localRotation * (local ? rot :
00135 (GetWorldOrientation().inverse() *
00136 rot *
00137 GetWorldOrientation()));
00138
00139 }
00140
00141 void SG_Spatial::SetLocalOrientation(const MT_Matrix3x3& rot)
00142 {
00143 m_localRotation = rot;
00144 }
00145
00146 const SG_Node* SG_Spatial::GetRootSGParent()
00147 {
00148 return (m_SGparent ? (const SG_Node*) m_SGparent->GetRootSGParent() : (const SG_Node*) this);
00149 }