Blender V2.61 - r43446

KX_ObColorIpoSGController.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "KX_ObColorIpoSGController.h"
00034 #include "KX_ScalarInterpolator.h"
00035 #include "KX_GameObject.h"
00036 
00037 #if defined(_WIN64)
00038 typedef unsigned __int64 uint_ptr;
00039 #else
00040 typedef unsigned long uint_ptr;
00041 #endif
00042 
00043 
00044 bool KX_ObColorIpoSGController::Update(double currentTime)
00045 {
00046     if (m_modified)
00047     {
00048         m_rgba[0]=0;
00049         m_rgba[1]=0;
00050         m_rgba[2]=0;
00051         m_rgba[3]=0;
00052 
00053         T_InterpolatorList::iterator i;
00054         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00055             (*i)->Execute(m_ipotime);
00056         }
00057         
00058 
00059         SG_Spatial* ob = (SG_Spatial*)m_pObject;
00060         KX_GameObject* kxgameobj= (KX_GameObject*) ob->GetSGClientObject();
00061 
00062         kxgameobj->SetObjectColor(m_rgba);
00063         
00064 
00065         m_modified=false;
00066     }
00067     return false;
00068 }
00069 
00070 
00071 void KX_ObColorIpoSGController::AddInterpolator(KX_IInterpolator* interp)
00072 {
00073     this->m_interpolators.push_back(interp);
00074 }
00075 
00076 SG_Controller*  KX_ObColorIpoSGController::GetReplica(class SG_Node* destnode)
00077 {
00078     KX_ObColorIpoSGController* iporeplica = new KX_ObColorIpoSGController(*this);
00079     // clear object that ipo acts on
00080     iporeplica->ClearObject();
00081 
00082     // dirty hack, ask Gino for a better solution in the ipo implementation
00083     // hacken en zagen, in what we call datahiding, not written for replication :(
00084 
00085     T_InterpolatorList oldlist = m_interpolators;
00086     iporeplica->m_interpolators.clear();
00087 
00088     T_InterpolatorList::iterator i;
00089     for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
00090         KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
00091         iporeplica->AddInterpolator(copyipo);
00092 
00093         MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
00094         uint_ptr orgbase = (uint_ptr)this;
00095         uint_ptr orgloc = (uint_ptr)scaal;
00096         uint_ptr offset = orgloc-orgbase;
00097         uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
00098         MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
00099         copyipo->SetNewTarget((MT_Scalar*)blaptr);
00100     }
00101     
00102     return iporeplica;
00103 }
00104 
00105 KX_ObColorIpoSGController::~KX_ObColorIpoSGController()
00106 {
00107 
00108     T_InterpolatorList::iterator i;
00109     for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00110         delete (*i);
00111     }
00112     
00113 }