add missing files after merging
[blender.git] / source / gameengine / Ketsji / KX_LightIpoSGController.cpp
1 /*
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file gameengine/Ketsji/KX_LightIpoSGController.cpp
30  *  \ingroup ketsji
31  */
32
33
34 #include "KX_LightIpoSGController.h"
35 #include "KX_ScalarInterpolator.h"
36 #include "KX_Light.h"
37 #include "RAS_LightObject.h"
38
39 #if defined(_WIN64)
40 typedef unsigned __int64 uint_ptr;
41 #else
42 typedef unsigned long uint_ptr;
43 #endif
44
45 bool KX_LightIpoSGController::Update(double currentTime)
46 {
47         if (m_modified)
48         {
49                 T_InterpolatorList::iterator i;
50                 for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
51                         (*i)->Execute(m_ipotime);//currentTime);
52                 }
53                 
54                 RAS_LightObject *lightobj;
55
56                 SG_Spatial* ob = (SG_Spatial*)m_pObject;
57                 KX_LightObject* kxlight = (KX_LightObject*) ob->GetSGClientObject();
58                 lightobj = kxlight->GetLightData();
59                 //lightobj = (KX_Light*) 
60
61                 if (m_modify_energy) {
62                         lightobj->m_energy = m_energy;
63                 }
64
65                 if (m_modify_color) {
66                         lightobj->m_red   = m_col_rgb[0];
67                         lightobj->m_green = m_col_rgb[1];
68                         lightobj->m_blue  = m_col_rgb[2];
69                 }
70
71                 if (m_modify_dist) {
72                         lightobj->m_distance = m_dist;
73                 }
74
75                 m_modified=false;
76         }
77         return false;
78 }
79
80
81 void KX_LightIpoSGController::AddInterpolator(KX_IInterpolator* interp)
82 {
83         this->m_interpolators.push_back(interp);
84 }
85
86 SG_Controller*  KX_LightIpoSGController::GetReplica(class SG_Node* destnode)
87 {
88         KX_LightIpoSGController* iporeplica = new KX_LightIpoSGController(*this);
89         // clear object that ipo acts on
90         iporeplica->ClearObject();
91
92         // dirty hack, ask Gino for a better solution in the ipo implementation
93         // hacken en zagen, in what we call datahiding, not written for replication :(
94
95         T_InterpolatorList oldlist = m_interpolators;
96         iporeplica->m_interpolators.clear();
97
98         T_InterpolatorList::iterator i;
99         for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
100                 KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
101                 iporeplica->AddInterpolator(copyipo);
102
103                 MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
104                 uint_ptr orgbase = (uint_ptr)this;
105                 uint_ptr orgloc = (uint_ptr)scaal;
106                 uint_ptr offset = orgloc-orgbase;
107                 uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
108                 MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
109                 copyipo->SetNewTarget((MT_Scalar*)blaptr);
110         }
111         
112         return iporeplica;
113 }
114
115 KX_LightIpoSGController::~KX_LightIpoSGController()
116 {
117
118         T_InterpolatorList::iterator i;
119         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
120                 delete (*i);
121         }
122         
123 }