Blender V2.61 - r43446

KX_MaterialIpoController.cpp

Go to the documentation of this file.
00001 
00005 #include "KX_MaterialIpoController.h"
00006 #include "KX_ScalarInterpolator.h"
00007 #include "KX_GameObject.h"
00008 
00009 #include "BLO_sys_types.h" // for intptr_t support
00010 
00011 bool KX_MaterialIpoController::Update(double currentTime)
00012 {
00013     if (m_modified)
00014     {
00015         m_rgba[0]=0;
00016         m_rgba[1]=0;
00017         m_rgba[2]=0;
00018         m_rgba[3]=0;
00019     
00020         m_specrgb[0] =0;
00021         m_specrgb[1] =0;
00022         m_specrgb[2] =0;
00023         m_hard =0;
00024         m_spec=0;
00025         m_ref=0;
00026         m_emit=0;
00027         m_alpha = 0;
00028 
00029 
00030         T_InterpolatorList::iterator i;
00031         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00032             (*i)->Execute(m_ipotime);
00033         }
00034         
00035 
00036         SG_Spatial* ob = (SG_Spatial*)m_pObject;
00037         KX_GameObject* kxgameobj= (KX_GameObject*) ob->GetSGClientObject();
00038 
00039         //kxgameobj->SetObjectColor(m_rgba);
00040         kxgameobj->UpdateMaterialData( 
00041             m_matname_hash,
00042             m_rgba, 
00043             m_specrgb, 
00044             m_hard, 
00045             m_spec, 
00046             m_ref, 
00047             m_emit,
00048             m_alpha
00049         );
00050 
00051         m_modified=false;
00052     }
00053     return false;
00054 }
00055 
00056 
00057 void KX_MaterialIpoController::AddInterpolator(KX_IInterpolator* interp)
00058 {
00059     this->m_interpolators.push_back(interp);
00060 }
00061 
00062 SG_Controller*  KX_MaterialIpoController::GetReplica(class SG_Node* destnode)
00063 {
00064     KX_MaterialIpoController* iporeplica = new KX_MaterialIpoController(*this);
00065     // clear object that ipo acts on
00066     iporeplica->ClearObject();
00067 
00068     // dirty hack, ask Gino for a better solution in the ipo implementation
00069     // hacken en zagen, in what we call datahiding, not written for replication :(
00070 
00071     T_InterpolatorList oldlist = m_interpolators;
00072     iporeplica->m_interpolators.clear();
00073 
00074     T_InterpolatorList::iterator i;
00075     for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
00076         KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
00077         iporeplica->AddInterpolator(copyipo);
00078 
00079         MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
00080         intptr_t orgbase = (intptr_t)this;
00081         intptr_t orgloc = (intptr_t)scaal;
00082         intptr_t offset = orgloc-orgbase;
00083         intptr_t newaddrbase = (intptr_t)iporeplica + offset;
00084         MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
00085         copyipo->SetNewTarget((MT_Scalar*)blaptr);
00086     }
00087     
00088     return iporeplica;
00089 }
00090 
00091 KX_MaterialIpoController::~KX_MaterialIpoController()
00092 {
00093 
00094     T_InterpolatorList::iterator i;
00095     for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00096         delete (*i);
00097     }
00098     
00099 }
00100