Blender V2.61 - r43446

KX_WorldIpoController.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_WorldIpoController.h"
00034 #include "KX_ScalarInterpolator.h"
00035 #include "KX_WorldInfo.h"
00036 
00037 #if defined(_WIN64)
00038 typedef unsigned __int64 uint_ptr;
00039 #else
00040 typedef unsigned long uint_ptr;
00041 #endif
00042 
00043 bool KX_WorldIpoController::Update(double currentTime)
00044 {
00045     if (m_modified)
00046     {
00047         T_InterpolatorList::iterator i;
00048         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00049             (*i)->Execute(m_ipotime);//currentTime);
00050         }
00051 
00052         /* TODO, this will crash! */
00053         KX_WorldInfo *world = NULL;
00054 
00055         if (m_modify_mist_start) {
00056             world->setMistStart(m_mist_start);
00057         }
00058 
00059         if (m_modify_mist_color) {
00060             world->setMistColorRed(m_mist_rgb[0]);
00061             world->setMistColorGreen(m_mist_rgb[1]);
00062             world->setMistColorBlue(m_mist_rgb[2]);
00063         }
00064 
00065         if (m_modify_mist_dist) {
00066             world->setMistDistance(m_mist_dist);
00067         }
00068 
00069         m_modified=false;
00070     }
00071     return false;
00072 }
00073 
00074 
00075 void KX_WorldIpoController::AddInterpolator(KX_IInterpolator* interp)
00076 {
00077     this->m_interpolators.push_back(interp);
00078 }
00079 
00080 
00081 SG_Controller*  KX_WorldIpoController::GetReplica(class SG_Node* destnode)
00082 {
00083     KX_WorldIpoController* iporeplica = new KX_WorldIpoController(*this);
00084     // clear object that ipo acts on
00085     iporeplica->ClearObject();
00086 
00087     // dirty hack, ask Gino for a better solution in the ipo implementation
00088     // hacken en zagen, in what we call datahiding, not written for replication :(
00089 
00090     T_InterpolatorList oldlist = m_interpolators;
00091     iporeplica->m_interpolators.clear();
00092 
00093     T_InterpolatorList::iterator i;
00094     for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
00095         KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
00096         iporeplica->AddInterpolator(copyipo);
00097 
00098         MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
00099         uint_ptr orgbase = (uint_ptr)this;
00100         uint_ptr orgloc = (uint_ptr)scaal;
00101         uint_ptr offset = orgloc-orgbase;
00102         uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
00103         MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
00104         copyipo->SetNewTarget((MT_Scalar*)blaptr);
00105     }
00106     
00107     return iporeplica;
00108 }
00109 
00110 KX_WorldIpoController::~KX_WorldIpoController()
00111 {
00112 
00113     T_InterpolatorList::iterator i;
00114     for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
00115         delete (*i);
00116     }
00117     
00118 }