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