00001 #include "KX_IPO_SGController.h" 00002 #include "KX_ScalarInterpolator.h" 00003 00004 bool KX_IpoSGController::Update(double currentTime) 00005 { 00006 if (m_modified) 00007 { 00008 T_InterpolatorList::iterator i; 00009 for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) { 00010 (*i)->Execute(m_ipotime);//currentTime); 00011 } 00012 00013 SG_Spatial* ob = (SG_Spatial*)m_pObject; 00014 00015 if (m_modify_position) 00016 ob->SetLocalPosition(m_ipo_xform.GetPosition()); 00017 if (m_modify_orientation) 00018 ob->SetLocalOrientation(MT_Matrix3x3(m_ipo_xform.GetEulerAngles())); 00019 if (m_modify_scaling) 00020 ob->SetLocalScale(m_ipo_xform.GetScaling()); 00021 00022 m_modified=false; 00023 } 00024 return false; 00025 } 00026 00027 00028 void KX_IpoSGController::AddInterpolator(KX_IInterpolator* interp) 00029 { 00030 this->m_interpolators.push_back(interp); 00031 } 00032 00033 SG_Controller* KX_IpoSGController::GetReplica() 00034 { 00035 KX_IpoSGController* iporeplica = new KX_IpoSGController(*this); 00036 // clear object that ipo acts on 00037 SG_Controller::ProcessReplica(iporeplica); 00038 // iporeplica->m_SGclientObject = NULL; 00039 00040 // dirty hack, ask Gino for a better solution in the ipo implementation 00041 // hacken en zagen, in what we call datahiding, not written for replication :( 00042 00043 T_InterpolatorList oldlist = m_interpolators; 00044 iporeplica->m_interpolators.clear(); 00045 00046 T_InterpolatorList::iterator i; 00047 for (i = oldlist.begin(); !(i == oldlist.end()); ++i) { 00048 KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i)); 00049 iporeplica->AddInterpolator(copyipo); 00050 00051 MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget(); 00052 int orgbase = (int)&m_ipo_xform; 00053 int orgloc = (int)scaal; 00054 int offset = orgloc-orgbase; 00055 int newaddrbase = (int)&iporeplica->m_ipo_xform; 00056 newaddrbase += offset; 00057 MT_Scalar* blaptr = (MT_Scalar*) newaddrbase; 00058 copyipo->SetNewTarget((MT_Scalar*)blaptr); 00059 } 00060 00061 return iporeplica; 00062 }