doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / Ketsji / KX_MaterialIpoController.cpp
1
2 #include "KX_MaterialIpoController.h"
3 #include "KX_ScalarInterpolator.h"
4 #include "KX_GameObject.h"
5
6 #include "BLO_sys_types.h" // for intptr_t support
7
8 bool KX_MaterialIpoController::Update(double currentTime)
9 {
10         if (m_modified)
11         {
12                 m_rgba[0]=0;
13                 m_rgba[1]=0;
14                 m_rgba[2]=0;
15                 m_rgba[3]=0;
16         
17                 m_specrgb[0] =0;
18                 m_specrgb[1] =0;
19                 m_specrgb[2] =0;
20                 m_hard =0;
21                 m_spec=0;
22                 m_ref=0;
23                 m_emit=0;
24                 m_alpha = 0;
25
26
27                 T_InterpolatorList::iterator i;
28                 for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
29                         (*i)->Execute(m_ipotime);
30                 }
31                 
32
33                 SG_Spatial* ob = (SG_Spatial*)m_pObject;
34                 KX_GameObject* kxgameobj= (KX_GameObject*) ob->GetSGClientObject();
35
36                 //kxgameobj->SetObjectColor(m_rgba);
37                 kxgameobj->UpdateMaterialData( 
38                         m_matname_hash,
39                         m_rgba, 
40                         m_specrgb, 
41                         m_hard, 
42                         m_spec, 
43                         m_ref, 
44                         m_emit,
45                         m_alpha
46                 );
47
48                 m_modified=false;
49         }
50         return false;
51 }
52
53
54 void KX_MaterialIpoController::AddInterpolator(KX_IInterpolator* interp)
55 {
56         this->m_interpolators.push_back(interp);
57 }
58
59 SG_Controller*  KX_MaterialIpoController::GetReplica(class SG_Node* destnode)
60 {
61         KX_MaterialIpoController* iporeplica = new KX_MaterialIpoController(*this);
62         // clear object that ipo acts on
63         iporeplica->ClearObject();
64
65         // dirty hack, ask Gino for a better solution in the ipo implementation
66         // hacken en zagen, in what we call datahiding, not written for replication :(
67
68         T_InterpolatorList oldlist = m_interpolators;
69         iporeplica->m_interpolators.clear();
70
71         T_InterpolatorList::iterator i;
72         for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
73                 KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
74                 iporeplica->AddInterpolator(copyipo);
75
76                 MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
77                 intptr_t orgbase = (intptr_t)this;
78                 intptr_t orgloc = (intptr_t)scaal;
79                 intptr_t offset = orgloc-orgbase;
80                 intptr_t newaddrbase = (intptr_t)iporeplica + offset;
81                 MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
82                 copyipo->SetNewTarget((MT_Scalar*)blaptr);
83         }
84         
85         return iporeplica;
86 }
87
88 KX_MaterialIpoController::~KX_MaterialIpoController()
89 {
90
91         T_InterpolatorList::iterator i;
92         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
93                 delete (*i);
94         }
95         
96 }
97