ParticlesSimple Plugin  1.0
Efecto de partículas simple, con motor físico por aproximación de Euler.
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones 'defines' Páginas
moEffectParticlesSimple.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moEffectParticlesSimple.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
33 
34 
35 #include "moArray.h"
36 moDefineDynamicArray( moParticlesSimpleArray )
37 
38 //========================
39 // Factory
40 //========================
41 
42 moEffectParticlesSimpleFactory *m_EffectParticlesSimpleFactory = NULL;
43 
44 MO_PLG_API moEffectFactory* CreateEffectFactory(){
45  if(m_EffectParticlesSimpleFactory==NULL)
46  m_EffectParticlesSimpleFactory = new moEffectParticlesSimpleFactory();
47  return(moEffectFactory*) m_EffectParticlesSimpleFactory;
48 }
49 
50 MO_PLG_API void DestroyEffectFactory(){
51  delete m_EffectParticlesSimpleFactory;
52  m_EffectParticlesSimpleFactory = NULL;
53 }
54 
56  return new moEffectParticlesSimple();
57 }
58 
60  delete fx;
61 }
62 
63 //========================
64 // Efecto
65 //========================
66 
68  SetName("particlessimple");
69 
71  //m_EffectState.stereo = MO_ACTIVATED;
72 }
73 
75  Finish();
76 }
77 
78 moConfigDefinition *
79 moEffectParticlesSimple::GetDefinition( moConfigDefinition *p_configdefinition ) {
80 
81  //default: alpha, color, syncro
82  p_configdefinition = moEffect::GetDefinition( p_configdefinition );
83 
84  p_configdefinition->Add( moText("particlecolor"), MO_PARAM_COLOR, PARTICLES_PARTICLECOLOR );
85 
86  p_configdefinition->Add( moText("font"), MO_PARAM_FONT, PARTICLES_FONT, moValue( "Default", "TXT", "0", "NUM", "32.0", "NUM") );
87  p_configdefinition->Add( moText("text"), MO_PARAM_TEXT, PARTICLES_TEXT, moValue( "Insert text in text parameter", "TXT") );
88  p_configdefinition->Add( moText("ortho"), MO_PARAM_NUMERIC, PARTICLES_ORTHO, moValue( "0", "NUM").Ref() );
89 
90 
91  p_configdefinition->Add( moText("texture"), MO_PARAM_TEXTURE, PARTICLES_TEXTURE, moValue( "default", "TXT") );
92  p_configdefinition->Add( moText("folders"), MO_PARAM_TEXTUREFOLDER, PARTICLES_FOLDERS, moValue( "", "TXT") );
93 
94  p_configdefinition->Add( moText("texture_mode"), MO_PARAM_NUMERIC, PARTICLES_TEXTUREMODE, moValue( "0", "NUM"), moText("UNIT,PATCH,MANY,MANY2PATCH"));
95 
96  p_configdefinition->Add( moText("blending"), MO_PARAM_BLENDING, PARTICLES_BLENDING, moValue( "0", "NUM") );
97  p_configdefinition->Add( moText("width"), MO_PARAM_NUMERIC, PARTICLES_WIDTH, moValue( "9", "NUM") );
98  p_configdefinition->Add( moText("height"), MO_PARAM_NUMERIC, PARTICLES_HEIGHT, moValue( "9", "NUM") );
99 
100  p_configdefinition->Add( moText("sizex"), MO_PARAM_FUNCTION, PARTICLES_SIZEX, moValue( "10.0", "FUNCTION").Ref() );
101  p_configdefinition->Add( moText("sizey"), MO_PARAM_FUNCTION, PARTICLES_SIZEY, moValue( "10.0", "FUNCTION").Ref() );
102  p_configdefinition->Add( moText("sizez"), MO_PARAM_FUNCTION, PARTICLES_SIZEY, moValue( "10.0", "FUNCTION").Ref() );
103 
104  p_configdefinition->Add( moText("gravity"), MO_PARAM_FUNCTION, PARTICLES_GRAVITY, moValue( "0.0", "FUNCTION").Ref() );
105  p_configdefinition->Add( moText("viscosity"), MO_PARAM_FUNCTION, PARTICLES_VISCOSITY, moValue( "0.8", "FUNCTION").Ref() );
106 
107  p_configdefinition->Add( moText("maxage"), MO_PARAM_FUNCTION, PARTICLES_MAXAGE, moValue( "3000", "FUNCTION").Ref() );
108  p_configdefinition->Add( moText("emitionperiod"), MO_PARAM_FUNCTION, PARTICLES_EMITIONPERIOD, moValue( "10", "FUNCTION").Ref() );
109  //p_configdefinition->Add( moText("emitionrate"), MO_PARAM_NUMERIC, PARTICLES_EMITIONRATE, moValue( "1", "NUM").Ref() );
110  p_configdefinition->Add( moText("emitionrate"), MO_PARAM_FUNCTION, PARTICLES_EMITIONRATE, moValue( "1", "FUNCTION").Ref() );
111  p_configdefinition->Add( moText("deathperiod"), MO_PARAM_NUMERIC, PARTICLES_DEATHPERIOD, moValue( "1", "NUM").Ref() );
112  p_configdefinition->Add( moText("particlescript"), MO_PARAM_SCRIPT, PARTICLES_SCRIPT2 );
113 
114  p_configdefinition->Add( moText("randommethod"), MO_PARAM_NUMERIC, PARTICLES_RANDOMMETHOD, moValue( "0", "NUM").Ref(), moText("NOISY,COLINEAR,PERPENDICULAR") );
115  p_configdefinition->Add( moText("creationmethod"), MO_PARAM_NUMERIC, PARTICLES_CREATIONMETHOD, moValue( "0", "NUM").Ref(), moText("LINEAR,PLANAR,VOLUMETRIC,CENTER") );
116  p_configdefinition->Add( moText("orientationmode"), MO_PARAM_NUMERIC, PARTICLES_ORIENTATIONMODE, moValue( "0", "NUM").Ref(), moText("FIXED,CAMERA,MOTION,ACCELERATION") );
117 
118  p_configdefinition->Add( moText("fadein"), MO_PARAM_FUNCTION, PARTICLES_FADEIN, moValue( "0", "FUNCTION").Ref() );
119  p_configdefinition->Add( moText("fadeout"), MO_PARAM_FUNCTION, PARTICLES_FADEOUT, moValue( "0", "FUNCTION").Ref() );
120  p_configdefinition->Add( moText("sizein"), MO_PARAM_FUNCTION, PARTICLES_SIZEIN, moValue( "0", "FUNCTION").Ref() );
121  p_configdefinition->Add( moText("sizeout"), MO_PARAM_FUNCTION, PARTICLES_SIZEOUT, moValue( "0", "FUNCTION").Ref() );
122 
123 
124 
125  p_configdefinition->Add( moText("attractortype"), MO_PARAM_NUMERIC, PARTICLES_ATTRACTORTYPE, moValue( "0", "NUM").Ref(), moText("POINT,GRID,SPHERE,TUBE,JET,TRACKER,VERTEX") );
126  p_configdefinition->Add( moText("attractormode"), MO_PARAM_NUMERIC, PARTICLES_ATTRACTORMODE, moValue( "0", "NUM").Ref(), moText("ACCELERATION,STICK,BOUNCE,BREAKS,BRAKE,LINEAR") );
127  p_configdefinition->Add( moText("attractorvectorx"), MO_PARAM_FUNCTION, PARTICLES_ATTRACTORVECTOR_X, moValue( "0", "FUNCTION").Ref() );
128  p_configdefinition->Add( moText("attractorvectory"), MO_PARAM_FUNCTION, PARTICLES_ATTRACTORVECTOR_Y, moValue( "0", "FUNCTION").Ref() );
129  p_configdefinition->Add( moText("attractorvectorz"), MO_PARAM_FUNCTION, PARTICLES_ATTRACTORVECTOR_Z, moValue( "0", "FUNCTION").Ref() );
130 
131  p_configdefinition->Add( moText("emittertype"), MO_PARAM_NUMERIC, PARTICLES_EMITTERTYPE, moValue( "0", "NUM").Ref(), moText("GRID,SPHERE,TUBE,JET,POINT,TRACKER,TRACKER2,SPIRAL,CIRCLE") );
132  p_configdefinition->Add( moText("emittervectorx"), MO_PARAM_FUNCTION, PARTICLES_EMITTERVECTOR_X, moValue( "0", "FUNCTION").Ref() );
133  p_configdefinition->Add( moText("emittervectory"), MO_PARAM_FUNCTION, PARTICLES_EMITTERVECTOR_Y, moValue( "0", "FUNCTION").Ref() );
134  p_configdefinition->Add( moText("emittervectorz"), MO_PARAM_FUNCTION, PARTICLES_EMITTERVECTOR_Z, moValue( "0", "FUNCTION").Ref() );
135 
136 
137  p_configdefinition->Add( moText("randomposition"), MO_PARAM_FUNCTION, PARTICLES_RANDOMPOSITION, moValue( "0", "FUNCTION").Ref() );
138  p_configdefinition->Add( moText("randompositionx"), MO_PARAM_FUNCTION, PARTICLES_RANDOMPOSITION_X, moValue( "0", "FUNCTION").Ref() );
139  p_configdefinition->Add( moText("randompositiony"), MO_PARAM_FUNCTION, PARTICLES_RANDOMPOSITION_Y, moValue( "0", "FUNCTION").Ref() );
140  p_configdefinition->Add( moText("randompositionz"), MO_PARAM_FUNCTION, PARTICLES_RANDOMPOSITION_Y, moValue( "0", "FUNCTION").Ref() );
141 
142  p_configdefinition->Add( moText("randomvelocity"), MO_PARAM_FUNCTION, PARTICLES_RANDOMVELOCITY, moValue( "1.0", "FUNCTION").Ref() );
143  p_configdefinition->Add( moText("randomvelocityx"), MO_PARAM_FUNCTION, PARTICLES_RANDOMVELOCITY_X, moValue( "1.0", "FUNCTION").Ref() );
144  p_configdefinition->Add( moText("randomvelocityy"), MO_PARAM_FUNCTION, PARTICLES_RANDOMVELOCITY_Y, moValue( "1.0", "FUNCTION").Ref() );
145  p_configdefinition->Add( moText("randomvelocityz"), MO_PARAM_FUNCTION, PARTICLES_RANDOMVELOCITY_Z, moValue( "1.0", "FUNCTION").Ref() );
146 
147  p_configdefinition->Add( moText("randommotion"), MO_PARAM_FUNCTION, PARTICLES_RANDOMMOTION, moValue( "0.0", "FUNCTION").Ref() );
148  p_configdefinition->Add( moText("randommotionx"), MO_PARAM_FUNCTION, PARTICLES_RANDOMMOTION_X, moValue( "0.0", "FUNCTION").Ref() );
149  p_configdefinition->Add( moText("randommotiony"), MO_PARAM_FUNCTION, PARTICLES_RANDOMMOTION_Y, moValue( "0.0", "FUNCTION").Ref() );
150  p_configdefinition->Add( moText("randommotionz"), MO_PARAM_FUNCTION, PARTICLES_RANDOMMOTION_Z, moValue( "0.0", "FUNCTION").Ref() );
151 
152  p_configdefinition->Add( moText("rotatex_particle"), MO_PARAM_ROTATEX, PARTICLES_ROTATEX_PARTICLE, moValue( "0.0", "FUNCTION").Ref() );
153  p_configdefinition->Add( moText("rotatey_particle"), MO_PARAM_ROTATEY, PARTICLES_ROTATEY_PARTICLE, moValue( "0.0", "FUNCTION").Ref() );
154  p_configdefinition->Add( moText("rotatez_particle"), MO_PARAM_ROTATEZ, PARTICLES_ROTATEZ_PARTICLE, moValue( "0.0", "FUNCTION").Ref() );
155 
156  p_configdefinition->Add( moText("scalex_particle"), MO_PARAM_SCALEX, PARTICLES_SCALEX_PARTICLE, moValue( "1.0", "FUNCTION").Ref() );
157  p_configdefinition->Add( moText("scaley_particle"), MO_PARAM_SCALEY, PARTICLES_SCALEY_PARTICLE, moValue( "1.0", "FUNCTION").Ref() );
158  p_configdefinition->Add( moText("scalez_particle"), MO_PARAM_SCALEZ, PARTICLES_SCALEZ_PARTICLE, moValue( "1.0", "FUNCTION").Ref() );
159 
160  p_configdefinition->Add( moText("time_to_revelation"), MO_PARAM_NUMERIC, PARTICLES_TIMETOREVELATION, moValue( "2000", "NUM") );
161  p_configdefinition->Add( moText("time_of_revelation"), MO_PARAM_NUMERIC, PARTICLES_TIMEOFREVELATION, moValue( "3000", "NUM") );
162  p_configdefinition->Add( moText("time_to_restoration"), MO_PARAM_NUMERIC, PARTICLES_TIMETORESTORATION, moValue( "2000", "NUM") );
163  p_configdefinition->Add( moText("time_of_restoration"), MO_PARAM_NUMERIC, PARTICLES_TIMEOFRESTORATION, moValue( "3000", "NUM") );
164  p_configdefinition->Add( moText("drawing_features"), MO_PARAM_NUMERIC, PARTICLES_DRAWINGFEATURES, moValue( "0", "NUM"), moText("NO,YES") );
165 
166  p_configdefinition->Add( moText("translatex"), MO_PARAM_TRANSLATEX, PARTICLES_TRANSLATEX, moValue( "0.0", "FUNCTION").Ref() );
167  p_configdefinition->Add( moText("translatey"), MO_PARAM_TRANSLATEY, PARTICLES_TRANSLATEY, moValue( "0.0", "FUNCTION").Ref() );
168  p_configdefinition->Add( moText("translatez"), MO_PARAM_TRANSLATEZ, PARTICLES_TRANSLATEZ, moValue( "0.0", "FUNCTION").Ref() );
169  p_configdefinition->Add( moText("rotatex"), MO_PARAM_ROTATEX, PARTICLES_ROTATEX, moValue( "0.0", "FUNCTION").Ref() );
170  p_configdefinition->Add( moText("rotatey"), MO_PARAM_ROTATEY, PARTICLES_ROTATEY, moValue( "0.0", "FUNCTION").Ref() );
171  p_configdefinition->Add( moText("rotatez"), MO_PARAM_ROTATEZ, PARTICLES_ROTATEZ, moValue( "0.0", "FUNCTION").Ref() );
172  p_configdefinition->Add( moText("scalex"), MO_PARAM_SCALEX, PARTICLES_SCALEX, moValue( "1.0", "FUNCTION").Ref() );
173  p_configdefinition->Add( moText("scaley"), MO_PARAM_SCALEY, PARTICLES_SCALEY, moValue( "1.0", "FUNCTION").Ref() );
174  p_configdefinition->Add( moText("scalez"), MO_PARAM_SCALEZ, PARTICLES_SCALEZ, moValue( "1.0", "FUNCTION").Ref() );
175  p_configdefinition->Add( moText("eyex"), MO_PARAM_FUNCTION, PARTICLES_EYEX, moValue( "0.0", "FUNCTION").Ref() );
176  p_configdefinition->Add( moText("eyey"), MO_PARAM_FUNCTION, PARTICLES_EYEY, moValue( "0.0", "FUNCTION").Ref() );
177  p_configdefinition->Add( moText("eyez"), MO_PARAM_FUNCTION, PARTICLES_EYEZ, moValue( "10.0", "FUNCTION").Ref() );
178  p_configdefinition->Add( moText("viewx"), MO_PARAM_FUNCTION, PARTICLES_VIEWX, moValue( "0.0", "FUNCTION").Ref() );
179  p_configdefinition->Add( moText("viewy"), MO_PARAM_FUNCTION, PARTICLES_VIEWY, moValue( "0.0", "FUNCTION").Ref() );
180  p_configdefinition->Add( moText("viewz"), MO_PARAM_FUNCTION, PARTICLES_VIEWZ, moValue( "0.0", "FUNCTION").Ref() );
181  p_configdefinition->Add( moText("orderingmode"), MO_PARAM_NUMERIC, PARTICLES_ORDERING_MODE, moValue( "0", "NUM"), moText("NONE,ZDEPTHTEST,ZPOSITION,COMPLETE") );
182  return p_configdefinition;
183 }
184 
185 MOboolean
187 {
188 
190  m_pParticleTime = new moInlet();
191 
192  if (m_pParticleTime) {
193  ((moConnector*)m_pParticleTime)->Init( moText("particletime"), m_Inlets.Count(), MO_DATA_NUMBER_DOUBLE );
194  m_Inlets.Add(m_pParticleTime);
195  }
196 
197  m_pParticleIndex = new moInlet();
198 
199  if (m_pParticleIndex) {
200  ((moConnector*)m_pParticleIndex)->Init( moText("particleindex"), m_Inlets.Count(), MO_DATA_NUMBER_LONG );
201  m_Inlets.Add(m_pParticleIndex);
202  }
203 
204 
205  if (!PreInit()) return false;
206 
207  if (glActiveTextureARB) {
208  } else {
209  glewInit();
210  //MODebug2->Message( moText("moEffectParticlesSimple::Init > glActiveTextureARB: ") + moText(IntToStr((int)glActiveTextureARB)) );
211  //MODebug2->Message( moText("moEffectParticlesSimple::Init > glMultiTexCoord2fARB: ") + moText(IntToStr((int)glMultiTexCoord2fARB)) );
212  }
213 
214  moDefineParamIndex( PARTICLES_INLET, moText("inlet") );
215  moDefineParamIndex( PARTICLES_OUTLET, moText("outlet") );
216  moDefineParamIndex( PARTICLES_SCRIPT, moText("script") );
217 
218  moDefineParamIndex( PARTICLES_ALPHA, moText("alpha") );
219  moDefineParamIndex( PARTICLES_COLOR, moText("color") );
220  moDefineParamIndex( PARTICLES_SYNC, moText("syncro") );
221  moDefineParamIndex( PARTICLES_PHASE, moText("phase") );
222  moDefineParamIndex( PARTICLES_PARTICLECOLOR, moText("particlecolor") );
223  moDefineParamIndex( PARTICLES_FONT, moText("font") );
224  moDefineParamIndex( PARTICLES_TEXT, moText("text") );
225  moDefineParamIndex( PARTICLES_ORTHO, moText("ortho") );
226 
227 
228  moDefineParamIndex( PARTICLES_TEXTURE, moText("texture") );
229  moDefineParamIndex( PARTICLES_FOLDERS, moText("folders") );
230  moDefineParamIndex( PARTICLES_TEXTUREMODE, moText("texture_mode") );
231  moDefineParamIndex( PARTICLES_BLENDING, moText("blending") );
232 
233  moDefineParamIndex( PARTICLES_WIDTH, moText("width") );
234  moDefineParamIndex( PARTICLES_HEIGHT, moText("height") );
235  moDefineParamIndex( PARTICLES_SIZEX, moText("sizex") );
236  moDefineParamIndex( PARTICLES_SIZEY, moText("sizey") );
237  moDefineParamIndex( PARTICLES_SIZEZ, moText("sizez") );
238 
239  moDefineParamIndex( PARTICLES_GRAVITY, moText("gravity") );
240  moDefineParamIndex( PARTICLES_VISCOSITY, moText("viscosity") );
241 
242  moDefineParamIndex( PARTICLES_MAXAGE, moText("maxage") );
243  moDefineParamIndex( PARTICLES_EMITIONPERIOD, moText("emitionperiod") );
244  moDefineParamIndex( PARTICLES_EMITIONRATE, moText("emitionrate") );
245  moDefineParamIndex( PARTICLES_DEATHPERIOD, moText("deathperiod") );
246  moDefineParamIndex( PARTICLES_SCRIPT2, moText("particlescript") );
247 
248  moDefineParamIndex( PARTICLES_FADEIN, moText("fadein") );
249  moDefineParamIndex( PARTICLES_FADEOUT, moText("fadeout") );
250  moDefineParamIndex( PARTICLES_SIZEIN, moText("sizein") );
251  moDefineParamIndex( PARTICLES_SIZEOUT, moText("sizeout") );
252 
253  moDefineParamIndex( PARTICLES_RANDOMMETHOD, moText("randommethod") );
254  moDefineParamIndex( PARTICLES_CREATIONMETHOD, moText("creationmethod") );
255  moDefineParamIndex( PARTICLES_ORIENTATIONMODE, moText("orientationmode") );
256 
257  moDefineParamIndex( PARTICLES_RANDOMPOSITION, moText("randomposition") );
258  moDefineParamIndex( PARTICLES_RANDOMPOSITION_X, moText("randompositionx") );
259  moDefineParamIndex( PARTICLES_RANDOMPOSITION_Y, moText("randompositiony") );
260  moDefineParamIndex( PARTICLES_RANDOMPOSITION_Z, moText("randompositionz") );
261 
262  moDefineParamIndex( PARTICLES_RANDOMVELOCITY, moText("randomvelocity") );
263  moDefineParamIndex( PARTICLES_RANDOMVELOCITY_X, moText("randomvelocityx") );
264  moDefineParamIndex( PARTICLES_RANDOMVELOCITY_Y, moText("randomvelocityy") );
265  moDefineParamIndex( PARTICLES_RANDOMVELOCITY_Z, moText("randomvelocityz") );
266 
267  moDefineParamIndex( PARTICLES_RANDOMMOTION, moText("randommotion") );
268  moDefineParamIndex( PARTICLES_RANDOMMOTION_X, moText("randommotionx") );
269  moDefineParamIndex( PARTICLES_RANDOMMOTION_Y, moText("randommotiony") );
270  moDefineParamIndex( PARTICLES_RANDOMMOTION_Z, moText("randommotionz") );
271 
272  moDefineParamIndex( PARTICLES_EMITTERTYPE, moText("emittertype") );
273  moDefineParamIndex( PARTICLES_EMITTERVECTOR_X, moText("emittervectorx") );
274  moDefineParamIndex( PARTICLES_EMITTERVECTOR_Y, moText("emittervectory") );
275  moDefineParamIndex( PARTICLES_EMITTERVECTOR_Z, moText("emittervectorz") );
276 
277  moDefineParamIndex( PARTICLES_ATTRACTORTYPE, moText("attractortype") );
278  moDefineParamIndex( PARTICLES_ATTRACTORMODE, moText("attractormode") );
279  moDefineParamIndex( PARTICLES_ATTRACTORVECTOR_X, moText("attractorvectorx") );
280  moDefineParamIndex( PARTICLES_ATTRACTORVECTOR_Y, moText("attractorvectory") );
281  moDefineParamIndex( PARTICLES_ATTRACTORVECTOR_Z, moText("attractorvectorz") );
282 
283 
284  moDefineParamIndex( PARTICLES_SCALEX_PARTICLE, moText("scalex_particle") );
285  moDefineParamIndex( PARTICLES_SCALEY_PARTICLE, moText("scaley_particle") );
286  moDefineParamIndex( PARTICLES_SCALEZ_PARTICLE, moText("scalez_particle") );
287  moDefineParamIndex( PARTICLES_ROTATEX_PARTICLE, moText("rotatex_particle") );
288  moDefineParamIndex( PARTICLES_ROTATEY_PARTICLE, moText("rotatey_particle") );
289  moDefineParamIndex( PARTICLES_ROTATEZ_PARTICLE, moText("rotatez_particle") );
290 
291  moDefineParamIndex( PARTICLES_TIMETOREVELATION, moText("time_to_revelation") );
292  moDefineParamIndex( PARTICLES_TIMEOFREVELATION, moText("time_of_revelation") );
293  moDefineParamIndex( PARTICLES_TIMETORESTORATION, moText("time_to_restoration") );
294  moDefineParamIndex( PARTICLES_TIMEOFRESTORATION, moText("time_of_restoration") );
295  moDefineParamIndex( PARTICLES_DRAWINGFEATURES, moText("drawing_features") );
296 
297  moDefineParamIndex( PARTICLES_TRANSLATEX, moText("translatex") );
298  moDefineParamIndex( PARTICLES_TRANSLATEY, moText("translatey") );
299  moDefineParamIndex( PARTICLES_TRANSLATEZ, moText("translatez") );
300  moDefineParamIndex( PARTICLES_SCALEX, moText("scalex") );
301  moDefineParamIndex( PARTICLES_SCALEY, moText("scaley") );
302  moDefineParamIndex( PARTICLES_SCALEZ, moText("scalez") );
303  moDefineParamIndex( PARTICLES_ROTATEX, moText("rotatex") );
304  moDefineParamIndex( PARTICLES_ROTATEY, moText("rotatey") );
305  moDefineParamIndex( PARTICLES_ROTATEZ, moText("rotatez") );
306  moDefineParamIndex( PARTICLES_EYEX, moText("eyex") );
307  moDefineParamIndex( PARTICLES_EYEY, moText("eyey") );
308  moDefineParamIndex( PARTICLES_EYEZ, moText("eyez") );
309  moDefineParamIndex( PARTICLES_VIEWX, moText("viewx") );
310  moDefineParamIndex( PARTICLES_VIEWY, moText("viewy") );
311  moDefineParamIndex( PARTICLES_VIEWZ, moText("viewz") );
312  moDefineParamIndex( PARTICLES_ORDERING_MODE, moText("orderingmode") );
313 
314  m_Physics.m_ParticleScript = moText("");
315 
316  m_Rate = 0;
317  last_tick = 0;
318  frame = 0;
319 
320  ortho = false;
321 
322  m_bTrackerInit = false;
323  m_pTrackerData = NULL;
324 
325  UpdateParameters();
326 
327  ResetTimers();
328 
329  InitParticlesSimple( m_Config.Int( moR(PARTICLES_WIDTH) ),
330  m_Config.Int( moR(PARTICLES_HEIGHT)) );
331 
332 
333  pTextureDest = NULL;
334  pSubSample = NULL;
335  samplebuffer = NULL;
336 
337  glidori = 0;
338  glid = 0;
339  original_width = 0;
340  original_height = 0;
341  original_proportion = 1.0;
342 
343  midi_red = midi_green = midi_blue = 1.0;
344  midi_maxage = 1.0; //in millis
345  midi_emitionperiod = 1.0;//in millisec
346  midi_emitionrate = 1.0; // n per emitionperiod
347  midi_randomvelocity = 1.0; //inicial vel
348  midi_randommotion = 1.0; //motion dynamic
349  #ifdef USE_TUIO
350  m_InletTuioSystemIndex = GetInletIndex("TUIOSYSTEM");
351  #endif
352  m_InletTrackerSystemIndex = GetInletIndex("TRACKERKLT");
353 
354  return true;
355 
356 }
357 
358 
359 void moEffectParticlesSimple::ResetTimers() {
360 
361  TimerFullRevelation.Stop();
362  TimerFullRestoration.Stop();
363  TimerOfRevelation.Stop();
364  TimerOfRestoration.Stop();
365 
366  FeatureActivity.Stop();
367  MotionActivity.Stop();
368  NoMotionActivity.Stop();
369  m_Physics.EmitionTimer.Stop();
370 
371  for ( int i=0; i < m_ParticlesSimpleArray.Count(); i++ ) {
372  moParticlesSimple* pPar = m_ParticlesSimpleArray[i];
373  pPar->Age.Stop();
374  pPar->Age.SetRelativeTimer( (moTimerAbsolute*)&m_EffectState.tempo );
375  pPar->Visible = false;
376  }
377 
378  m_Physics.m_pLastBordParticle = NULL;
379 }
380 
381 void moEffectParticlesSimple::Shot( moText source, int shot_type, int shot_file ) {
382 
383  MODebug2->Push(moText("moEffectParticlesSimple::Shot: Shot activated!!!!")+ (moText)source);
384 
385  moTextureBuffer* pTexBuf = NULL;
386 
387  pTextureDest = NULL;
388 
389  if (pSubSample && samplebuffer) {
390  delete [] samplebuffer;
391  pSubSample = NULL;
392  samplebuffer = NULL;
393  }
394 
395  glid = 0;
396  glidori = 0;
397 
398  if (texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH) {
399 
400 
401 
404 
405  if ( source != moText("")) {
406  //agregado:
407  //version banco de datos
408  moTextureBuffer* pTexBufAltas = NULL;
409  int ichosen;
410 
411  int idid = m_pResourceManager->GetTextureMan()->GetTextureBuffer(moText( source ),true);
412  if (idid>-1) {
413  pTexBufAltas = m_pResourceManager->GetTextureMan()->GetTextureBuffer(idid);
414  pTexBufAltas->UpdateImages(1);
415  }
416  if (pTexBufAltas) {
417  pTexBufAltas->UpdateImages(1);
418  int np = pTexBufAltas->GetImagesProcessed();
419  if (np>0) {
420  if (shot_type==0) {
422  ichosen = (int)( moMathf::UnitRandom() * np );
423  } else {
425  if (shot_file<0) {
426  ichosen = np - 1;
427  } else {
428  ichosen = shot_file;
429  }
430  }
431 
432  glidori = pTexBufAltas->GetFrame(ichosen);
433  glid = glidori;
434  if (glidori>0) {
435  pTextureDest = (moTexture*) pTexBufAltas->GetTexture(ichosen);
436  }
437  } else MODebug2->Error( moText("no images processed yet"));
438  }
439 
440  } else {
441  glid = m_Config.GetGLId( moR(PARTICLES_TEXTURE), &m_EffectState.tempo );
442  glidori = glid;
443  //MODebug2->Error( moText(" no texture buffer"));
444  //version self texture (LIVEIN0 o imagen)
445  if (glid>0) pTextureDest = m_Config[moR(PARTICLES_TEXTURE)][MO_SELECTED][0].Texture();
446  }
447 
448 
450  if (pTextureDest) {
451 
452 
454  time_t rawtime;
455  char strbuffer[0x100];
456  struct tm * timeinfo;
457 
458  srand(2);
459  int randcode = rand();
460 
461  time(&rawtime);
462  timeinfo = localtime ( &rawtime );
463  strftime (strbuffer,80,"%Y-%m-%d-%H-%M-",timeinfo);
464 
465 
466  moText datetime = strbuffer;
467  datetime+= IntToStr(randcode);
468 
469  moText alta;
470  moText baja;
471  moText extension;
472 
473  original_width = pTextureDest->GetWidth();
474  original_height = pTextureDest->GetHeight();
475  if (original_height>0) {
476  original_proportion = (float)original_width / (float) original_height;
477  } else original_proportion = 1.0f;
478 
479  alta = (this->GetLabelName()) + moText("ALTA");
480  baja = (this->GetLabelName()) + moText("BAJA");
481  extension = moText(".png");
482 
483  moText destalta;
484  moText destbaja;
485  moText copyalta;
486  destalta = m_pResourceManager->GetDataMan()->GetDataPath() + (moText)alta;
487  destbaja = m_pResourceManager->GetDataMan()->GetDataPath() + (moText)baja;
488  copyalta = m_pResourceManager->GetDataMan()->GetDataPath() + moText("cams/") + (moText)datetime + (moText)alta;
489 
490  pTextureDest->CreateThumbnail( "PNG", pTextureDest->GetWidth(), pTextureDest->GetHeight(), destalta );
491  pTextureDest->CreateThumbnail( "PNG", m_cols, m_rows, destbaja );
492 
493  if (source==moText("")) m_pResourceManager->GetFileMan()->CopyFile( destalta+(moText)extension , copyalta+(moText)extension );
494 
495  int idori = m_pResourceManager->GetTextureMan()->GetTextureMOId( alta+(moText)extension, false );
496  if (idori>-1) {
497  m_pResourceManager->GetTextureMan()->GetTexture(idori)->BuildFromFile( destalta+(moText)extension);
498  } else idori = m_pResourceManager->GetTextureMan()->AddTexture( alta+(moText)extension );
499 
500  int idti = m_pResourceManager->GetTextureMan()->GetTextureMOId( baja+(moText)extension, false );
501  if (idti>-1) {
502  m_pResourceManager->GetTextureMan()->GetTexture(idti)->BuildFromFile( destbaja+(moText)extension );
503  } else idti = m_pResourceManager->GetTextureMan()->AddTexture( baja+(moText)extension );
504 
505  if (idori>-1) glidori = m_pResourceManager->GetTextureMan()->GetTexture(idori)->GetGLId();
506 
507  //BAJA FOR SUBSAMPLING
508  if (idti>-1) {
509  pSubSample = m_pResourceManager->GetTextureMan()->GetTexture(idti);
510  if (pSubSample) {
511  glid = pSubSample->GetGLId();
512  samplebuffer = new MObyte [ pSubSample->GetWidth() * pSubSample->GetHeight() * 3];
513 
514  pSubSample->GetBuffer( samplebuffer, GL_RGB, GL_UNSIGNED_BYTE );
515 
516  }
517  }
518  }
519  }
520 
521 
522 }
523 
525 
526  MODebug2->Push(moText("moEffectParticlesSimple::ReInit Face construction activated!!!!"));
527 
528  int i;
529  int j;
530  int lum = 0;
531  int lumindex = 0;
532  int contrast = 0;
533 
534  UpdateParameters();
535  //ResetTimers();
536 
537  m_pResourceManager->GetTimeMan()->ClearByObjectId( this->GetId() );
538 
539 
540  //m_ParticlesSimpleArray.Init( p_cols*p_rows, NULL );
541  //m_ParticlesSimpleArrayTmp.Init( p_cols*p_rows, NULL );
542 
543  for( i=0; i<m_cols ; i++) {
544  for( j=0; j<m_rows ; j++) {
545  moParticlesSimple* pPar = m_ParticlesSimpleArray[i+j*m_cols];
546 
547  if (pPar) {
548 
549  pPar->Pos = moVector2f( (float) i, (float) j);
550  pPar->ImageProportion = 1.0;
551  pPar->Color = moVector3f(1.0,1.0,1.0);
552  pPar->GLId2 = 0;
553 
554  if (texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH) {
555 
557  moTextureBuffer* pTexBuf = m_Config[moR(PARTICLES_FOLDERS)][MO_SELECTED][0].TextureBuffer();
558 
559  pPar->GLId = glidori;
560  pPar->GLId2 = glid;
561  //pPar->GLId2 = 0;
562 
563  pPar->TCoord2 = moVector2f( 0.0, 0.0 );
564  pPar->TSize2 = moVector2f( 1.0f, 1.0f );
565 
566  pPar->TCoord = moVector2f( (float) (i ) / (float) m_cols, (float) (j) / (float) m_rows );
567  pPar->TSize = moVector2f( 1.0f / (float) m_cols, 1.0f / (float) m_rows );
568 
570  //int x0, y0, x1, y1;
571  float lumf = 0.0;
572 
573  if (pSubSample && samplebuffer) {
574 
575  if (pSubSample->GetWidth()!=m_cols) MODebug2->Error(moText("pSubSample width doesnt match m_cols"));
576  if (pSubSample->GetHeight()!=m_rows) MODebug2->Error(moText("pSubSample height doesnt match m_rows"));
577 
578  int r = samplebuffer[ (i + j*pSubSample->GetWidth() ) *3 ];
579  int g = samplebuffer[ (i+1 + j*pSubSample->GetWidth() ) *3 ];
580  int b = samplebuffer[ (i+2 + j*pSubSample->GetWidth() ) *3 ];
581  //MODebug2->Message(moText("r:")+IntToStr(r)+moText(" g:")+IntToStr(g)+moText(" b:")+IntToStr(b));
582 
583  lum = (r+g+b)/3;
584 
585  //lum = ( + samplebuffer[ (i+1 + j*pSubSample->GetWidth() ) *3 ] + samplebuffer[ (i+2 + j*pSubSample->GetWidth() ) *3 ] ) / 3;
586  lum = ((lum & 1) << 7) | ((lum & 2) << 5) | ((lum & 4) << 3) | ((lum & 8) << 1) | ((lum & 16) >> 1) | ((lum & 32) >> 3) | ((lum & 64) >> 5) | ((lum & 128) >> 7);
587  if (lum<0) lum = 0;
588  //MODebug2->Message(moText("lum:")+IntToStr(lum));
589 
590  if (lum>=0) {
591  lum = lum*1.2;
592 
593  lumf = ( 100.0 * (float)lum ) / (float)255.0;
594  lumindex = (int) lumf;
595  if (lumindex>99) lumindex = 99;
596  //MODebug2->Push( moText("## Lum Index R G B ##") +IntToStr(lum)+IntToStr(r)+IntToStr(g)+IntToStr(b));
597 
598  } else {
599  MODebug2->Message(moText("ReInit error:## lum is negative!!! ##")+IntToStr(lum)
600  +moText("subs: w:") + IntToStr(pSubSample->GetWidth())
601  +moText("subs: h:") + IntToStr(pSubSample->GetHeight())
602  );
603  lumindex = 99;
604  }
605 
606  } else MODebug2->Push(moText("ReInit error: no texture nor samplebuffer"));
607 
608 
609  if (pTexBuf && pTextureDest && samplebuffer) {
610 
611  int nim = pTexBuf->GetImagesProcessed();
612 
613  pPar->ImageProportion = 1.0;
614 
615  if (nim>0) {
616 
617  moTextureFrames& pTextFrames(pTexBuf->GetBufferLevels( lumindex, 0 ) );
618 
619  int nc = pTextFrames.Count();
620  int irandom = -1;
621 
622  irandom = (int)( moMathf::UnitRandom() * (double)nc );
623  //irandom = 0;
624 
625  moTextureMemory* pTexMem = pTextFrames.GetRef( irandom );
626 
627  if (pTexMem) {
628  pPar->GLId = glidori;
629  pTexMem->GetReference();
630  pPar->GLId2 = pTexMem->GetGLId();
631  pPar->pTextureMemory = pTexMem;
632  if (pTexMem->GetHeight()>0) pPar->ImageProportion = (float) pTexMem->GetWidth() / (float) pTexMem->GetHeight();
633  } else {
634  #ifdef _DEBUG
635  MODebug2->Message(moText("Sample not founded: lumindex:")+IntToStr(lumindex)+moText(" irandom:")+IntToStr(irandom));
636  #endif
637  pPar->GLId = glidori;
638  pPar->GLId2 = pPar->GLId;
639  pPar->Color.X() = ((float)lum )/ 255.0f;
640  pPar->Color.Y() = ((float)lum )/ 255.0f;
641  pPar->Color.Z() = ((float)lum )/ 255.0f;
642  pPar->Color.X()*= pPar->Color.X();
643  pPar->Color.Y()*= pPar->Color.Y();
644  pPar->Color.Z()*= pPar->Color.Z();
645  }
646 
647  //MODebug2->Push( moText("creating particle: irandom:") + IntToStr(irandom) + moText(" nc:") + IntToStr(nc) + moText(" count:") + IntToStr(pTexBuf->GetImagesProcessed()) + moText(" glid:") + IntToStr(pPar->GLId) + moText(" glid2:") + IntToStr(pPar->GLId2) );
648 
649  }
650 
651  } else {
652  MODebug2->Error( moText("particles error creating texture") );
653  }
654 
655 
656  //MODebug2->Log( moText("i:") + IntToStr(i) + moText(" J:") + IntToStr(j) + moText(" lum:") + IntToStr(lum) + moText(" lumindex:") + IntToStr(lumindex) + moText(" glid:") + IntToStr(pPar->GLId) + moText(" glid2:") + IntToStr(pPar->GLId2));
657 
658  }
659 
660 
661  pPar->Size = moVector2f( m_Physics.m_EmitterSize.X() / (float) m_cols, m_Physics.m_EmitterSize.Y() / (float) m_rows );
662  pPar->Force = moVector3f( 0.0f, 0.0f, 0.0f );
663 
664  SetParticlePosition( pPar );
665 
666  if (m_Physics.m_EmitionPeriod>0) {
667  pPar->Age.Stop();
668  pPar->Visible = false;
669  } else {
670  pPar->Age.Stop();
671  pPar->Age.Start();
672  pPar->Visible = true;
673  }
674 
676  pPar->Age.SetObjectId( this->GetId() );
677  pPar->Age.SetTimerId( i + j*m_cols );
678  m_pResourceManager->GetTimeMan()->AddTimer( &pPar->Age );
679 
680  m_ParticlesSimpleArray.Set( i + j*m_cols, pPar );
681 
682  moParticlesSimple* pParTmp = m_ParticlesSimpleArrayTmp[i + j*m_cols];
683  pParTmp->Pos3d = pPar->Pos3d;
684  pParTmp->Velocity = pPar->Velocity;
685  pParTmp->Mass = pPar->Mass;
686  pParTmp->Force = pPar->Force;
687  pParTmp->Fixed = pPar->Fixed;
688  m_ParticlesSimpleArrayTmp.Set( i + j*m_cols, pParTmp );
689 /*
690  MODebug2->Log( moText("Pos:") + IntToStr(i) + moText(" J:") + IntToStr(j) + moText(" lum:") + IntToStr(lum) + moText(" lumindex:") + IntToStr(lumindex) + moText(" glid:") + IntToStr(pPar->GLId) + moText(" glid2:") + IntToStr(pPar->GLId2));
691  MODebug2->Log( moText("X:") + FloatToStr(pPar->Pos3d.X()) + moText(" Y:") + FloatToStr(pPar->Pos3d.Y()) + moText(" Z:") + FloatToStr(pPar->Pos3d.Z()) );
692  MODebug2->Log( moText("VX:") + FloatToStr(pPar->Velocity.X()) + moText(" VY:") + FloatToStr(pPar->Velocity.Y()) + moText(" VZ:") + FloatToStr(pPar->Velocity.Z()) );
693  MODebug2->Log( moText("FX:") + FloatToStr(pPar->Force.X()) + moText(" FY:") + FloatToStr(pPar->Force.Y()) + moText(" FZ:") + FloatToStr(pPar->Force.Z()) );
694  MODebug2->Log( moText("Size X:") + FloatToStr(pPar->Size.X()) + moText(" Size Y:") + FloatToStr(pPar->Size.Y()) );
695  MODebug2->Log( moText("TCoord X:") + FloatToStr(pPar->TCoord.X()) + moText(" TCoord Y:") + FloatToStr(pPar->TCoord.Y()) );
696  MODebug2->Log( moText("TCoord2 X:") + FloatToStr(pPar->TCoord2.X()) + moText(" TCoord2 Y:") + FloatToStr(pPar->TCoord2.Y()) );
697  MODebug2->Log( moText("Visible:") + IntToStr((int)pPar->Visible) );
698  MODebug2->Log( moText("Age:") + IntToStr((int)pPar->Age.Duration()) );
699  */
700 
701  } else MODebug2->Error(moText("ParticleSimple::ReInit::no particle pointer"));
702  }
703  }
704 
705  //TrackParticle(1);
706 
707 }
708 
709 void moEffectParticlesSimple::UpdateDt() {
710 
713  //double dt = m_Config.Eval( moR(PARTICLES_SYNC),m_EffectState.tempo.ang) * (double)(m_EffectState.tempo.delta) / (double)100.0;
714 
715 
724  //
725 /*
726  dtrel = (double) ( gral_ticks - last_tick ) / (double)16.666666;
727  //if ( ( (last_tick/100) % 50 ) == 0 ) MODebug2->Push("dtrel:"+FloatToStr(dtrel));
728  dt = m_Config.Eval( moR(PARTICLES_SYNC),m_EffectState.tempo.ang) * dtrel * (double)(m_EffectState.tempo.delta) / (double)100.0;
729 
730  if ( ( (last_tick/100) % 50 ) == 0 ) MODebug2->Push("dt:"+FloatToStr(dt));
731 
732  last_tick = gral_ticks;
733  */
736  dtrel = (double) ( m_EffectState.tempo.ticks - last_tick ) / (double)16.666666;
737 
738  //if ( ( (last_tick/100) % 50 ) == 0 ) MODebug2->Push("dtrel:"+FloatToStr(dtrel));
739 
740  dt = m_Config.Eval( moR(PARTICLES_SYNC)) * dtrel * (double)(m_EffectState.tempo.delta) / (double)100.0;
741 
742  last_tick = m_EffectState.tempo.ticks;
743 
744 }
745 
746 void moEffectParticlesSimple::UpdateParameters() {
747 
748 
749  this->UpdateDt(); // now in ::Update()
750 
751  time_tofull_restoration = m_Config.Int( moR(PARTICLES_TIMETORESTORATION) );
752  time_of_restoration = m_Config.Int( moR(PARTICLES_TIMEOFRESTORATION) );
753 
754  time_tofull_revelation = m_Config.Int( moR(PARTICLES_TIMETOREVELATION));
755  time_of_revelation = m_Config.Int( moR(PARTICLES_TIMEOFREVELATION) );
756 
757  ortho = (bool) m_Config.Int( moR(PARTICLES_ORTHO) );
758 
759  if ( moIsTimerStopped() || !m_EffectState.tempo.Started() ) {
760  ResetTimers();
761  //MODebug2->Message("moEffectParticlesSimple::UpdateParameters > ResetTimers!!!");
762  }
763 
764  //if script is modified... recompile
765  if ((moText)m_Physics.m_ParticleScript!=m_Config.Text( moR(PARTICLES_SCRIPT2) ) ) {
766 
767  m_Physics.m_ParticleScript = m_Config.Text( moR(PARTICLES_SCRIPT2) );
768  moText fullscript = m_pResourceManager->GetDataMan()->GetDataPath()+ moSlash + (moText)m_Physics.m_ParticleScript;
769 
770  if ( CompileFile(fullscript) ) {
771 
772  MODebug2->Message(moText("ParticlesSimple script loaded ") + (moText)fullscript );
773 
774  SelectScriptFunction( "Init" );
775  //AddFunctionParam( m_FramesPerSecond );
776  RunSelectedFunction();
777 
778  } else MODebug2->Error(moText("ParticlesSimple couldnt compile lua script ") + (moText)fullscript );
779  }
780 
781  if (moScript::IsInitialized()) {
782  if (ScriptHasFunction("RunSystem")) {
783  SelectScriptFunction("RunSystem");
784  //passing number of particles
785  AddFunctionParam( (int) ( m_rows*m_cols ) );
786  AddFunctionParam( (float) dt );
787  RunSelectedFunction(1);
788  }
789  }
790 
791  drawing_features = m_Config.Int( moR(PARTICLES_DRAWINGFEATURES));
792  texture_mode = m_Config.Int( moR(PARTICLES_TEXTUREMODE));
793 
794  m_Physics.m_EyeVector = moVector3f(
795  m_Config.Eval( moR(PARTICLES_EYEX)),
796  m_Config.Eval( moR(PARTICLES_EYEY)),
797  m_Config.Eval( moR(PARTICLES_EYEZ))
798  );
799 
800 
801  m_Physics.gravitational = m_Config.Eval( moR(PARTICLES_GRAVITY));
802  m_Physics.viscousdrag = m_Config.Eval( moR(PARTICLES_VISCOSITY));
803 
804 
805  /*
806  m_Physics.m_MaxAge = (int)((float)(m_Config[moR(PARTICLES_MAXAGE)][MO_SELECTED][0].Int()) * midi_maxage);
807  m_Physics.m_EmitionPeriod = (int)((float)(m_Config[moR(PARTICLES_EMITIONPERIOD)][MO_SELECTED][0].Int()) * midi_emitionperiod);
808  m_Physics.m_EmitionRate = (int)((float)(m_Config[moR(PARTICLES_EMITIONRATE)][MO_SELECTED][0].Int()) * midi_emitionrate);
809  m_Physics.m_DeathPeriod = m_Config[moR(PARTICLES_DEATHPERIOD)][MO_SELECTED][0].Float();
810 */
811 
812  //emiper = (float)m_Config[moR(PARTICLES_EMITIONPERIOD)][MO_SELECTED][0].Int();
813  //emiper = emiper * midi_emitionperiod;
814  //emiperi = (long) emiper;
815  //MODebug2->Message(moText("Emiper:")+IntToStr(emiperi));
816 
817  //m_Physics.m_MaxAge = m_Config.Int( moR(PARTICLES_MAXAGE) );
818  m_Physics.m_MaxAge = (long) m_Config.Eval( moR(PARTICLES_MAXAGE) );
819  //m_Physics.m_EmitionPeriod = emiperi;
820  //emiperi = m_Config[moR(PARTICLES_EMITIONPERIOD)][MO_SELECTED][0].Int() * midi_emitionperiod;
821  //m_Physics.m_EmitionPeriod = emiperi;
822  m_Physics.m_EmitionPeriod = (long) m_Config.Eval( moR(PARTICLES_EMITIONPERIOD) );
823  //m_Physics.m_EmitionPeriod = m_Config[moR(PARTICLES_EMITIONPERIOD)][MO_SELECTED][0].Int();
824  //MODebug2->Message(moText("Emiperiod:")+IntToStr(m_Physics.m_EmitionPeriod));
825 
826  //m_Physics.m_EmitionRate = m_Config.Int( moR(PARTICLES_EMITIONRATE) );
827  m_Physics.m_EmitionRate = (long) m_Config.Eval( moR(PARTICLES_EMITIONRATE) );
828  m_Physics.m_DeathPeriod = m_Config.Int( moR(PARTICLES_DEATHPERIOD) );
829 
830 
831  m_Physics.m_RandomMethod = (moParticlesRandomMethod) m_Config.Int( moR(PARTICLES_RANDOMMETHOD) );
832  m_Physics.m_CreationMethod = (moParticlesCreationMethod) m_Config.Int( moR(PARTICLES_CREATIONMETHOD) );
833 
835 
836  m_Physics.m_FadeIn = m_Config.Eval( moR(PARTICLES_FADEIN));
837  m_Physics.m_FadeOut = m_Config.Eval( moR(PARTICLES_FADEOUT));
838  m_Physics.m_SizeIn = m_Config.Eval( moR(PARTICLES_SIZEIN));
839  m_Physics.m_SizeOut = m_Config.Eval( moR(PARTICLES_SIZEOUT));
840 
841 
842  /*
843  m_Physics.m_RandomPosition = m_Config[moR(PARTICLES_RANDOMPOSITION)].GetData()->Fun()->Eval(m_EffectState.tempo.ang);
844  m_Physics.m_RandomVelocity = m_Config[moR(PARTICLES_RANDOMVELOCITY)].GetData()->Fun()->Eval(m_EffectState.tempo.ang) * midi_randomvelocity;
845  m_Physics.m_RandomMotion = m_Config[moR(PARTICLES_RANDOMMOTION)].GetData()->Fun()->Eval(m_EffectState.tempo.ang) * midi_randommotion;
846  */
847  m_Physics.m_RandomPosition = m_Config.Eval( moR(PARTICLES_RANDOMPOSITION));
848  m_Physics.m_RandomVelocity = m_Config.Eval( moR(PARTICLES_RANDOMVELOCITY));
849  m_Physics.m_RandomMotion = m_Config.Eval( moR(PARTICLES_RANDOMMOTION));
850 
851 
852  m_Physics.m_EmitterType = (moParticlesSimpleEmitterType) m_Config.Int( moR(PARTICLES_EMITTERTYPE));
854 
855  m_Physics.m_PositionVector = moVector3f(m_Config.Eval( moR(PARTICLES_RANDOMPOSITION_X)),
856  m_Config.Eval( moR(PARTICLES_RANDOMPOSITION_Y)),
857  m_Config.Eval( moR(PARTICLES_RANDOMPOSITION_Z)) );
858 
859  m_Physics.m_EmitterSize = moVector3f( m_Config.Eval( moR(PARTICLES_SIZEX)),
860  m_Config.Eval( moR(PARTICLES_SIZEY)),
861  m_Config.Eval( moR(PARTICLES_SIZEZ)));
862 
863  m_Physics.m_VelocityVector = moVector3f( m_Config.Eval( moR(PARTICLES_RANDOMVELOCITY_X)),
864  m_Config.Eval( moR(PARTICLES_RANDOMVELOCITY_Y)),
865  m_Config.Eval( moR(PARTICLES_RANDOMVELOCITY_Z)));
866 
867  m_Physics.m_MotionVector = moVector3f( m_Config.Eval( moR(PARTICLES_RANDOMMOTION_X)),
868  m_Config.Eval( moR(PARTICLES_RANDOMMOTION_Y)),
869  m_Config.Eval( moR(PARTICLES_RANDOMMOTION_Z)));
870 
871  m_Physics.m_EmitterVector = moVector3f( m_Config.Eval( moR(PARTICLES_EMITTERVECTOR_X)),
872  m_Config.Eval( moR(PARTICLES_EMITTERVECTOR_Y)),
873  m_Config.Eval( moR(PARTICLES_EMITTERVECTOR_Z)));
874 
875  if (m_bTrackerInit && m_Physics.m_EmitterType==PARTICLES_EMITTERTYPE_TRACKER2) {
876  m_Physics.m_EmitterVector = moVector3f( m_TrackerBarycenter.X()*normalf, m_TrackerBarycenter.Y()*normalf, 0.0f );
877  }
878 
880  m_Physics.m_AttractorVector = moVector3f( m_Config.Eval( moR(PARTICLES_ATTRACTORVECTOR_X)),
881  m_Config.Eval( moR(PARTICLES_ATTRACTORVECTOR_Y)),
882  m_Config.Eval( moR(PARTICLES_ATTRACTORVECTOR_Z)));
883 
884  if (original_proportion!=1.0f) {
885  if (original_proportion>1.0f) {
886  m_Physics.m_AttractorVector.Y() = m_Physics.m_AttractorVector.Y() / original_proportion;
887  } else {
888  m_Physics.m_AttractorVector.X() = m_Physics.m_AttractorVector.X() * original_proportion;
889  }
890  }
891 
892  normalf = m_Physics.m_EmitterSize.X();
893 }
894 
895 void moEffectParticlesSimple::SetParticlePosition( moParticlesSimple* pParticle ) {
896 
897  float left = - (m_Physics.m_EmitterSize.X()) / 2.0;
898  float top = m_Physics.m_EmitterSize.Y() / 2.0;
899  float randomvelx = 0;
900  float randomvely = 0;
901  float randomvelz = 0;
902  float randomposx = 0;
903  float randomposy = 0;
904  float randomposz = 0;
905  double alpha;
906  double phi;
907  double radius;
908  double z;
909  double radius1;
910  double radius2;
911 
912  double len=0,index=0,index_normal=0;
913 
914  randomposx = ( fabs(m_Physics.m_RandomPosition) >0.0)? (0.5-moMathf::UnitRandom())*m_Physics.m_RandomPosition*m_Physics.m_PositionVector.X() : m_Physics.m_PositionVector.X();
915  randomposy = ( fabs(m_Physics.m_RandomPosition) >0.0)? (0.5-moMathf::UnitRandom())*m_Physics.m_RandomPosition*m_Physics.m_PositionVector.Y() : m_Physics.m_PositionVector.Y();
916  randomposz = ( fabs(m_Physics.m_RandomPosition) >0.0)? (0.5-moMathf::UnitRandom())*m_Physics.m_RandomPosition*m_Physics.m_PositionVector.Z() : m_Physics.m_PositionVector.Z();
917 
918  randomvelx = ( fabs(m_Physics.m_RandomVelocity) >0.0)? (moMathf::UnitRandom())*m_Physics.m_RandomVelocity*m_Physics.m_VelocityVector.X() : m_Physics.m_VelocityVector.X();
919  randomvely = ( fabs(m_Physics.m_RandomVelocity) >0.0)? (moMathf::UnitRandom())*m_Physics.m_RandomVelocity*m_Physics.m_VelocityVector.Y() : m_Physics.m_VelocityVector.Y();
920  randomvelz = ( fabs(m_Physics.m_RandomVelocity) >0.0)? (moMathf::UnitRandom())*m_Physics.m_RandomVelocity*m_Physics.m_VelocityVector.Z() : m_Physics.m_VelocityVector.Z();
921 
922  moVector4d fullcolor;
923  fullcolor = m_Config.EvalColor( moR(PARTICLES_PARTICLECOLOR));
924  pParticle->Color = moVector3f(
925  fullcolor.X(),
926  fullcolor.Y(),
927  fullcolor.Z() );
928 
929  pParticle->Mass = 10.0f;
930  pParticle->Fixed = false;
931 
932  pParticle->U = moVector3f( 1.0, 0.0, 0.0 );
933  pParticle->V = moVector3f( 0.0, 1.0, 0.0 );
934  pParticle->W = moVector3f( 0.0, 0.0, 1.0 );
935 
936  pParticle->dpdt = moVector3f( 0.0f, 0.0f, 0.0f );
937  pParticle->dvdt = moVector3f( 0.0f, 0.0f, 0.0f );
938 
939  if (m_Physics.m_FadeIn>0.0) pParticle->Alpha = 0.0;
940  else pParticle->Alpha = fullcolor.W();
941 
942  if (m_Physics.m_SizeIn>0.0) pParticle->Scale = 0.0;
943  else pParticle->Scale = 1.0;
944 
945  switch(m_Physics.m_EmitterType) {
946 
948  //GRID POSITION
949  switch(m_Physics.m_CreationMethod) {
951  pParticle->Pos3d = moVector3f( ( left + pParticle->Pos.X()*pParticle->Size.X() + pParticle->Size.X()*randomposx/2.0 )*m_Physics.m_EmitterVector.X() ,
952  ( top - pParticle->Pos.Y()*pParticle->Size.Y() - pParticle->Size.Y()*randomposy/2.0 )*m_Physics.m_EmitterVector.Y(),
953  randomposz*m_Physics.m_EmitterVector.Z() );
954  pParticle->Velocity = moVector3f( randomvelx,
955  randomvely,
956  randomvelz );
957  break;
958 
961  pParticle->Pos3d = moVector3f( ( left + moMathf::UnitRandom()*m_Physics.m_EmitterSize.X() + pParticle->Size.X()*randomposx/2.0 )*m_Physics.m_EmitterVector.X() ,
962  ( top - moMathf::UnitRandom()*m_Physics.m_EmitterSize.Y() - pParticle->Size.Y()*randomposy/2.0 )*m_Physics.m_EmitterVector.Y(),
963  randomposz*m_Physics.m_EmitterVector.Z() );
964  pParticle->Velocity = moVector3f( randomvelx,
965  randomvely,
966  randomvelz );
967  break;
968  }
969 
970  break;
971 
973  //SPHERE POSITION
974  switch(m_Physics.m_CreationMethod) {
976  alpha = 2 * moMathf::PI * pParticle->Pos.X() / (double)m_cols;
977  phi = moMathf::PI * pParticle->Pos.Y() / (double)m_rows;
978  radius = moMathf::Sqrt( m_Physics.m_EmitterSize.X()*m_Physics.m_EmitterSize.X()+m_Physics.m_EmitterSize.Y()*m_Physics.m_EmitterSize.Y()) / 2.0;
979 
980  pParticle->Pos3d = moVector3f( (radius*moMathf::Cos(alpha)*moMathf::Sin(phi) + randomposx ) * m_Physics.m_EmitterVector.X(),
981  (radius*moMathf::Sin(alpha)*moMathf::Sin(phi) + randomposy ) * m_Physics.m_EmitterVector.Y(),
982  (radius*moMathf::Cos(phi) + randomposz ) * m_Physics.m_EmitterVector.Z() );
983 
984  pParticle->Velocity = moVector3f( randomvelx,
985  randomvely,
986  randomvelz );
987  break;
988 
990  alpha = 2 * (moMathf::PI) * moMathf::UnitRandom();
991  phi = moMathf::PI * moMathf::UnitRandom();
992  radius = moMathf::Sqrt( m_Physics.m_EmitterSize.X()*m_Physics.m_EmitterSize.X()+m_Physics.m_EmitterSize.Y()*m_Physics.m_EmitterSize.Y()) / 2.0;
993  pParticle->Pos3d = moVector3f(
994  (radius*moMathf::Cos(alpha)*moMathf::Sin(phi) + randomposx)* m_Physics.m_EmitterVector.X(),
995  (radius*moMathf::Sin(alpha)*moMathf::Sin(phi) + randomposy)* m_Physics.m_EmitterVector.Y(),
996  (radius*moMathf::Cos(phi) + randomposz)* m_Physics.m_EmitterVector.Z()
997  );
998  pParticle->Velocity = moVector3f( randomvelx,
999  randomvely,
1000  randomvelz );
1001  break;
1002 
1004  alpha = 2 * moMathf::PI * moMathf::UnitRandom();
1005  phi = moMathf::PI * moMathf::UnitRandom();
1006  radius = moMathf::Sqrt( m_Physics.m_EmitterSize.X()*m_Physics.m_EmitterSize.X()+m_Physics.m_EmitterSize.Y()*m_Physics.m_EmitterSize.Y())*moMathf::UnitRandom() / 2.0;
1007 
1008  pParticle->Pos3d = moVector3f( (radius*moMathf::Cos(alpha)*moMathf::Sin(phi) + randomposx ) * m_Physics.m_EmitterVector.X(),
1009  (radius*moMathf::Sin(alpha)*moMathf::Sin(phi) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1010  (radius*moMathf::Cos(phi) + randomposz ) * m_Physics.m_EmitterVector.Z() );
1011 
1012  pParticle->Velocity = moVector3f( randomvelx,
1013  randomvely,
1014  randomvelz );
1015  break;
1016  }
1017  break;
1018 
1020  //SPHERE POSITION
1021  switch(m_Physics.m_CreationMethod) {
1023  alpha = 2 * moMathf::PI * pParticle->Pos.X() / (double)m_cols;
1024  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1025  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1026  z = m_Physics.m_EmitterSize.Z() * ( 0.5f - ( pParticle->Pos.Y() / (double)m_rows ) );
1027 
1028  pParticle->Pos3d = moVector3f( ( radius1*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1029  ( radius1*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1030  ( z + randomposz ) * m_Physics.m_EmitterVector.Z() );
1031 
1032  pParticle->Velocity = moVector3f( randomvelx,
1033  randomvely,
1034  randomvelz );
1035  break;
1036 
1038  alpha = 2 * moMathf::PI * moMathf::UnitRandom();
1039  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1040  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1041  z = m_Physics.m_EmitterSize.Z() * ( 0.5f - moMathf::UnitRandom());
1042 
1043  pParticle->Pos3d = moVector3f( ( radius1*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1044  ( radius1*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1045  ( z + randomposz ) * m_Physics.m_EmitterVector.Z() );
1046 
1047  pParticle->Velocity = moVector3f( randomvelx,
1048  randomvely,
1049  randomvelz );
1050  break;
1051 
1053  alpha = 2 * moMathf::PI * moMathf::UnitRandom();
1054  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1055  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1056  radius = radius1 + moMathf::UnitRandom()*(radius2-radius1)*moMathf::UnitRandom();
1057  z = m_Physics.m_EmitterSize.Z() * ( 0.5f - moMathf::UnitRandom());
1058 
1059  pParticle->Pos3d = moVector3f( ( radius*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1060  ( radius*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1061  ( z + randomposz ) * m_Physics.m_EmitterVector.Z() );
1062 
1063  pParticle->Velocity = moVector3f( randomvelx,
1064  randomvely,
1065  randomvelz );
1066  break;
1067  }
1068  break;
1069 
1071  //SPHERE POSITION
1072  switch(m_Physics.m_CreationMethod) {
1074 
1075  //z = m_Physics.m_EmitterSize.Z() * moMathf::UnitRandom();
1076  len = m_Physics.m_EmitterVector.Length();
1077  index = pParticle->Pos.X()+pParticle->Pos.Y()*(double)m_cols;
1078  index_normal = 0.0;
1079 
1080  if (m_cols*m_rows) {
1081  index_normal = index / (double)(m_cols*m_rows);
1082  }
1083  z = index_normal;
1084 
1085  pParticle->Pos3d = moVector3f( m_Physics.m_EmitterVector.X()*( z + randomposx ),
1086  m_Physics.m_EmitterVector.Y()*( z + randomposy ),
1087  m_Physics.m_EmitterVector.Z()*( z + randomposz) );
1088 
1089  pParticle->Velocity = moVector3f( randomvelx,
1090  randomvely,
1091  randomvelz);
1092  break;
1095  z = m_Physics.m_EmitterSize.Z() * moMathf::UnitRandom();
1096 
1097  pParticle->Pos3d = moVector3f( m_Physics.m_EmitterVector.X()*( z + randomposx ),
1098  m_Physics.m_EmitterVector.Y()*( z + randomposy ),
1099  m_Physics.m_EmitterVector.Z()*( z + randomposz) );
1100 
1101  pParticle->Velocity = moVector3f( randomvelx,
1102  randomvely,
1103  randomvelz);
1104  break;
1105 
1106  }
1107  break;
1108 
1110  //SPHERE POSITION
1111  pParticle->Pos3d = moVector3f( randomposx+m_Physics.m_EmitterVector.X(),
1112  randomposy+m_Physics.m_EmitterVector.Y(),
1113  randomposz+m_Physics.m_EmitterVector.Z() );
1114 
1115  pParticle->Velocity = moVector3f( randomvelx,
1116  randomvely,
1117  randomvelz);
1118 
1119  break;
1121  //SPIRAL POSITION
1122  switch(m_Physics.m_CreationMethod) {
1126  alpha = 2 * moMathf::PI * pParticle->Pos.X() / (double)m_cols;
1127  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1128  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1129  z = m_Physics.m_EmitterSize.Z() * ( 0.5f - ( pParticle->Pos.Y() / (double)m_rows ) - (pParticle->Pos.X() / (double)(m_cols*m_rows)) );
1130 
1131  pParticle->Pos3d = moVector3f( ( radius1*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1132  ( radius1*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1133  ( z + randomposz ) * m_Physics.m_EmitterVector.Z() );
1134 
1135  pParticle->Velocity = moVector3f( randomvelx,
1136  randomvely,
1137  randomvelz );
1138  break;
1139  }
1140  break;
1142  //CIRCLE POSITION
1143  switch(m_Physics.m_CreationMethod) {
1145  alpha = 2 * moMathf::PI * ( pParticle->Pos.X() + pParticle->Pos.Y()*m_rows ) / ((double)m_cols*(double)m_rows );
1146  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1147  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1148  z = 0.0;
1149  //z = m_Physics.m_EmitterSize.Z() * ( 0.5f - ( pParticle->Pos.Y() / (double)m_rows ) - (pParticle->Pos.X() / (double)(m_cols*m_rows)) );
1150 
1151  pParticle->Pos3d = moVector3f( ( radius1*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1152  ( radius1*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1153  ( z + randomposz ) );
1154 
1155  pParticle->Velocity = moVector3f( randomvelx,
1156  randomvely,
1157  randomvelz );
1158  break;
1161  alpha = 2 * moMathf::PI * ( pParticle->Pos.X()*m_rows + pParticle->Pos.Y()) / ((double)m_cols*(double)m_rows );
1162  radius1 = m_Physics.m_EmitterSize.X() / 2.0;
1163  radius2 = m_Physics.m_EmitterSize.Y() / 2.0;
1164  z = 0.0;
1165  //z = m_Physics.m_EmitterSize.Z() * ( 0.5f - ( pParticle->Pos.Y() / (double)m_rows ) - (pParticle->Pos.X() / (double)(m_cols*m_rows)) );
1166  randomposx = randomposx + (radius1-radius2)*moMathf::Cos(alpha);
1167  randomposy = randomposy + (radius1-radius2)*moMathf::Sin(alpha);
1168  pParticle->Pos3d = moVector3f( ( radius1*moMathf::Cos(alpha) + randomposx ) * m_Physics.m_EmitterVector.X(),
1169  ( radius1*moMathf::Sin(alpha) + randomposy ) * m_Physics.m_EmitterVector.Y(),
1170  ( z + randomposz ) );
1171 
1172  pParticle->Velocity = moVector3f( randomvelx,
1173  randomvely,
1174  randomvelz );
1175  break;
1176  }
1177  break;
1178 
1180  switch(m_Physics.m_CreationMethod) {
1182  if (m_pTrackerData) {
1183  pParticle->Pos3d = moVector3f( (m_pTrackerData->GetBarycenter().X() - 0.5)*normalf, (-m_pTrackerData->GetBarycenter().Y()+0.5)*normalf, 0.0 );
1184  pParticle->Pos3d+= moVector3f( randomposx, randomposy, randomposz );
1185  pParticle->Velocity = moVector3f( randomvelx, randomvely, randomvelz );
1186  }
1187  break;
1188 
1192 
1193 
1194 
1195  if (m_pTrackerData) {
1196  bool bfounded = false;
1197  int np = (int) ( moMathf::UnitRandom() * m_pTrackerData->GetFeaturesCount() );
1198 
1199  moTrackerFeature *pTF = NULL;
1200 
1201  pTF = m_pTrackerData->GetFeature( np );
1202  if (pTF->valid) {
1203  pParticle->Pos3d = moVector3f( (pTF->x - 0.5)*normalf, (-pTF->y+0.5)*normalf, 0.0 );
1204  bfounded = true;
1205  }
1206 
1207  np = 0;
1208  //como no encontro un feature valido para usar de generador arranca desde el primero....
1209  //error, deberia tomar el baricentro.... o tomar al azar otro...
1210  /*
1211  if (!bfounded) {
1212  pParticle->Pos3d = moVector3f( (m_pTrackerData->GetBarycenter().X() - 0.5)*normalf, (-m_pTrackerData->GetBarycenter().Y()+0.5)*normalf, 0.0 );
1213  }*/
1214  int cn=0;
1215  if (!bfounded) {
1216  do {
1217  pTF = m_pTrackerData->GetFeature( np );
1218  if (pTF->valid) {
1219  pParticle->Pos3d = moVector3f( (pTF->x - 0.5)*normalf, (-pTF->y+0.5)*normalf, 0.0 );
1220  bfounded = true;
1221  }
1222  np = (int) ( moMathf::UnitRandom() * m_pTrackerData->GetFeaturesCount() );
1223  cn++;
1224  } while (!pTF->valid && np < m_pTrackerData->GetFeaturesCount() && cn<5 );
1225  if (!bfounded) pParticle->Pos3d = moVector3f( (m_pTrackerData->GetBarycenter().X() - 0.5)*normalf, (-m_pTrackerData->GetBarycenter().Y()+0.5)*normalf, 0.0 );
1226  }
1227 
1228 
1229  } else {
1230  pParticle->Pos3d = moVector3f( 0, 0, 0 );
1231  }
1232 
1233  pParticle->Pos3d+= moVector3f( randomposx, randomposy, randomposz );
1234 
1235  pParticle->Velocity = moVector3f( randomvelx,
1236  randomvely,
1237  randomvelz);
1238  break;
1239 
1240  }
1241  break;
1242  };
1243 
1244 
1245 }
1246 
1247 void moEffectParticlesSimple::InitParticlesSimple( int p_cols, int p_rows, bool p_forced ) {
1248 
1249  int i,j;
1250 
1251  bool m_bNewImage = false;
1252 
1253 
1254  if (texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH) {
1255  Shot();
1256  }
1257 
1258  if (m_pResourceManager){
1259  if (m_pResourceManager->GetTimeMan()) {
1260  m_pResourceManager->GetTimeMan()->ClearByObjectId( this->GetId() );
1261  }
1262  }
1263 
1264  //if (p_cols==m_cols && p_rows==m_rows && !forced) {
1265 
1266  if (m_ParticlesSimpleArray.Count()>0) {
1267  /*for(i=0;i<m_ParticlesSimpleArray.Count();i++) {
1268  if (m_ParticlesSimpleArray[i]!=NULL) {
1269  delete m_ParticlesSimpleArray[i];
1270  //m_ParticlesSimple.Set(i, NULL);
1271  }
1272  }
1273  */
1274  m_ParticlesSimpleArray.Empty();
1275  }
1276 
1277  if (m_ParticlesSimpleArrayTmp.Count()>0) {
1278  /*for(i=0;i<m_ParticlesSimpleArrayTmp.Count();i++) {
1279  if (m_ParticlesSimpleArrayTmp[i]!=NULL) {
1280  delete m_ParticlesSimpleArrayTmp[i];
1281  //m_ParticlesSimple.Set(i, NULL);
1282  }
1283  }
1284  */
1285  m_ParticlesSimpleArrayTmp.Empty();
1286  }
1287  //}
1288 
1289  m_ParticlesSimpleArray.Init( p_cols*p_rows, NULL );
1290  m_ParticlesSimpleArrayTmp.Init( p_cols*p_rows, NULL );
1291 
1292 
1293  for( j=0; j<p_rows ; j++) {
1294  for( i=0; i<p_cols ; i++) {
1295 
1296  moParticlesSimple* pPar = new moParticlesSimple();
1297 
1298  pPar->Pos = moVector2f( (float) i, (float) j);
1299  pPar->ImageProportion = 1.0;
1300  //pPar->Color = moVector3f(1.0,1.0,1.0);
1301  moVector4d fullcolor;
1302  fullcolor = m_Config.EvalColor( moR(PARTICLES_PARTICLECOLOR));
1303  pPar->Color = moVector3f(
1304  fullcolor.X(),
1305  fullcolor.Y(),
1306  fullcolor.Z() );
1307  pPar->GLId2 = 0;
1308 
1309  if (texture_mode==PARTICLES_TEXTUREMODE_UNIT) {
1310 
1311  pPar->TCoord = moVector2f( 0.0, 0.0 );
1312  pPar->TSize = moVector2f( 1.0f, 1.0f );
1313 
1314  } else if (texture_mode==PARTICLES_TEXTUREMODE_PATCH) {
1315 
1316  pPar->TCoord = moVector2f( (float) (i) / (float) p_cols, (float) (j) / (float) p_rows );
1317  pPar->TSize = moVector2f( 1.0f / (float) p_cols, 1.0f / (float) p_rows );
1318 
1319  } else if (texture_mode==PARTICLES_TEXTUREMODE_MANY ) {
1320 
1321  pPar->TCoord = moVector2f( 0.0, 0.0 );
1322  pPar->TSize = moVector2f( 1.0f, 1.0f );
1323 
1324  } else if (texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH) {
1325 
1327  moTextureBuffer* pTexBuf = m_Config[moR(PARTICLES_FOLDERS)][MO_SELECTED][0].TextureBuffer();
1328 
1329  pPar->GLId = glidori; //first id for Image reference to patch (and blend after)
1330  pPar->GLId2 = glid; //second id for each patch image
1331 
1332  pPar->TCoord2 = moVector2f( 0.0, 0.0 ); //coords for patch
1333  pPar->TSize2 = moVector2f( 1.0f, 1.0f );
1334 
1335  pPar->TCoord = moVector2f( (float) (i ) / (float) p_cols, (float) (j) / (float) p_rows );//grid
1336  pPar->TSize = moVector2f( 1.0f / (float) p_cols, 1.0f / (float) p_rows );//sizes
1337 
1339  //int x0, y0, x1, y1;
1340  int lum = 0;
1341  int lumindex = 0;
1342  int contrast = 0;
1343 
1345  if (pSubSample && samplebuffer) {
1346 
1347  lum = (samplebuffer[ (i + j*pSubSample->GetWidth() ) *3 ]
1348  + samplebuffer[ (i+1 + j*pSubSample->GetWidth() ) *3 ]
1349  + samplebuffer[ (i+2 + j*pSubSample->GetWidth() ) *3 ]) / 3;
1350 
1351  if (lum<0) lum = -lum;
1353  if (lum>=0) {
1354  lumindex = (int)( 100.0 * (float)lum / (float)256) - 1;
1355  if (lumindex>99) lumindex = 99;
1356  }
1357  } else {
1358  MODebug2->Message(moText("pSubSample: ")+IntToStr((long)pSubSample) +
1359  moText("samplebuffer: ")+IntToStr((long)samplebuffer));
1360  }
1361 
1362  if (pTexBuf) {
1363 
1365  int nim = pTexBuf->GetImagesProcessed();
1366 
1367  pPar->ImageProportion = 1.0;
1368 
1369 
1370  if (nim>0) {
1371 
1373 
1374  moTextureFrames& pTextFrames(pTexBuf->GetBufferLevels( lumindex, 0 ) );
1375 
1376  int nc = pTextFrames.Count();
1377  int irandom = -1;
1378 
1379  irandom = (int)( moMathf::UnitRandom() * (double)nc );
1380 
1381  moTextureMemory* pTexMem = pTextFrames.GetRef( irandom );
1382 
1383  if (pTexMem) {
1384  pPar->GLId = glidori;
1385  pTexMem->GetReference();
1386  pPar->GLId2 = pTexMem->GetGLId();
1387  pPar->pTextureMemory = pTexMem;
1388  if (pTexMem->GetHeight()>0) pPar->ImageProportion = (float) pTexMem->GetWidth() / (float) pTexMem->GetHeight();
1389  } else {
1390  pPar->GLId = glidori;
1391  pPar->GLId2 = pPar->GLId;
1392  pPar->Color.X() = ((float)lum )/ 255.0f;
1393  pPar->Color.Y() = ((float)lum )/ 255.0f;
1394  pPar->Color.Z() = ((float)lum )/ 255.0f;
1395  pPar->Color.X()*= pPar->Color.X();
1396  pPar->Color.Y()*= pPar->Color.Y();
1397  pPar->Color.Z()*= pPar->Color.Z();
1398  }
1399  //MODebug2->Push( moText("creating particle: irandom:") + IntToStr(irandom) + moText(" count:") + IntToStr(pTexBuf->GetImagesProcessed()) + moText(" glid:") + IntToStr(pPar->GLId) );
1400 
1401  }
1402 
1403  } else MODebug2->Error( moText("particles error creating texture") );
1404 
1405  }
1406 
1407  pPar->Size = moVector2f( m_Physics.m_EmitterSize.X() / (float) p_cols, m_Physics.m_EmitterSize.Y() / (float) p_rows );
1408  pPar->Force = moVector3f( 0.0f, 0.0f, 0.0f );
1409 
1410  SetParticlePosition( pPar );
1411 
1412  /*
1413  MODebug2->Message("i:"+IntToStr(i) );
1414  MODebug2->Message("j:"+IntToStr(j) );
1415  MODebug2->Message("px:"+FloatToStr(pPar->Pos3d.X()) );
1416  MODebug2->Message("py:"+FloatToStr(pPar->Pos3d.Y()) );
1417  */
1418 
1419  if (m_Physics.m_EmitionPeriod>0) {
1420  pPar->Age.Stop();
1421  pPar->Visible = false;
1422  } else {
1423  pPar->Age.Start();
1424  pPar->Visible = true;
1425  }
1426 
1428  pPar->Age.SetObjectId( this->GetId() );
1429  pPar->Age.SetTimerId( i + j*p_cols );
1430  pPar->Age.SetRelativeTimer( (moTimerAbsolute*)&m_EffectState.tempo );
1431  m_pResourceManager->GetTimeMan()->AddTimer( &pPar->Age );
1432 
1433  m_ParticlesSimpleArray.Set( i + j*p_cols, pPar );
1434 
1435  moParticlesSimple* pParTmp = new moParticlesSimple();
1436  pParTmp->Pos3d = pPar->Pos3d;
1437  pParTmp->Velocity = pPar->Velocity;
1438  pParTmp->Mass = pPar->Mass;
1439  pParTmp->Force = pPar->Force;
1440  pParTmp->Fixed = pPar->Fixed;
1441  m_ParticlesSimpleArrayTmp.Set( i + j*p_cols, pParTmp );
1442 
1443  }
1444  }
1445 
1446  m_rows = p_rows;
1447  m_cols = p_cols;
1448 
1449 }
1450 
1452 void moEffectParticlesSimple::Regenerate() {
1453 
1454  int i,j;
1455  float randommotionx,randommotiony,randommotionz;
1456 
1457  long emitiontimer_duration = m_Physics.EmitionTimer.Duration();
1458  //MODebug2->Message("dur:"+IntToStr(emitiontimer_duration));
1459 
1461  if (emitiontimer_duration<0)
1462  m_Physics.EmitionTimer.Start();
1463 
1464 
1465  for( j=0; j<m_rows ; j++) {
1466  for( i=0; i<m_cols ; i++) {
1467 
1468 
1469  moParticlesSimple* pPar = m_ParticlesSimpleArray[i+j*m_cols];
1470 
1471  pPar->pTextureMemory = NULL;
1472 
1475  if (pPar->Age.Duration() > moGetTicks() ) {
1476  pPar->Age.Stop();
1477  pPar->Visible = false;
1478  pPar->MOId = -1; //reseteamos la textura asociada
1479  if (pPar->pTextureMemory) {
1480  pPar->pTextureMemory->ReleaseReference();
1481  pPar->pTextureMemory = NULL;
1482  pPar->GLId = 0;
1483  }
1484  }
1485 
1486 
1489  //if (i==3 && j==3)
1490  //MODebug2->Message("visible: " + IntToStr((int)pPar->Visible) + "on:" + IntToStr((int)pPar->Age.Started()) + " agedur:" + IntToStr(pPar->Age.Duration()));
1492  if ( pPar->Visible) {
1493  if (
1494  (
1495  (m_Physics.m_MaxAge>0) &&
1496  (pPar->Age.Duration() > m_Physics.m_MaxAge)
1497  )
1498  ||
1499  (
1500  (pPar->MaxAge>0) &&
1501  (pPar->Age.Duration() > pPar->MaxAge)
1502  )
1503  ) {
1504 
1505  pPar->Age.Stop();
1506  pPar->Visible = false;
1507  pPar->MOId = -1; //reseteamos la textura asociada
1508 
1510  if (m_Rate>0) m_Rate--;
1511 
1512  if (pPar->pTextureMemory) {
1513  pPar->pTextureMemory->ReleaseReference();
1514  pPar->pTextureMemory = NULL;
1515  pPar->GLId = 0;
1516  }
1517 
1518  }
1519  }
1520 
1522  //m_Physics.EmitionTimer.Duration()
1523  //MODebug2->Message("dur:"+IntToStr(emitiontimer_duration)+" vs:"+IntToStr(m_Physics.m_EmitionPeriod) );
1527  if ( m_Rate<m_Physics.m_EmitionRate &&
1528  (m_Physics.EmitionTimer.Duration() > m_Physics.m_EmitionPeriod)
1529  && pPar->Visible==false ) {
1530 
1531  bool letsborn = true;
1532  int id_last_particle = 0;
1533  int this_id_particle = 0;
1534 
1537  if (m_Physics.m_pLastBordParticle)
1538  id_last_particle = m_Physics.m_pLastBordParticle->Pos.X() + m_Physics.m_pLastBordParticle->Pos.Y()*m_cols;
1539  else id_last_particle = -1;
1540 
1541  this_id_particle = i+j*m_cols;
1542 
1543  if ( id_last_particle==(m_rows*m_cols-1)
1544  && this_id_particle == 0 ) {
1546  letsborn = true;
1547  } else if ( this_id_particle == (id_last_particle+1) ) {
1549  letsborn = true;
1551  } else {
1553  letsborn = false;
1555  }
1556 
1557  }
1558 
1559  //m_Physics.EmitionTimer.Start();
1560  if (letsborn) {
1561  pPar->Visible = true;
1562  pPar->Age.Start();
1563 
1564  //guardamos la referencia a esta particula, que servira para la proxima
1565  m_Physics.m_pLastBordParticle = pPar;
1566 
1568  m_Rate++;
1569 
1571  SetParticlePosition( pPar );
1572  /*
1573  MODebug2->Message("frame:"+IntToStr(frame) );
1574  MODebug2->Message("i:"+IntToStr(i) );
1575  MODebug2->Message("j:"+IntToStr(j) );
1576  MODebug2->Message("px:"+FloatToStr(pPar->Pos3d.X()) );
1577  MODebug2->Message("py:"+FloatToStr(pPar->Pos3d.Y()) );
1578  */
1579 
1580  /*
1581  if ((i+j*m_cols)%1000 == 0) {
1582  MODebug2->Push(moText("partícula en proceso - regenerando GLID ")+IntToStr(pPar->GLId)
1583  + moText(" GLID2: ") + IntToStr(pPar->GLId2) );
1584  }*/
1585 
1586  //pPar->Pos3d = moVector3f( 0, 0, 0);
1587 
1588  //regenerate
1589 
1590  //moTexture* pTex = ; //m_pResourceManager->GetTextureMan()->GetTexture();
1591 
1593  if ( texture_mode==PARTICLES_TEXTUREMODE_MANY ) {
1596  moTextureBuffer* pTexBuf = m_Config[ moR(PARTICLES_FOLDERS) ][MO_SELECTED][0].TextureBuffer();
1597  //m_Config[moR(PARTICLES_TEXTURE)].GetData()->GetGLId(&m_EffectState.tempo, 1, NULL );
1598  if (pTexBuf) {
1599  int nim = pTexBuf->GetImagesProcessed();
1600  //MODebug2->Push( "nim: " + IntToStr(nim) );
1601 
1602  pPar->ImageProportion = 1.0;
1603 
1604  if (nim>0) {
1605 
1606  float frandom = moMathf::UnitRandom() * nim;
1607 
1608  //MODebug2->Push( "frandom: " + FloatToStr(frandom) );
1609 
1610  //int irandom = ( ::rand() * nim )/ RAND_MAX;
1611  int irandom = (int)frandom;
1612  //MODebug2->Push( "irandom: " + IntToStr(irandom) + " rand: " + IntToStr(::rand()) );
1613 
1614  if (irandom>=nim) irandom = nim - 1;
1615 
1616  pPar->GLId = pTexBuf->GetFrame( irandom );
1617 
1618  moTextureMemory* pTexMem = pTexBuf->GetTexture( irandom );
1619  if (pTexMem) {
1620  pPar->pTextureMemory = pTexMem;
1621  if (pTexMem->GetHeight()>0) pPar->ImageProportion = (float) pTexMem->GetWidth() / (float) pTexMem->GetHeight();
1622  }
1623 
1625 
1626 
1627  } else {
1629  }
1630  pPar->TCoord = moVector2f( 0.0, 0.0 );
1631  pPar->TSize = moVector2f( 1.0f, 1.0f );
1632 
1633  } else MODebug2->Error( moText("PARTICLES_TEXTUREMODE_MANY particles error creating texture") );
1634  }
1635 
1636  }
1637 
1638  }
1639 
1641  if (m_Rate>=m_Physics.m_EmitionRate) {
1643  m_Physics.EmitionTimer.Start();
1644  m_Rate = 0;
1645  }
1646 
1648  if ( pPar->Visible && m_Physics.m_FadeIn>0.0) {
1650  if ( m_Physics.m_MaxAge>0 && pPar->Age.Duration() < m_Physics.m_MaxAge ) {
1652  if ( pPar->Age.Duration() < ( m_Physics.m_FadeIn * m_Physics.m_MaxAge / 2.0 ) ) {
1653 
1654  pPar->Alpha = ( 2.0 * pPar->Age.Duration() / ( m_Physics.m_FadeIn * m_Physics.m_MaxAge ) );
1655 
1656  } else pPar->Alpha = 1.0 ;
1657  } else if ( m_Physics.m_MaxAge==0) {
1659  pPar->Alpha = m_Physics.m_FadeIn * pPar->Age.Duration() / 1000.0;
1660  }
1661  }
1662 
1664  if ( pPar->Visible && m_Physics.m_FadeOut>0.0) {
1666  if ( m_Physics.m_MaxAge>0 && (pPar->Age.Duration() < m_Physics.m_MaxAge) ) {
1668  if ( (m_Physics.m_MaxAge/2.0) < pPar->Age.Duration() ) {
1669  if ( (m_Physics.m_FadeOut*m_Physics.m_MaxAge / 2.0) > (m_Physics.m_MaxAge - pPar->Age.Duration()) ) {
1670 
1671  pPar->Alpha = ( m_Physics.m_MaxAge - pPar->Age.Duration() ) / (m_Physics.m_FadeOut *m_Physics.m_MaxAge / 2.0);
1672 
1673  }
1674  }
1675  }
1676 
1677  }
1678 
1680  if ( pPar->Visible && m_Physics.m_SizeIn>0.0
1681  && (m_Physics.m_MaxAge>0) && (pPar->Age.Duration() < m_Physics.m_MaxAge) ) {
1682 
1683  if ( pPar->Age.Duration() < ( m_Physics.m_SizeIn * m_Physics.m_MaxAge / 2.0 )) {
1684 
1685  pPar->Scale = ( 2.0 * pPar->Age.Duration() / ( m_Physics.m_SizeIn * m_Physics.m_MaxAge ) );
1686 
1687  } else pPar->Scale = 1.0 ;
1688 
1689 
1690  }
1691 
1692 
1694  if ( pPar->Visible && m_Physics.m_SizeOut>0.0 && (m_Physics.m_MaxAge>0)
1695  && ( (m_Physics.m_MaxAge/2.0) < pPar->Age.Duration() ) && (pPar->Age.Duration() < m_Physics.m_MaxAge) ) {
1696 
1697  if ( (m_Physics.m_SizeOut*m_Physics.m_MaxAge / 2.0) > (m_Physics.m_MaxAge - pPar->Age.Duration()) && pPar->Age.Duration() < m_Physics.m_MaxAge ) {
1698 
1699  pPar->Scale = ( m_Physics.m_MaxAge - pPar->Age.Duration() ) / (m_Physics.m_SizeOut *m_Physics.m_MaxAge / 2.0);
1700 
1701  }
1702 
1703 
1704  }
1705 
1706  if ( pPar->Visible ) {
1707 
1708  randommotionx = (m_Physics.m_RandomMotion>0)? (0.5-moMathf::UnitRandom())*m_Physics.m_MotionVector.X() : m_Physics.m_MotionVector.X();
1709  randommotiony = (m_Physics.m_RandomMotion>0)? (0.5-moMathf::UnitRandom())*m_Physics.m_MotionVector.Y() : m_Physics.m_MotionVector.Y();
1710  randommotionz = (m_Physics.m_RandomMotion>0)? (0.5-moMathf::UnitRandom())*m_Physics.m_MotionVector.Z() : m_Physics.m_MotionVector.Z();
1711 
1712  m_Physics.m_MotionVector.Normalize();
1713  if ( m_Physics.m_MotionVector.Length() > 0.0 ) {
1714  if (m_Physics.m_RandomMotion>0.0) {
1715  pPar->Velocity+= moVector3f( randommotionx, randommotiony, randommotionz ) * m_Physics.m_RandomMotion;
1716  }
1717  }
1718 
1719  }
1720 
1721 
1722 
1723 
1724  }
1725  }
1726 }
1727 
1728 void moEffectParticlesSimple::ParticlesSimpleInfluence( float posx, float posy, float velx, float vely, float veln ) {
1729 
1730 /*
1731  float left = - normalf / 2.0;
1732  float top = normalf / 2.0;
1733  float sizex = normalf / (float) m_cols;
1734  float sizey = normalf / (float) m_rows;
1735 
1736  float If,Jf;
1737  int I,J;
1738  int II,JJ;
1739 
1740  If = (posx - left - sizex/2.0 ) / sizex;
1741  Jf = -(posy - top + sizey/2.0 ) / sizey;
1742 
1743  II = (int) If;
1744  JJ = (int) Jf;
1745 
1746 
1747  int Ileft, Iright, Jtop, Jbottom;
1748 
1749  int INFLUENZA = 2;
1750 
1751  if (0<=II && II<m_cols && 0<=JJ && JJ<m_rows) {
1752 
1753  moParticlesSimple* pPar = m_ParticlesSimpleArray.GetRef( II + JJ*m_cols );
1754 
1755  //pBal->Size[0] = pBal->Size[0] / 1.1;
1756  //pBal->Size[1] = pBal->Size[1] / 1.1;
1757 
1758  pPar->Force = moVector3f( 0.0, 0.0, 1.01f );
1759 
1760  if (INFLUENZA>0) {
1761 
1762  //influence neigbours!!! on a force radius
1763  Ileft = II - INFLUENZA;
1764  Iright = II + INFLUENZA;
1765  Jbottom = JJ - INFLUENZA;
1766  Jtop = JJ + INFLUENZA;
1767 
1768  ( Ileft > 0 ) ? Ileft = Ileft : Ileft = 0;
1769  ( Iright < m_cols ) ? Iright = Iright : Iright = m_cols;
1770  ( Jbottom > 0 ) ? Jbottom = Jbottom : Jbottom = 0;
1771  ( Jtop < m_rows ) ? Jtop = Jtop : Jtop = m_rows;
1772 
1773  for( I=Ileft; I<Iright; I++) {
1774  for( J=Jbottom; J<Jtop; J++) {
1775  m_ParticlesSimpleArray.GetRef( I + J*m_cols )->Force = moVector3f( 0.0, 0.0, 1.01f );
1776  }
1777  }
1778 
1779  }
1780 
1781 
1782  }
1783 */
1784 
1785 }
1786 
1787 void moEffectParticlesSimple::RevealingAll() {
1788 
1789  float scale = 1.0;
1790  moVector2f BSize = moVector2f( normalf / (float) m_cols, normalf / (float) m_rows );
1791 
1792  if (!TimerOfRevelation.Started() ) {
1793  TimerOfRevelation.Start();
1794  }
1795 
1796  if (TimerOfRevelation.Started() ) {
1797 
1798  if (TimerOfRevelation.Duration() < time_of_revelation ) {
1799  scale = (float)( time_of_revelation - TimerOfRevelation.Duration() ) / (float)time_of_revelation;
1800  } else {
1801  scale = 0.0;
1802  TimerOfRevelation.Stop();
1803  }
1804 
1805  for( int i=0; i<m_cols ; i++) {
1806  for(int j=0; j<m_rows ; j++) {
1807  if (m_ParticlesSimpleArray[i+j*m_cols]->Size.X() > 0.1 )
1808  m_ParticlesSimpleArray[i+j*m_cols]->Size = BSize * scale;
1809  }
1810  }
1811 
1812  }
1813 
1815  if (!TimerOfRevelation.Started() ) {
1816  revelation_status = PARTICLES_FULLREVEALED;
1817  }
1818 
1819 }
1820 
1821 void moEffectParticlesSimple::RestoringAll() {
1822 
1823  float scale = 1.0;
1824  float left = - normalf / 2.0;
1825  float top = normalf / 2.0;
1826  moVector2f BSize = moVector2f( normalf / (float) m_cols, normalf / (float) m_rows );
1827 
1828  if (!TimerOfRestoration.Started() ) {
1829  TimerOfRestoration.Start();
1830  }
1831 
1832  if (TimerOfRestoration.Started() ) {
1833 
1834  if (TimerOfRestoration.Duration() < time_of_restoration ) {
1835  scale = 1.0f - (float)( time_of_restoration - TimerOfRestoration.Duration() ) / (float)time_of_restoration;
1836  } else {
1837  scale = 1.0f;
1838  TimerOfRestoration.Stop();
1839  }
1840 
1841  for( int i=0; i<m_cols ; i++) {
1842  for(int j=0; j<m_rows ; j++) {
1843  m_ParticlesSimpleArray[i+j*m_cols]->Size = BSize * scale;
1844  m_ParticlesSimpleArray[i+j*m_cols]->Pos3d = moVector3f( left + (float)(i)*BSize.X() + BSize.X()/2.0,
1845  top - (float)(j)*BSize.Y() - BSize.Y()/2.0,
1846  0.0f );
1847  }
1848  }
1849 
1850  }
1851 
1853  if (!TimerOfRestoration.Started() ) {
1854  revelation_status = PARTICLES_FULLRESTORED;
1855  }
1856 }
1857 
1858 
1859 void moEffectParticlesSimple::CalculateForces(bool tmparray)
1860 {
1861  int i,p1,p2;
1862  //moVector3f down(1.0,1.0,-1.0);
1863  moVector3f zero(0.0,0.0,0.0);
1864  moVector3f f;
1865  moVector3f atdis;
1866  double len,dx,dy,dz;
1867 
1868 
1869  float left = - (m_Physics.m_EmitterSize.X()) / 2.0;
1870  float top = m_Physics.m_EmitterSize.Y() / 2.0;
1871 
1872  for ( i=0; i < m_ParticlesSimpleArray.Count(); i++ ) {
1873  moParticlesSimple* pPar = m_ParticlesSimpleArray[i];
1874  pPar->Force = zero;
1875 
1876  /*if (pPar->Fixed)
1877  continue;*/
1878 
1879  /* Gravitation */
1880  switch(m_Physics.m_AttractorType) {
1882  pPar->Force = ( m_Physics.m_AttractorVector - pPar->Pos3d )*(m_Physics.gravitational * pPar->Mass);
1883  break;
1884 
1886  if (m_pTrackerData) {
1887  pPar->Force = ( moVector3f( 0.5f - m_pTrackerData->GetBarycenter().X(), 0.5f - m_pTrackerData->GetBarycenter().Y(), 0.0 ) - pPar->Pos3d )*(m_Physics.gravitational * pPar->Mass);
1888  }
1889  break;
1891  switch( m_Physics.m_AttractorMode ) {
1894 
1895  pPar->Destination = moVector3f( ( left + pPar->Pos.X()*pPar->Size.X() + pPar->Size.X()/2.0 )*m_Physics.m_AttractorVector.X() ,
1896  ( top - pPar->Pos.Y()*pPar->Size.Y() - pPar->Size.Y()/2.0 )*m_Physics.m_AttractorVector.Y(),
1897  m_Physics.m_AttractorVector.Z() );
1898 
1899  if (m_Physics.m_AttractorMode==PARTICLES_ATTRACTORMODE_STICK && moVector3f( pPar->Destination - pPar->Pos3d ).Length() < 0.1 ) {
1900  pPar->Pos3d = pPar->Destination;
1901  pPar->Velocity = zero;
1902  pPar->Force = zero;
1903  } else pPar->Force = ( pPar->Destination - pPar->Pos3d )*(m_Physics.gravitational * pPar->Mass);
1904  break;
1906  pPar->Destination = moVector3f( ( left + pPar->Pos.X()*pPar->Size.X() + pPar->Size.X()/2.0 )*m_Physics.m_AttractorVector.X() ,
1907  ( top - pPar->Pos.Y()*pPar->Size.Y() - pPar->Size.Y()/2.0 )*m_Physics.m_AttractorVector.Y(),
1908  m_Physics.m_AttractorVector.Z() );
1909 
1910  pPar->Pos3d = pPar->Pos3d + ( pPar->Destination - pPar->Pos3d) * m_Physics.gravitational;
1911 
1912  //atdis =( pPar->Destination - pPar->Pos3d);
1913  //if ( 0.04 < atdis.Length() && atdis.Length() < 0.05 ) {
1914  //MODebug2->Message( moText("Position reached : X:") + FloatToStr(pPar->Pos3d.X()) + moText(" Y:") + FloatToStr(pPar->Pos3d.Y()) );
1915  // }
1916  break;
1917  default:
1918  break;
1919  }
1920  break;
1921 
1922  }
1923 
1924 
1925  /* Viscous drag */
1926  pPar->Force-= pPar->Velocity*m_Physics.viscousdrag;
1927  }
1928 
1929  // Handle the spring interaction
1930  /*
1931  for (i=0;i<ns;i++) {
1932  p1 = s[i].from;
1933  p2 = s[i].to;
1934  dx = p[p1].p.x - p[p2].p.x;
1935  dy = p[p1].p.y - p[p2].p.y;
1936  dz = p[p1].p.z - p[p2].p.z;
1937  len = sqrt(dx*dx + dy*dy + dz*dz);
1938  f.x = s[i].springconstant * (len - s[i].restlength);
1939  f.x += s[i].dampingconstant * (p[p1].v.x - p[p2].v.x) * dx / len;
1940  f.x *= - dx / len;
1941  f.y = s[i].springconstant * (len - s[i].restlength);
1942  f.y += s[i].dampingconstant * (p[p1].v.y - p[p2].v.y) * dy / len;
1943  f.y *= - dy / len;
1944  f.z = s[i].springconstant * (len - s[i].restlength);
1945  f.z += s[i].dampingconstant * (p[p1].v.z - p[p2].v.z) * dz / len;
1946  f.z *= - dz / len;
1947  if (!p[p1].fixed) {
1948  p[p1].f.x += f.x;
1949  p[p1].f.y += f.y;
1950  p[p1].f.z += f.z;
1951  }
1952  if (!p[p2].fixed) {
1953  p[p2].f.x -= f.x;
1954  p[p2].f.y -= f.y;
1955  p[p2].f.z -= f.z;
1956  }
1957  }
1958  */
1959 }
1960 
1961 void moEffectParticlesSimple::UpdateParticles( double dt,int method )
1962 {
1963  int i;
1964 
1965  switch (method) {
1966  case 0:
1967  /* Euler */
1968  Regenerate();
1969  CalculateForces();
1970  CalculateDerivatives(false,dt);
1971  for ( i=0; i<m_ParticlesSimpleArray.Count(); i++ ) {
1972  moParticlesSimple* pPar = m_ParticlesSimpleArray[i];
1973 
1974  if (pPar && dt!=0.0) {
1975  pPar->Pos3d+= pPar->dpdt * dt;
1976  pPar->Velocity+= pPar->dvdt * dt;
1977  }
1978  }
1979  break;
1980  case 1: /* Midpoint */
1981  Regenerate();
1982  CalculateForces();
1983  CalculateDerivatives(false,dt);
1984  for (i=0;i<m_ParticlesSimpleArray.Count();i++) {
1985  moParticlesSimple* pPar = m_ParticlesSimpleArray[i];
1986  moParticlesSimple* ptmpPar = m_ParticlesSimpleArrayTmp[i];
1987  if (pPar && ptmpPar && dt!=0.0) {
1988  ptmpPar->Pos3d = pPar->Pos3d;
1989  ptmpPar->Velocity = pPar->Velocity;
1990  ptmpPar->Force = pPar->Force;
1991  ptmpPar->Pos3d = pPar->dpdt * dt / 2;
1992  ptmpPar->Pos3d+= pPar->dvdt * dt / 2;
1993  }
1994  }
1995  CalculateForces(true);
1996  CalculateDerivatives(true,dt);
1997  for ( i=0; i < m_ParticlesSimpleArray.Count(); i++ ) {
1998  moParticlesSimple* pPar = m_ParticlesSimpleArray[i];
1999  moParticlesSimple* ptmpPar = m_ParticlesSimpleArrayTmp[i];
2000  if (pPar && ptmpPar && dt!=0.0) {
2001  pPar->Pos3d+= ptmpPar->dpdt * dt;
2002  pPar->Velocity += ptmpPar->dvdt * dt;
2003  }
2004  }
2005  break;
2006  }
2007 }
2008 
2009 /*
2010  Calculate the derivatives
2011  dp/dt = v
2012  dv/dt = f / m
2013 */
2014 void moEffectParticlesSimple::CalculateDerivatives(bool tmparray, double dt)
2015 {
2016  int i;
2017  if (tmparray) {
2018  for ( i=0; i<m_ParticlesSimpleArrayTmp.Count(); i++) {
2019  if (dt>0) m_ParticlesSimpleArrayTmp[i]->dpdt = m_ParticlesSimpleArrayTmp[i]->Velocity;
2020  if (dt>0) m_ParticlesSimpleArrayTmp[i]->dvdt = m_ParticlesSimpleArrayTmp[i]->Force * 1.0f / m_ParticlesSimpleArrayTmp[i]->Mass;
2021 
2022  }
2023  } else {
2024  for ( i=0; i<m_ParticlesSimpleArray.Count(); i++) {
2025  if (dt>0) m_ParticlesSimpleArray[i]->dpdt = m_ParticlesSimpleArray[i]->Velocity;
2026 
2027  if (dt>0) m_ParticlesSimpleArray[i]->dvdt = m_ParticlesSimpleArray[i]->Force * 1.0f / m_ParticlesSimpleArray[i]->Mass;
2028 
2029  }
2030  }
2031 }
2032 
2033 /*
2034  A 1st order 1D DE solver.
2035  Assumes the function is not time dependent.
2036  Parameters
2037  h - step size
2038  y0 - last value
2039  method - algorithm to use [0,5]
2040  fcn - evaluate the derivative of the field
2041 */
2042 double moEffectParticlesSimple::Solver1D(double h,double y0,int method,double (*fcn)(double))
2043 {
2044  double ynew;
2045  double k1,k2,k3,k4,k5,k6;
2046 
2047  switch (method) {
2048  case 0: /* Euler method */
2049  k1 = h * (*fcn)(y0);
2050  ynew = y0 + k1;
2051  break;
2052  case 1: /* Modified Euler */
2053  k1 = h * (*fcn)(y0);
2054  k2 = h * (*fcn)(y0 + k1);
2055  ynew = y0 + (k1 + k2) / 2;
2056  break;
2057  case 2: /* Heuns method */
2058  k1 = h * (*fcn)(y0);
2059  k2 = h * (*fcn)(y0 + 2 * k1 / 3);
2060  ynew = y0 + k1 / 4 + 3 * k2 / 4;
2061  break;
2062  case 3: /* Midpoint */
2063  k1 = h * (*fcn)(y0);
2064  k2 = h * (*fcn)(y0 + k1 / 2);
2065  ynew = y0 + k2;
2066  break;
2067  case 4: /* 4'th order Runge-kutta */
2068  k1 = h * (*fcn)(y0);
2069  k2 = h * (*fcn)(y0 + k1/2);
2070  k3 = h * (*fcn)(y0 + k2/2);
2071  k4 = h * (*fcn)(y0 + k3);
2072  ynew = y0 + k1 / 6 + k2 / 3 + k3 / 3 + k4 / 6;
2073  break;
2074  case 5: /* England 4'th order, six stage */
2075  k1 = h * (*fcn)(y0);
2076  k2 = h * (*fcn)(y0 + k1 / 2);
2077  k3 = h * (*fcn)(y0 + (k1 + k2) / 4);
2078  k4 = h * (*fcn)(y0 - k2 + 2 * k3);
2079  k5 = h * (*fcn)(y0 + (7 * k1 + 10 * k2 + k4) / 27);
2080  k6 = h * (*fcn)(y0 + (28*k1 - 125*k2 + 546*k3 + 54*k4 - 378*k5) / 625);
2081  ynew = y0 + k1 / 6 + 4 * k3 / 6 + k4 / 6;
2082  break;
2083  }
2084 
2085  return(ynew);
2086 }
2087 
2088 
2089 void moEffectParticlesSimple::ParticlesSimpleAnimation( moTempo* tempogral, moEffectState* parentstate ) {
2090 
2091  int i,j;
2092  int I,J;
2093  int Ileft, Iright, Jtop, Jbottom;
2094 
2095  switch(revelation_status) {
2097  /*
2098  if (MotionActivity.Started()) {
2099  if (!TimerFullRevelation.Started()) {
2100  TimerFullRevelation.Start();
2101  revelation_status = PARTICLES_REVEALING;
2102  }
2103  }*/
2104  break;
2106  /*
2107  if (!TimerFullRestoration.Started()) {
2108  TimerFullRestoration.Start();
2109  }
2110 
2111  if (TimerFullRestoration.Duration() > time_tofull_restoration ) {
2112  TimerFullRestoration.Stop();
2113  revelation_status = PARTICLES_RESTORINGALL;
2114  }*/
2115  break;
2117  //RevealingAll();
2118  break;
2119 
2121  //RestoringAll();
2122  break;
2123 
2124  case PARTICLES_REVEALING:
2125  /*
2126  if (TimerFullRevelation.Started()) {
2127  if (TimerFullRevelation.Duration() > time_tofull_revelation ) {
2128  TimerFullRevelation.Stop();
2129  revelation_status = PARTICLES_REVEALINGALL;
2130  }
2131  }
2132 */
2133  for( i = 0; i<m_cols ; i++) {
2134  for( j = 0; j<m_rows ; j++) {
2135 
2136  moParticlesSimple* pPar = m_ParticlesSimpleArray.GetRef( i + j*m_cols );
2137 
2138 
2139 
2140  }
2141 
2142  }
2143  break;
2144 
2145  }
2146 
2147 
2148 }
2149 
2151  moParticlesSimple* pPar = NULL;
2152  pPar = m_ParticlesSimpleArray.GetRef( partid );
2153  int i = partid;
2154  int j = 0;
2155  if (pPar) {
2156  //MODebug2->Push( moText("Pos:") + IntToStr(i) + moText(" J:") + IntToStr(j) + moText(" lum:") + IntToStr(lum) + moText(" lumindex:") + IntToStr(lumindex) + moText(" glid:") + IntToStr(pPar->GLId) + moText(" glid2:") + IntToStr(pPar->GLId2));
2157  MODebug2->Push( moText("Pos X:") + FloatToStr(pPar->Pos.X()) + moText(" Pos Y:") + FloatToStr(pPar->Pos.Y()) + moText(" glid:") + IntToStr(pPar->GLId) + moText(" glid2:") + IntToStr(pPar->GLId2));
2158  MODebug2->Push( moText("X:") + FloatToStr(pPar->Pos3d.X()) + moText(" Y:") + FloatToStr(pPar->Pos3d.Y()) + moText(" Z:") + FloatToStr(pPar->Pos3d.Z()) );
2159  MODebug2->Push( moText("VX:") + FloatToStr(pPar->Velocity.X()) + moText(" VY:") + FloatToStr(pPar->Velocity.Y()) + moText(" VZ:") + FloatToStr(pPar->Velocity.Z()) );
2160  MODebug2->Push( moText("FX:") + FloatToStr(pPar->Force.X()) + moText(" FY:") + FloatToStr(pPar->Force.Y()) + moText(" FZ:") + FloatToStr(pPar->Force.Z()) );
2161  MODebug2->Push( moText("Size X:") + FloatToStr(pPar->Size.X()) + moText(" Size Y:") + FloatToStr(pPar->Size.Y()) );
2162  MODebug2->Push( moText("TCoord X:") + FloatToStr(pPar->TCoord.X()) + moText(" TCoord Y:") + FloatToStr(pPar->TCoord.Y()) );
2163  MODebug2->Push( moText("TCoord2 X:") + FloatToStr(pPar->TCoord2.X()) + moText(" TCoord2 Y:") + FloatToStr(pPar->TCoord2.Y()) );
2164  MODebug2->Push( moText("Visible:") + IntToStr((int)pPar->Visible) );
2165  MODebug2->Push( moText("Age:") + IntToStr((int)pPar->Age.Duration()) );
2166  }
2167 
2168 }
2169 
2171 
2173 
2174 
2175 }
2176 
2177 void moEffectParticlesSimple::DrawParticlesSimple( moTempo* tempogral, moEffectState* parentstate ) {
2178 
2179  int i,j;
2180  int cols2,rows2;
2181 
2182  //if ((moGetTicks() % 1000) == 0) TrackParticle(1);
2183 
2184  cols2 = m_Config.Int( moR(PARTICLES_WIDTH));
2185  rows2 = m_Config.Int( moR(PARTICLES_HEIGHT) );
2186 
2187  if (cols2!=m_cols || rows2!=m_rows) {
2188  InitParticlesSimple(cols2,rows2);
2189  }
2190 
2192  /*
2193  if ( last_tick > tempogral->ticks || tempogral->ticks==0 ) {
2194  m_Physics.EmitionTimer.Start();
2195  }
2196  */
2197 
2198 /*
2199  dtrel = (double) ( tempogral->ticks - last_tick ) / (double)16.666666;
2200  //if ( ( (last_tick/100) % 50 ) == 0 ) MODebug2->Push("dtrel:"+FloatToStr(dtrel));
2201  dt = m_Config.Eval( moR(PARTICLES_SYNC),m_EffectState.tempo.ang) * dtrel * (double)(m_EffectState.tempo.delta) / (double)100.0;
2202 
2203  last_tick = tempogral->ticks;
2204  */
2205  gral_ticks = tempogral->ticks;
2206 
2207 
2208 
2209  if (!m_Physics.EmitionTimer.Started())
2210  m_Physics.EmitionTimer.Start();
2211 
2212 
2213 
2214  //glBindTexture( GL_TEXTURE_2D, 0 );
2215  if ( texture_mode!=PARTICLES_TEXTUREMODE_MANY && texture_mode!=PARTICLES_TEXTUREMODE_MANY2PATCH ) {
2216  //glBindTexture( GL_TEXTURE_2D, /*m_Config[moR(PARTICLES_TEXTURE)].GetData()->GetGLId(&m_EffectState.tempo, 1, NULL )*/0 );
2217  if (glid>=0) glBindTexture( GL_TEXTURE_2D, glid );
2218  else glBindTexture( GL_TEXTURE_2D, 0);
2219  }
2220  //glColor4f(1.0,1.0,1.0,1.0);
2221  //glDisable( GL_CULL_FACE);
2222  //glDisable( GL_DEPTH_TEST);
2223  //glFrontFace( GL_CW);
2224  //glPolygonMode( GL_LINES, GL_FRONT_AND_BACK);
2225 
2226  //SetBlending( (moBlendingModes) m_Config[moR(PARTICLES_BLENDING)][MO_SELECTED][0].Int() );
2227 
2228 
2229  float sizexd2,sizeyd2;
2230  float tsizex,tsizey;
2231 
2232  moFont* pFont = m_Config[moR(PARTICLES_FONT) ][MO_SELECTED][0].Font();
2233  moText Texto;
2234 
2235  UpdateParticles( dt, 0 ); //Euler mode
2236  ParticlesSimpleAnimation( tempogral, parentstate );
2237 
2238  float idxt = 0.0;
2239 
2240  for( j = 0; j<m_rows ; j++) {
2241  for( i = 0; i<m_cols ; i++) {
2242 
2243 
2244  idxt = 0.5 + (float)( i + j * m_cols ) / (float)( m_cols * m_rows * 2 );
2245 
2246  moParticlesSimple* pPar = m_ParticlesSimpleArray.GetRef( i + j*m_cols );
2247 
2248  if (pPar->Visible) {
2249 
2250 
2251  if (texture_mode==PARTICLES_TEXTUREMODE_MANY || texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH ) {
2252  //pPar->GLId = 22;
2253  if (pPar->GLId>0) {
2254  glActiveTextureARB( GL_TEXTURE0_ARB );
2255  glEnable(GL_TEXTURE_2D);
2256  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2257  glBindTexture( GL_TEXTURE_2D, pPar->GLId );
2258  }
2259  if (pPar->GLId2>0) {
2260  glActiveTextureARB( GL_TEXTURE1_ARB );
2261  glEnable(GL_TEXTURE_2D);
2262  //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2263  glBindTexture( GL_TEXTURE_2D, pPar->GLId2 );
2264  }
2265  }
2266 
2267  if (moScript::IsInitialized()) {
2268  if (ScriptHasFunction("RunParticle")) {
2269  SelectScriptFunction("RunParticle");
2270  AddFunctionParam( (int) ( i + j*m_cols ) );
2271  AddFunctionParam( (float)dt );
2272  if (!RunSelectedFunction(1)) {
2273  MODebug2->Error( moText("RunParticle function not executed") );
2274  }
2275  }
2276  }
2277 
2278  sizexd2 = (pPar->Size.X()* pPar->ImageProportion )/2.0;
2279  sizeyd2 = pPar->Size.Y()/2.0;
2280  tsizex = pPar->TSize.X();
2281  tsizey = pPar->TSize.Y();
2282  double part_timer = 0.001f * (double)(pPar->Age.Duration()); // particule ang = durationinmilis / 1000 ...
2283 
2284  if (m_pParticleTime) {
2285  if (m_pParticleTime->GetData()) {
2286  m_pParticleTime->GetData()->SetDouble(part_timer);
2287  m_pParticleTime->Update(true);
2288  }
2289  }
2290 
2291  if (m_pParticleIndex) {
2292  if (m_pParticleIndex->GetData()) {
2293  m_pParticleIndex->GetData()->SetLong( i + j*m_cols );
2294  m_pParticleIndex->Update(true);
2295  }
2296  }
2297 
2298  glPushMatrix();
2299 
2300  glTranslatef( pPar->Pos3d.X(), pPar->Pos3d.Y(), pPar->Pos3d.Z() );
2301 
2302  glRotatef( m_Config.Eval( moR(PARTICLES_ROTATEZ_PARTICLE) ) + pPar->Rotation.Z(), 0.0, 0.0, 1.0 );
2303  glRotatef( m_Config.Eval( moR(PARTICLES_ROTATEY_PARTICLE) ) + pPar->Rotation.Y(), 0.0, 1.0, 0.0 );
2304  glRotatef( m_Config.Eval( moR(PARTICLES_ROTATEX_PARTICLE) ) + pPar->Rotation.X(), 1.0, 0.0, 0.0 );
2305 
2306  //scale
2307  glScalef( m_Config.Eval( moR(PARTICLES_SCALEX_PARTICLE) )*pPar->Scale,
2308  m_Config.Eval( moR(PARTICLES_SCALEY_PARTICLE) )*pPar->Scale,
2309  m_Config.Eval( moR(PARTICLES_SCALEZ_PARTICLE) )*pPar->Scale);
2310 
2311 
2312  glColor4f( m_Config[moR(PARTICLES_COLOR)][MO_SELECTED][MO_RED].Eval() * pPar->Color.X() * m_EffectState.tintr,
2313  m_Config[moR(PARTICLES_COLOR)][MO_SELECTED][MO_GREEN].Eval() * pPar->Color.Y() * m_EffectState.tintg,
2314  m_Config[moR(PARTICLES_COLOR)][MO_SELECTED][MO_BLUE].Eval() * pPar->Color.Z() * m_EffectState.tintb,
2315  m_Config[moR(PARTICLES_COLOR)][MO_SELECTED][MO_ALPHA].Eval()
2316  * m_Config.Eval( moR(PARTICLES_ALPHA))
2317  * m_EffectState.alpha * pPar->Alpha );
2318 
2319 
2320  moVector3f CO(m_Physics.m_EyeVector - pPar->Pos3d);
2321  moVector3f U,V,W;
2322  moVector3f CPU,CPW;
2323  moVector3f A,B,C,D;
2324 
2325  moVector3f CENTRO;
2326 
2327  U = moVector3f( 0.0f, 0.0f, 1.0f );
2328  V = moVector3f( 1.0f, 0.0f, 0.0f );
2329  W = moVector3f( 0.0f, 1.0f, 0.0f );
2330 
2331  U = CO;
2332  U.Normalize();
2333 
2334  //orientation always perpendicular to plane (X,Y)
2335  switch(m_Physics.m_OrientationMode) {
2336 
2338  //cuadrado centrado en Pos3d....
2339  U = moVector3f( 0.0f, 0.0f, 1.0f );
2340  V = moVector3f( 1.0f, 0.0f, 0.0f );
2341  W = moVector3f( 0.0f, 1.0f, 0.0f );
2342  break;
2343 
2345  V = moVector3f( -CO.Y(), CO.X(), 0.0f );
2346  V.Normalize();
2347 
2348  CPU = moVector3f( U.X(), U.Y(), 0.0f );
2349  W = moVector3f( 0.0f, 0.0f, CPU.Length() );
2350  CPU.Normalize();
2351  CPW = CPU * -U.Z();
2352  W+= CPW;
2353  break;
2354 
2356  U = pPar->Velocity;
2357  U.Normalize();
2358  if (U.Length() < 0.5) {
2359  U = moVector3f( 0.0, 0.0, 1.0 );
2360  U.Normalize();
2361  }
2362  V = moVector3f( -U.Y(), U.X(), 0.0f );
2363  V.Normalize();
2364  CPU = moVector3f( U.X(), U.Y(), 0.0f );
2365  W = moVector3f( 0.0f, 0.0f, CPU.Length() );
2366  CPU.Normalize();
2367  CPW = CPU * -U.Z();
2368  W+= CPW;
2369  break;
2370  }
2371 
2372  A = V * -sizexd2 + W * sizeyd2;
2373  B = V *sizexd2 + W * sizeyd2;
2374  C = V *sizexd2 + W * -sizeyd2;
2375  D = V * -sizexd2 + W * -sizeyd2;
2376 
2377 
2378  //cuadrado centrado en Pos3d....
2379 
2380  //TODO: dirty code here!!!
2381  if (texture_mode==PARTICLES_TEXTUREMODE_UNIT || texture_mode==PARTICLES_TEXTUREMODE_PATCH) {
2382 
2383  MOfloat cycleage = m_EffectState.tempo.ang;
2384 
2385  //if (m_Physics.m_MaxAge>0) cycleage = (float) ((double)pPar->Age.Duration() / (double)m_Physics.m_MaxAge );
2386  cycleage = part_timer;
2387 
2388  int glid = pPar->GLId;
2389 
2390  if ( pPar->MOId==-1 ) {
2391 
2392  glid = m_Config.GetGLId( moR(PARTICLES_TEXTURE), cycleage, 1.0, NULL );
2393 
2394  } else {
2395 
2396 
2397  if ( pPar->MOId>-1 ) {
2398 
2399  moTexture* pTex = m_pResourceManager->GetTextureMan()->GetTexture(pPar->MOId);
2400 
2401  if (pTex) {
2402 
2403  if (
2404  pTex->GetType()==MO_TYPE_VIDEOBUFFER
2405  || pTex->GetType()==MO_TYPE_CIRCULARVIDEOBUFFER
2406  || pTex->GetType()==MO_TYPE_MOVIE
2407  || pTex->GetType()==MO_TYPE_TEXTURE_MULTIPLE
2408  ) {
2409  moTextureAnimated *pTA = (moTextureAnimated*)pTex;
2410 
2411  if (pPar->FrameForced) {
2412  glid = pTA->GetGLId( pPar->ActualFrame );
2413  } else {
2414  glid = pTA->GetGLId((MOfloat)cycleage);
2415  pPar->ActualFrame = pTA->GetActualFrame();
2416 
2417  pPar->FramePS = pTA->GetFramesPerSecond();
2418  pPar->FrameCount = pTA->GetFrameCount();
2419  }
2420 
2421  } else {
2422  glid = pTex->GetGLId();
2423  }
2424 
2425  }
2426  }
2427  }
2428 
2429  glBindTexture( GL_TEXTURE_2D , glid );
2430  }
2431 
2432 
2433  glBegin(GL_QUADS);
2434  //glColor4f( 1.0, 0.5, 0.5, idxt );
2435 
2436  if (pPar->GLId2>0) {
2437  //glColor4f( 1.0, 0.5, 0.5, idxt );
2438  glMultiTexCoord2fARB( GL_TEXTURE0_ARB, pPar->TCoord.X(), pPar->TCoord.Y() );
2439  glMultiTexCoord2fARB( GL_TEXTURE1_ARB, pPar->TCoord2.X(), pPar->TCoord2.Y());
2440  } else glTexCoord2f( pPar->TCoord.X(), pPar->TCoord.Y() );
2441  glVertex3f( A.X(), A.Y(), 0.0);
2442 
2443  //glColor4f( 0.5, 1.0, 0.5, idxt );
2444 
2445  if (pPar->GLId2>0) {
2446  glMultiTexCoord2fARB( GL_TEXTURE0_ARB, pPar->TCoord.X()+tsizex, pPar->TCoord.Y() );
2447  glMultiTexCoord2fARB( GL_TEXTURE1_ARB, pPar->TCoord2.X()+pPar->TSize2.X(), pPar->TCoord2.Y());
2448  } else glTexCoord2f( pPar->TCoord.X()+tsizex, pPar->TCoord.Y() );
2449  glVertex3f( B.X(), B.Y(), 0.0);
2450 
2451  //glColor4f( 0.5, 0.5, 1.0, idxt );
2452  if (pPar->GLId2>0) {
2453  glMultiTexCoord2fARB( GL_TEXTURE0_ARB, pPar->TCoord.X()+tsizex, pPar->TCoord.Y()+tsizey );
2454  glMultiTexCoord2fARB( GL_TEXTURE1_ARB, pPar->TCoord2.X()+pPar->TSize2.X(), pPar->TCoord2.Y()+pPar->TSize2.Y());
2455  } else glTexCoord2f( pPar->TCoord.X()+tsizex, pPar->TCoord.Y()+tsizey );
2456  glVertex3f( C.X(), C.Y(), 0.0);
2457 
2458  //glColor4f( 1.0, 1.0, 1.0, idxt );
2459  if (pPar->GLId2>0) {
2460  glMultiTexCoord2fARB( GL_TEXTURE0_ARB, pPar->TCoord.X(), pPar->TCoord.Y()+pPar->TSize.Y());
2461  glMultiTexCoord2fARB( GL_TEXTURE1_ARB, pPar->TCoord2.X(), pPar->TCoord2.Y()+pPar->TSize2.Y());
2462  } else glTexCoord2f( pPar->TCoord.X(), pPar->TCoord.Y()+tsizey );
2463  glVertex3f( D.X(), D.Y(), 0.0);
2464  glEnd();
2465 
2466  //draw vectors associated...
2467  if ( drawing_features>2 ) {
2468  CENTRO = moVector3f( 0.0 , 0.0, 0.0 );
2469 
2470  glDisable( GL_TEXTURE_2D );
2471  glLineWidth( 8.0 );
2472  glBegin(GL_LINES);
2474  glColor4f( 0.0, 1.0, 1.0, 1.0);
2475  glVertex3f( CENTRO.X(), CENTRO.Y(), 0.0001);
2476 
2477  glColor4f( 0.0, 1.0, 1.0, 1.0);
2478  glVertex3f( CENTRO.X() + U.X(), CENTRO.Y() + U.Y(), 0.0001);
2479 
2480  glEnd();
2481 
2482  glBegin(GL_LINES);
2484  glColor4f( 1.0, 0.0, 1.0, 1.0);
2485  glVertex3f( CENTRO.X(), CENTRO.Y(), 0.0001);
2486 
2487  glColor4f( 1.0, 0.0, 1.0, 1.0);
2488  glVertex3f( CENTRO.X() + V.X(), CENTRO.Y() + V.Y(), 0.0001);
2489 
2490  glEnd();
2491 
2492  glBegin(GL_LINES);
2494  glColor4f( 0.0, 0.0, 1.0, 1.0);
2495  glVertex3f( CENTRO.X(), CENTRO.Y(), 0.0001);
2496 
2497  glColor4f( 0.0, 0.0, 1.0, 1.0);
2498  glVertex3f( CENTRO.X() + W.X(), CENTRO.Y() + W.Y(), 0.0001);
2499 
2500  glEnd();
2501  glEnable( GL_TEXTURE_2D );
2502  }
2503 
2504 
2505  glPopMatrix();
2506  }
2507  }
2508  }
2509 
2510  if (pFont && drawing_features>2) {
2511  for( i = 0; i<m_cols ; i++) {
2512  for( j = 0; j<m_rows ; j++) {
2513 
2514  moParticlesSimple* pPar = m_ParticlesSimpleArray.GetRef( i + j*m_cols );
2515  if ((i + j*m_cols) % 10 == 0 ) {
2516  Texto = moText( IntToStr(i + j*m_cols));
2517  Texto.Left(5);
2518  Texto+= moText("F:")+moText( (moText)FloatToStr( pPar->Force.X() ).Left(5) + moText(",")
2519  + (moText)FloatToStr( pPar->Force.Y() ).Left(5)
2520  + moText(",") + (moText)FloatToStr( pPar->Force.Z() ).Left(5) );
2521 
2522  Texto+= moText("V:")+ moText( (moText)FloatToStr( pPar->Velocity.X() ).Left(5) + moText(",")
2523  + (moText)FloatToStr( pPar->Velocity.Y() ).Left(5)
2524  + moText(",") + (moText)FloatToStr( pPar->Velocity.Z() ).Left(5) );
2525 
2526  pFont->Draw( pPar->Pos3d.X(),
2527  pPar->Pos3d.Y(),
2528  Texto );
2529 
2530 
2531  Texto = moText( moText("(") + (moText)FloatToStr(pPar->TCoord.X()).Left(4) + moText(",") + (moText)FloatToStr(pPar->TCoord.Y()).Left(4) + moText(")") );
2532 
2533  pFont->Draw( pPar->Pos3d.X()-sizexd2,
2534  pPar->Pos3d.Y()+sizeyd2-2,
2535  Texto );
2536 
2537  Texto = moText( moText("(") + (moText)FloatToStr(pPar->TCoord.X()+tsizex).Left(4) + moText(",") + (moText)FloatToStr(pPar->TCoord.Y()).Left(4) + moText(")"));
2538 
2539  pFont->Draw( pPar->Pos3d.X()+sizexd2-12,
2540  pPar->Pos3d.Y()+sizeyd2-5,
2541  Texto );
2542 
2543  Texto = moText( moText("(") + (moText)FloatToStr(pPar->TCoord.X()+tsizex).Left(4) + moText(",") + (moText)FloatToStr(pPar->TCoord.Y()+tsizey).Left(4) + moText(")"));
2544 
2545  pFont->Draw( pPar->Pos3d.X()+sizexd2-12,
2546  pPar->Pos3d.Y()-sizeyd2+2,
2547  Texto );
2548 
2549  Texto = moText( moText("(") + (moText)FloatToStr(pPar->TCoord.X()).Left(4) + moText(",") + (moText)FloatToStr(pPar->TCoord.Y()+tsizey).Left(4) + moText(")"));
2550 
2551  pFont->Draw( pPar->Pos3d.X()-sizexd2,
2552  pPar->Pos3d.Y()-sizeyd2+5,
2553  Texto );
2554  }
2555 
2556  }
2557  }
2558  }
2559 
2560  if (pFont && drawing_features>2) {
2561 
2562  Texto = moText( moText("T2 Rest.:") + IntToStr(TimerFullRestoration.Duration()));
2563  pFont->Draw( -10.0f,
2564  0.0f,
2565  Texto );
2566 
2567  Texto = moText( moText("T2 Revel.:") + IntToStr(TimerFullRevelation.Duration()));
2568  pFont->Draw( -10.0f,
2569  3.0f,
2570  Texto );
2571 
2572  Texto = moText( moText("T Revel.:") + IntToStr(TimerOfRevelation.Duration()) + moText(" rev: ") + IntToStr(time_of_revelation));
2573  pFont->Draw( -10.0f,
2574  6.0f,
2575  Texto );
2576 
2577  Texto = moText( moText("T Rest.:") + IntToStr(TimerOfRestoration.Duration()) + moText(" res: ") + IntToStr(time_of_restoration) );
2578  pFont->Draw( -10.0f,
2579  9.0f,
2580  Texto );
2581 
2582  Texto = moText("Status: ");
2583 
2584  switch(revelation_status) {
2586  Texto+= moText("Full Restored");
2587  break;
2588  case PARTICLES_REVEALING:
2589  Texto+= moText("Revealing");
2590  break;
2592  Texto+= moText("Revealing");
2593  break;
2595  Texto+= moText("Full Revealed");
2596  break;
2597  case PARTICLES_RESTORING:
2598  Texto+= moText("Restoring");
2599  break;
2601  Texto+= moText("Restoring All");
2602  break;
2603  }
2604  pFont->Draw( -10.0f,
2605  13.0f,
2606  Texto );
2607  }
2608 
2609 }
2610 #ifdef USE_TUIO
2611 using namespace TUIO;
2612 #endif
2613 void moEffectParticlesSimple::DrawTracker() {
2614 
2615  int w = m_pResourceManager->GetRenderMan()->ScreenWidth();
2616  int h = m_pResourceManager->GetRenderMan()->ScreenHeight();
2617 
2618  m_pTrackerData = NULL;
2619 
2620  bool has_motion = false;
2621  bool has_features = false;
2622 
2623  if (m_InletTrackerSystemIndex>-1) {
2624  moInlet* pInlet = m_Inlets.GetRef(m_InletTrackerSystemIndex);
2625  if (pInlet)
2626  if (pInlet->Updated()) {
2627  m_pTrackerData = (moTrackerSystemData *)pInlet->GetData()->Pointer();
2628  // chequeando info
2629 
2630  /*MODebug2->Push( moText("ParticlesSimple varX: ") + FloatToStr( m_pTrackerData->GetVariance().X())
2631  + moText(" varY: ") + FloatToStr(m_pTrackerData->GetVariance().Y()) );
2632  */
2633  }
2634  }
2635 #ifdef USE_TUIO
2636  m_pTUIOData = NULL;
2637  if (m_InletTuioSystemIndex>-1) {
2638  moInlet* pInlet = m_Inlets.GetRef(m_InletTuioSystemIndex);
2639  if (pInlet)
2640  if (pInlet->Updated()) {
2641  m_pTUIOData = (moTUIOSystemData *)pInlet->GetData()->Pointer();
2642 
2643  if (m_pTUIOData) {
2644 
2645  TuioObject* pObject;
2646 
2647 if (drawing_features > 0 ) {
2648 
2649  std::list<TuioObject*> objects = m_pTUIOData->getTuioObjects();
2650 
2651  for (std::list<TuioObject*>::iterator iter=objects.begin(); iter != objects.end(); iter++) {
2652 
2653  pObject = (*iter);
2654  if (pObject) {
2655  moVector2f position( pObject->getX(), pObject->getY() * h / w);
2656 
2657  glBindTexture(GL_TEXTURE_2D,0);
2658  glColor4f(0.0, 1.0, 1.0, 1.0);
2659 
2660  float angle = pObject->getAngle();
2661 
2662  //int u = pObject->getSymbolID();
2663 
2664  //moTrackerFeature* NF = NULL;
2665 
2666  //if (m_pTrackerData) {
2667  // NF = m_pTrackerData->GetFeature(u);
2668  //}
2669 
2670 
2672  //glRotatef( angle*moMathf::RAD_TO_DEG , 0.0, 0.0, 1.0 );
2673 
2674  glBegin(GL_QUADS);
2675  glVertex2f((position.X() - 0.02)*normalf, (position.Y() - 0.02)*normalf);
2676  glVertex2f((position.X() - 0.02)*normalf, (position.Y() + 0.02)*normalf);
2677  glVertex2f((position.X() + 0.02)*normalf, (position.Y() + 0.02)*normalf);
2678  glVertex2f((position.X() + 0.02)*normalf, (position.Y() - 0.02)*normalf);
2679  glEnd();
2680 
2681 
2683  glColor4f( 0.0,1.0,1.0,1.0);
2684  glLineWidth(8.0);
2685  glBegin(GL_LINES);
2686  glVertex2f( position.X(), position.Y());
2687  glVertex2f( position.X() + 0.04*cos(angle), position.Y() + 0.04*sin(angle) );
2688  glEnd();
2689 
2691 
2692  glColor4f( 0.4,0.6,0.2,1.0);
2693  glLineWidth(4.0);
2694  glBegin(GL_LINES);
2695  glVertex2f( position.X(), position.Y());
2696  glVertex2f( position.X() + pObject->getXSpeed(), position.Y() + pObject->getYSpeed() );
2697  glEnd();
2698 
2700 
2701  //glColor4f( 1.0,0.0,0.0,1.0);
2702  //glLineWidth(8.0);
2703  //glBegin(GL_LINES);
2704  // glVertex2f( position.X(), position.Y());
2705  // glVertex2f( position.X(), position.Y() + pObject->getRotationSpeed()*0.0001 );
2706  //glEnd();
2707 
2708  //MODebug2->Push(moText("rspeed:")+IntToStr( (int)(pObject->getRotationSpeed()/10.0)) );
2709 
2710  //if (NF) {
2711  // moVector2f pu( NF->x - 0.5, (-NF->y + 0.5) * h / w);
2712  // glColor4f( 0.5,0.0,0.0,1.0);
2713  // glBegin(GL_QUADS);
2714  // glVertex2f( ( pu.X() - 0.01)*normalf, (pu.Y() - 0.01)*normalf);
2715  // glVertex2f((pu.X() - 0.01)*normalf, (pu.Y() + 0.01)*normalf);
2716  // glVertex2f((pu.X() + 0.01)*normalf, (pu.Y() + 0.01)*normalf);
2717  // glVertex2f((pu.X() + 0.01)*normalf, (pu.Y() - 0.01)*normalf);
2718  // glEnd();
2719  //}
2720 
2721 
2722 
2723  }
2724 
2725  }
2726 
2727  TuioCursor* pCursor;
2728 
2729  std::list<TuioCursor*> cursors = m_pTUIOData->getTuioCursors();
2730 
2731  for (std::list<TuioCursor*>::iterator iter=cursors.begin(); iter != cursors.end(); iter++) {
2732 
2733  pCursor = (*iter);
2734  if (pCursor) {
2735  moVector2f position( pCursor->getX(), pCursor->getY() * h / w);
2736 
2737  glBindTexture(GL_TEXTURE_2D,0);
2738  glColor4f(0.0, 0.0, 1.0, 1.0);
2740 
2741  float r = 0.02;
2742  glLineWidth(4.0);
2743  glBegin(GL_LINE_LOOP);
2744  for(float t = 0; t <= moMathf::TWO_PI; t += moMathf::TWO_PI / 12 )
2745  glVertex2f( r* cos(t) + position.X(), r* sin(t) + position.Y());
2746  glEnd();
2747  }
2748 
2749  }
2750 }
2751  }
2752 
2753  }
2754  }
2755 #endif
2756 
2757  //if (m_pTUIOData) {
2758  // int nobjects = m_pTUIOData->getTuioObjects().size();
2759  // //MODebug2->Push( moText(" NOBJECTS: ") + IntToStr(nobjects) );
2760 
2761  // for (int f = 0; f < m_pTUIOData->getTuioObjects().size(); f++)
2762  // {
2763 
2764  // }
2765 
2766  //}
2767 
2768 
2769  if (m_pTrackerData ) {
2770 
2771  glDisable(GL_TEXTURE_2D);
2772 
2773  m_bTrackerInit = true;
2774 
2775  //SelectScriptFunction("Reset");
2776  //RunSelectedFunction();
2777 
2778  //MODebug2->Push(IntToStr(TrackerId));
2779 
2780  //MODebug2->Push(moText("Receiving:") + IntToStr(m_pTrackerData->GetFeaturesCount()) );
2781  if (m_pTrackerData->GetFeaturesCount()>0) {
2782  int tw = m_pTrackerData->GetVideoFormat().m_Width;
2783  int th = m_pTrackerData->GetVideoFormat().m_Height;
2784  //MODebug2->Push(moText("vformat:")+IntToStr(tw)+moText("th")+IntToStr(th));
2785 
2786  m_TrackerBarycenter = moVector2f( ( ( m_pTrackerData->GetBarycenter().X() ) - 0.5),
2787  ( -( m_pTrackerData->GetBarycenter().Y() ) + 0.5) * h / w );
2788 
2789  //MODebug2->Push(moText("Barycenter x:")+FloatToStr(m_TrackerBarycenter.X()) + moText(" y:")+FloatToStr(m_TrackerBarycenter.Y()) );
2790 
2791  if (drawing_features > 2 ) {
2792 
2793  glBindTexture(GL_TEXTURE_2D,0);
2794  glColor4f(0.3, 1.0, 1.0, 1.0);
2795 
2796  glBegin(GL_QUADS);
2797  glVertex2f((m_TrackerBarycenter.X() - 0.02)*normalf, (m_TrackerBarycenter.Y() - 0.02)*normalf);
2798  glVertex2f((m_TrackerBarycenter.X() - 0.02)*normalf, (m_TrackerBarycenter.Y() + 0.02)*normalf);
2799  glVertex2f((m_TrackerBarycenter.X() + 0.02)*normalf, (m_TrackerBarycenter.Y() + 0.02)*normalf);
2800  glVertex2f((m_TrackerBarycenter.X() + 0.02)*normalf, (m_TrackerBarycenter.Y() - 0.02)*normalf);
2801  glEnd();
2802 
2803  }
2804 
2805 
2806  for (int f = 0; f < m_pTrackerData->GetFeaturesCount(); f++)
2807  {
2808 
2809  moTrackerFeature* pF = m_pTrackerData->GetFeature(f);
2810 
2811  if (pF && pF->valid) {
2812 
2813  float x = (pF->x ) - 0.5;
2814  float y = ( -(pF->y ) + 0.5 ) * h / w;
2815  float tr_x = (pF->tr_x ) - 0.5 ;
2816  float tr_y = ( -(pF->tr_y ) + 0.5 ) * h / w;
2817  float v_x = (pF->v_x );
2818  float v_y = -(pF->v_y);
2819  float vel = sqrtf( v_x*v_x+v_y*v_y );
2820  int v = pF->val;
2821 
2822  //MODebug2->Log(moText(" x:")+FloatToStr(pF->x) + moText(" y:")+FloatToStr(pF->y) );
2823 
2824  glBindTexture(GL_TEXTURE_2D,0);
2825  glColor4f(1.0, 0.0, 0.0, 1.0);
2826 
2827  if (v >= 0) glColor4f(0.0, 1.0, 0.0, 1.0);
2828  else if (v == -1) glColor4f(1.0, 0.0, 1.0, 1.0);
2829  else if (v == -2) glColor4f(1.0, 0.0, 1.0, 1.0);
2830  else if (v == -3) glColor4f(1.0, 0.0, 1.0, 1.0);
2831  else if (v == -4) glColor4f(1.0, 0.0, 1.0, 1.0);
2832  else if (v == -5) glColor4f(1.0, 0.0, 1.0, 1.0);
2833 
2834 
2835 
2836 
2837  if ( v>=0) {
2838  has_features = true;
2839 
2840  if (drawing_features > 0 ) {
2841 
2842  glPointSize((GLfloat)4);
2843  glLineWidth((GLfloat)4.0);
2844 
2845  if ( pF->is_object) {
2846  glColor4f(1.0, 0.0, 0.0, 1.0);
2847 
2848  //Uplas[f] >=3 !!!!!
2849  int myuplas[3];
2850  myuplas[0] = -1;
2851  myuplas[1] = -1;
2852  myuplas[2] = -1;
2853  int k1,k2,o = 0;
2854  for( int pp=0; pp<m_pTrackerData->nPares; pp++) {
2855  k1 = m_pTrackerData->m_Pares[pp][0];
2856  k2 = m_pTrackerData->m_Pares[pp][1];
2857  if (o<3) if (k1==f) myuplas[o++] = k2;
2858  if (o<3) if (k2==f) myuplas[o++] = k1;
2859  }
2860 
2861  int countv = 1;
2862  moVector2f obj_v( x, y );
2863  glColor4f(1.0, 0.1, 0.1, 1.0);
2864  //glPointSiz((GLfloat)10);
2865  glLineWidth((GLfloat)2.0);
2866  for( int pp=0; pp<3; pp++ ) {
2867  int e = myuplas[pp];
2868  moTrackerFeature* NF = m_pTrackerData->GetFeature(e);
2869  if (NF) {
2870  moVector2f av2( NF->x - 0.5, (-NF->y + 0.5 ) * h / w );
2871  //obj_v+=av2;
2872  glBegin(GL_LINES);
2873  glVertex2f(obj_v.X(),obj_v.Y());
2874  glVertex2f(av2.X(),av2.Y());
2875  glEnd();
2876  countv++;
2877  }
2878  }
2879  }
2880 
2881  glBegin(GL_QUADS);
2882  glVertex2f((x - 0.008)*normalf, (y - 0.008)*normalf);
2883  glVertex2f((x - 0.008)*normalf, (y + 0.008)*normalf);
2884  glVertex2f((x + 0.008)*normalf, (y + 0.008)*normalf);
2885  glVertex2f((x + 0.008)*normalf, (y - 0.008)*normalf);
2886  glEnd();
2887  }
2888 
2889 
2890  if (drawing_features > 1 ) {
2891  glBegin(GL_QUADS);
2892  glVertex2f((tr_x - 0.008)*normalf, (tr_y - 0.008)*normalf);
2893  glVertex2f((tr_x - 0.008)*normalf, (tr_y + 0.008)*normalf);
2894  glVertex2f((tr_x + 0.008)*normalf, (tr_y + 0.008)*normalf);
2895  glVertex2f((tr_x + 0.008)*normalf, (tr_y - 0.008)*normalf);
2896  glEnd();
2897 
2898 
2899  glColor4f(1.0, 1.0, 1.0, 1.0);
2900  glBegin(GL_LINES);
2901  glVertex2f( x*normalf, y*normalf);
2902  glVertex2f( tr_x*normalf, tr_y*normalf);
2903  glEnd();
2904  }
2905 
2906  if ( vel > 0.01 && vel < 0.1) {
2907 
2908  has_motion = true;
2909 
2910  if (drawing_features > 1 ) {
2911 
2912  glColor4f(0.0, 0.0, 1.0, 1.0);
2913  //glPointSize((GLfloat)10);
2914  glLineWidth((GLfloat)2.0);
2915 
2916  glBegin(GL_LINES);
2917  glVertex2f( x*normalf, y*normalf);
2918  glVertex2f( (x+v_x)*normalf, (y+v_y)*normalf);
2919  glEnd();
2920  }
2921 
2923  }
2924 
2925 
2926  }
2927 
2928  }
2929 
2930 
2931  }
2932 
2935  if (has_motion) {
2936 
2937  if (!MotionActivity.Started()) {
2938  MotionActivity.Start();
2939  }
2940 
2941  } else {
2942  MotionActivity.Stop();
2943  }
2944 
2945  if (has_features) {
2946 
2947  if (!FeatureActivity.Started()) {
2948  FeatureActivity.Start();
2949  }
2950 
2951  } else {
2952  FeatureActivity.Stop();
2953  }
2954 
2955 
2956  }
2957 
2958  glEnable(GL_TEXTURE_2D);
2959 
2960  }
2961 
2962 }
2963 
2964 void moEffectParticlesSimple::Draw( moTempo* tempogral, moEffectState* parentstate)
2965 {
2966 
2967  int ancho,alto;
2968  int w = m_pResourceManager->GetRenderMan()->ScreenWidth();
2969  int h = m_pResourceManager->GetRenderMan()->ScreenHeight();
2970  frame++;
2971  moFont* pFont = m_Config[ moR(PARTICLES_FONT) ][MO_SELECTED][0].Font();
2972 
2973 
2974 
2975  /*
2976  MODebug2->Push( "sync: " + IntToStr((int)state.synchronized)
2977  +" tempo.on: " + IntToStr( (int)m_EffectState.tempo.Started() )
2978  +" tempo.pause_on: " + IntToStr( (int)m_EffectState.tempo.Paused())
2979  + " tempo.ticks: " + IntToStr( m_EffectState.tempo.ticks )
2980  + " tempo.ang: " + FloatToStr( m_EffectState.tempo.ang ) );
2981 
2982 */
2983  PreDraw( tempogral, parentstate);
2984  UpdateParameters();
2985  // Cambiar la proyeccion para una vista ortogonal //
2986 /*
2987 */
2988 
2989 
2990  if (ortho) {
2991 
2992  glDisable(GL_DEPTH_TEST); // Disables Depth Testing
2993  //glDepthMask(GL_FALSE);
2994  glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
2995  glLoadIdentity(); // Reset The Projection Matrix
2996  glOrtho(-0.5,0.5,-0.5*h/w,0.5*h/w,-1,1); // Set Up An Ortho Screen
2997 
2998  } else {
2999 
3000  glDisable(GL_DEPTH_TEST);
3001 
3002  //glClear( GL_DEPTH_BUFFER_BIT );
3003  //glDepthMask(GL_FALSE);
3004 
3005  glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
3006  glLoadIdentity(); // Reset The Projection Matrix
3007  m_pResourceManager->GetGLMan()->SetPerspectiveView( w, h );
3008  }
3009 
3010  glMatrixMode(GL_PROJECTION);
3011 
3012  if (!ortho) {
3013  if ( m_EffectState.stereoside == MO_STEREO_NONE ) {
3014 
3015  gluLookAt( m_Physics.m_EyeVector.X(),
3016  m_Physics.m_EyeVector.Y(),
3017  m_Physics.m_EyeVector.Z(),
3018  m_Config.Eval( moR(PARTICLES_VIEWX)),
3019  m_Config.Eval( moR(PARTICLES_VIEWY)),
3020  m_Config.Eval( moR(PARTICLES_VIEWZ)),
3021  0, 1, 0);
3022 
3023  } else {
3024  if ( m_EffectState.stereoside == MO_STEREO_LEFT ) {
3025  gluLookAt( m_Physics.m_EyeVector.X()-0.1,
3026  m_Physics.m_EyeVector.Y(),
3027  m_Physics.m_EyeVector.Z(),
3028  m_Config.Eval( moR(PARTICLES_VIEWX))-0.1,
3029  m_Config.Eval( moR(PARTICLES_VIEWY)),
3030  m_Config.Eval( moR(PARTICLES_VIEWZ)),
3031  0, 1, 0);
3032  } else if ( m_EffectState.stereoside == MO_STEREO_RIGHT ) {
3033  gluLookAt( m_Physics.m_EyeVector.X()+0.1,
3034  m_Physics.m_EyeVector.Y(),
3035  m_Physics.m_EyeVector.Z(),
3036  m_Config.Eval( moR(PARTICLES_VIEWX))+0.1,
3037  m_Config.Eval( moR(PARTICLES_VIEWY)),
3038  m_Config.Eval( moR(PARTICLES_VIEWZ)),
3039  0, 1, 0);
3040  }
3041 
3042  }
3043  }
3044 
3045  if (texture_mode==PARTICLES_TEXTUREMODE_UNIT || texture_mode==PARTICLES_TEXTUREMODE_PATCH) {
3046  glid = m_Config.GetGLId( moR(PARTICLES_TEXTURE), &m_EffectState.tempo);
3047  }
3048 
3049  glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
3050  glLoadIdentity(); // Reset The View
3051 
3052  glEnable(GL_ALPHA);
3053  //glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
3054  //glClear( GL_DEPTH_BUFFER_BIT );
3055  //glEnable(GL_ALPHA_TEST);
3056 
3057 
3058  //glDisable( GL_CULL_FACE);
3059  //glFrontFace( GL_CCW);
3060 
3061  //glDepthMask(true);
3062 
3063  //esto deberia ser parametrizable...
3064  //glEnable( GL_DEPTH_TEST);
3065  //glDisable( GL_DEPTH_TEST);
3066  glShadeModel(GL_SMOOTH);
3067 
3068  //setUpLighting();
3069 
3070  tx = m_Config.Eval( moR(PARTICLES_TRANSLATEX));
3071  ty = m_Config.Eval( moR(PARTICLES_TRANSLATEY));
3072  tz = m_Config.Eval( moR(PARTICLES_TRANSLATEZ));
3073 
3074 
3075  sx = m_Config.Eval( moR(PARTICLES_SCALEX));
3076  sy = m_Config.Eval( moR(PARTICLES_SCALEY));
3077  sz = m_Config.Eval( moR(PARTICLES_SCALEZ));
3078 
3079  glTranslatef( tx,
3080  ty,
3081  tz );
3082 
3083  //rotation
3084  float rz = m_Config.Eval( moR(PARTICLES_ROTATEZ));
3085  glRotatef( rz, 0.0, 0.0, 1.0 );
3086  glRotatef( m_Config.Eval( moR(PARTICLES_ROTATEY)), 0.0, 1.0, 0.0 );
3087  glRotatef( m_Config.Eval( moR(PARTICLES_ROTATEX)), 1.0, 0.0, 0.0 );
3088 
3089  //scale
3090  glScalef( sx,
3091  sy,
3092  sz);
3093 
3094  //blending
3095  SetBlending( (moBlendingModes) m_Config.Int( moR(PARTICLES_BLENDING) ) );
3096 /*
3097  //set image
3098  moTexture* pImage = (moTexture*) m_Config[moR(PARTICLES_TEXTURE)].GetData()->Pointer();
3099 */
3100  //color
3101  //SetColor( m_Config[moR(PARTICLES_COLOR)][MO_SELECTED], m_Config[moR(PARTICLES_ALPHA)][MO_SELECTED], m_EffectState );
3102  SetColor( m_Config[moR(PARTICLES_COLOR)], m_Config[moR(PARTICLES_ALPHA)], m_EffectState );
3103 
3104  moText Texto = m_Config.Text( moR(PARTICLES_TEXT) );
3105 
3106 
3107 
3108  DrawParticlesSimple( tempogral, parentstate );
3109 
3110  //add conditions
3111 
3112  DrawTracker();
3113 
3114 
3115  if (pFont && drawing_features>2) {
3116  moText infod = moText("gravitational:")+FloatToStr(m_Physics.gravitational)+moText(" viscosity:")+FloatToStr(m_Physics.viscousdrag);
3117  pFont->Draw( 0.0, 0.0, infod );
3118  }
3119 
3120  EndDraw();
3121 
3122  //glDisable(GL_DEPTH_TEST);
3123  glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
3124  glPopMatrix(); // Restore The Old Projection Matrix
3125  glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
3126  glPopMatrix(); // Restore The Old Projection Matrix
3127 
3128 }
3129 
3130 void moEffectParticlesSimple::setUpLighting()
3131 {
3132  // Set up lighting.
3133  float light1_ambient[4] = { 1.0, 1.0, 1.0, 1.0 };
3134  float light1_diffuse[4] = { 1.0, 0.9, 0.9, 1.0 };
3135  float light1_specular[4] = { 1.0, 0.7, 0.7, 1.0 };
3136  float light1_position[4] = { -1.0, 1.0, 1.0, 0.0 };
3137  glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
3138  glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
3139  glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
3140  glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
3141  glEnable(GL_LIGHT1);
3142 
3143  float light2_ambient[4] = { 0.2, 0.2, 0.2, 1.0 };
3144  float light2_diffuse[4] = { 0.9, 0.9, 0.9, 1.0 };
3145  float light2_specular[4] = { 0.7, 0.7, 0.7, 1.0 };
3146  float light2_position[4] = { 1.0, -1.0, -1.0, 0.0 };
3147  glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
3148  glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
3149  glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);
3150  glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
3151 // glEnable(GL_LIGHT2);
3152 
3153  float front_emission[4] = { 1, 1, 1, 0.0 };
3154  float front_ambient[4] = { 0.2, 0.2, 0.2, 0.0 };
3155  float front_diffuse[4] = { 0.95, 0.95, 0.8, 0.0 };
3156  float front_specular[4] = { 0.6, 0.6, 0.6, 0.0 };
3157  glMaterialfv(GL_FRONT, GL_EMISSION, front_emission);
3158  glMaterialfv(GL_FRONT, GL_AMBIENT, front_ambient);
3159  glMaterialfv(GL_FRONT, GL_DIFFUSE, front_diffuse);
3160  glMaterialfv(GL_FRONT, GL_SPECULAR, front_specular);
3161  glMaterialf(GL_FRONT, GL_SHININESS, 16.0);
3162  glColor4fv(front_diffuse);
3163 
3164  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
3165  glColorMaterial(GL_FRONT, GL_DIFFUSE);
3166  glEnable(GL_COLOR_MATERIAL);
3167 
3168  glEnable(GL_LIGHTING);
3169 }
3170 
3171 
3173 {
3174  return PreFinish();
3175 }
3176 
3177 //====================
3178 //
3179 // CUSTOM
3180 //
3181 //===================
3182 
3183 
3184 void moEffectParticlesSimple::Interaction( moIODeviceManager *IODeviceManager ) {
3185  moDeviceCode *temp;
3186  MOint did,cid,state,valor;
3187 
3188  moEffect::Interaction( IODeviceManager );
3189 
3190  if (devicecode!=NULL)
3191  for(int i=0; i<ncodes; i++) {
3192 
3193  temp = devicecode[i].First;
3194 
3195  while(temp!=NULL) {
3196  did = temp->device;
3197  cid = temp->devicecode;
3198  state = IODeviceManager->IODevices().GetRef(did)->GetStatus(cid);
3199  valor = IODeviceManager->IODevices().GetRef(did)->GetValue(cid);
3200  if (state)
3201  switch(i) {
3202  case 0:
3203  //Tx = valor;
3204  MODebug2->Push(IntToStr(valor));
3205  break;
3206  case 1:
3207  //Ty = m_pResourceManager->GetRenderMan()->RenderHeight() - valor;
3208  MODebug2->Push(IntToStr(valor));
3209  break;
3210  case 2:
3211  //Sx+=((float) valor / (float) 256.0);
3212  MODebug2->Push(IntToStr(valor));
3213  break;
3214  case 3:
3215  //Sy+=((float) valor / (float) 256.0);
3216  MODebug2->Push(IntToStr(valor));
3217  break;
3218  }
3219  temp = temp->next;
3220  }
3221  }
3222 
3224  moEvent* actual = IODeviceManager->GetEvents()->First;
3225  //recorremos todos los events y parseamos el resultado
3226  //borrando aquellos que ya usamos
3227  MOint tempval;
3228  while(actual!=NULL) {
3229  //solo nos interesan los del midi q nosotros mismos generamos, para destruirlos
3230  if(actual->deviceid == MO_IODEVICE_MIDI) {
3231 
3234 
3235  int CC = actual->reservedvalue1;
3236  int VAL = actual->reservedvalue2;
3237 
3238  switch (CC) {
3239  case 45:
3240  if (texture_mode==PARTICLES_TEXTUREMODE_MANY2PATCH) {
3241  this->Shot( "FOTOS", 1 );
3242  this->ReInit();
3243  MODebug2->Message(moText("## Midi Shot Triggered ##"));
3244  } else {
3245  this->ReInit();
3246  }
3247  break;
3248  case 81:
3249  midi_red = (float)VAL / (float) 127.0;
3250  MODebug2->Message(moText("Red:")+FloatToStr(midi_red));
3251  break;
3252  case 82:
3253  midi_green = (float)VAL / (float) 127.0;
3254  MODebug2->Message(moText("Green:")+FloatToStr(midi_green));
3255  break;
3256  case 83:
3257  midi_blue = (float)VAL / (float) 127.0;
3258  MODebug2->Message(moText("Blue:")+FloatToStr(midi_blue));
3259  break;
3260 
3261  case 84:
3262  midi_maxage = (float)VAL / (float) 127.0;
3263  MODebug2->Message(moText("Maxage:")+FloatToStr(midi_maxage));
3264  break;
3265  case 85:
3266  midi_emitionperiod = (float)VAL / (float) 127.0;
3267  MODebug2->Message(moText("Emition Period:")+FloatToStr(midi_emitionperiod));
3268  break;
3269  case 86:
3270  midi_emitionrate = (float)VAL / (float) 127.0;
3271  break;
3272  case 87:
3273  midi_randomvelocity = (float)VAL / (float) 127.0;
3274  break;
3275 
3276  case 88:
3277  midi_randommotion = (float)VAL / (float) 127.0;
3278  break;
3279 
3280  case 107:
3281  if (VAL==0 || VAL==127) {
3282  m_Config.PreConfPrev();
3283  }
3284  break;
3285  case 108:
3286  if (VAL==0 || VAL==127) {
3287  m_Config.PreConfNext();
3288  }
3289  break;
3290 
3291 
3292  default:
3293  MODebug2->Push("device in psimple!!!");
3294  MODebug2->Push(IntToStr(VAL));
3295  break;
3296  }
3297 
3298 
3299 
3300  actual = actual->next;
3301  } else actual = actual->next;
3302  }
3303 
3304 }
3305 
3306 void moEffectParticlesSimple::Update( moEventList *p_eventlist ) {
3307 
3308  moMoldeoObject::Update( p_eventlist );
3309 
3310 
3311 
3313  /*
3314  if (moScript::IsInitialized()) {
3315  if (ScriptHasFunction("Update")) {
3316  SelectScriptFunction("Update");
3317  //passing number of particles
3318  AddFunctionParam( (int) ( m_rows*m_cols ) );
3319  //passing dt
3320  AddFunctionParam( (float) dt );
3321  if (m_pTrackerData) {
3322  AddFunctionParam(m_pTrackerData->GetFeaturesCount());
3323  AddFunctionParam(m_pTrackerData->GetValidFeatures());
3324  //AddFunctionParam((int)m_pTrackerData->GetVideoFormat().m_Width);
3325  //AddFunctionParam((int)m_pTrackerData->GetVideoFormat().m_Height);
3326  } else {
3327  AddFunctionParam( -1 );
3328  AddFunctionParam( -1 );
3329  }
3330 
3331  if (!RunSelectedFunction(1)) {
3332  MODebug2->Error( GetLabelName() + moText(" moEffectParticlesSimple:: script > ") + moText("Update function not executed") );
3333  }
3334  }
3335  }
3336  */
3337 }
3338 
3339 void moEffectParticlesSimple::RegisterFunctions()
3340 {
3341  moMoldeoObject::RegisterFunctions();
3342 
3343  RegisterBaseFunction("GetDelta"); //0
3344  RegisterFunction("GetParticleCount"); //1
3345  RegisterFunction("GetParticle"); //2
3346  RegisterFunction("GetParticlePosition");//3
3347  RegisterFunction("GetParticleSize");//4
3348  RegisterFunction("GetParticleScale");//5
3349  RegisterFunction("GetParticleVelocity");//6
3350  RegisterFunction("GetParticleRotation");//7
3351  RegisterFunction("GetParticleGraphics");//8
3352 
3353  RegisterFunction("UpdateParticle");//9
3354  RegisterFunction("UpdateParticlePosition");//10
3355  RegisterFunction("UpdateParticleSize");//11
3356  RegisterFunction("UpdateParticleScale");//12
3357  RegisterFunction("UpdateParticleVelocity");//13
3358  RegisterFunction("UpdateParticleRotation");//14
3359  RegisterFunction("UpdateParticleGraphics");//15
3360 
3361  RegisterFunction("UpdateForce");//16
3362 
3363  RegisterFunction("Shot");//17
3364  RegisterFunction("ReInit");//18
3365 
3366  RegisterFunction("DrawPoint");//19
3367  RegisterFunction("GetParticleIntersection");//20
3368 
3369  ResetScriptCalling();
3370 }
3371 
3372 int moEffectParticlesSimple::ScriptCalling(moLuaVirtualMachine& vm, int iFunctionNumber)
3373 {
3374  switch (iFunctionNumber - m_iMethodBase)
3375  {
3376  case 0:
3377  ResetScriptCalling();
3378  return luaGetDelta(vm);
3379  case 1:
3380  ResetScriptCalling();
3381  return luaGetParticleCount(vm);
3382  case 2:
3383  ResetScriptCalling();
3384  return luaGetParticle(vm);
3385  case 3:
3386  ResetScriptCalling();
3387  return luaGetParticlePosition(vm);
3388  case 4:
3389  ResetScriptCalling();
3390  return luaGetParticleSize(vm);
3391  case 5:
3392  ResetScriptCalling();
3393  return luaGetParticleScale(vm);
3394  case 6:
3395  ResetScriptCalling();
3396  return luaGetParticleVelocity(vm);
3397  case 7:
3398  ResetScriptCalling();
3399  return luaGetParticleRotation(vm);
3400  case 8:
3401  ResetScriptCalling();
3402  return luaGetParticleGraphics(vm);
3403 
3404 
3405  case 9:
3406  ResetScriptCalling();
3407  return luaUpdateParticle(vm);
3408  case 10:
3409  ResetScriptCalling();
3410  return luaUpdateParticlePosition(vm);
3411  case 11:
3412  ResetScriptCalling();
3413  return luaUpdateParticleSize(vm);
3414  case 12:
3415  ResetScriptCalling();
3416  return luaUpdateParticleScale(vm);
3417  case 13:
3418  ResetScriptCalling();
3419  return luaUpdateParticleVelocity(vm);
3420  case 14:
3421  ResetScriptCalling();
3422  return luaUpdateParticleRotation(vm);
3423  case 15:
3424  ResetScriptCalling();
3425  return luaUpdateParticleGraphics(vm);
3426 
3427  case 16:
3428  ResetScriptCalling();
3429  return luaUpdateForce(vm);
3430 
3431 
3432  case 17:
3433  ResetScriptCalling();
3434  return luaShot(vm);
3435 
3436  case 18:
3437  ResetScriptCalling();
3438  return luaReInit(vm);
3439 
3440  case 19:
3441  ResetScriptCalling();
3442  return luaDrawPoint(vm);
3443 
3444  case 20:
3445  ResetScriptCalling();
3446  return luaGetParticleIntersection(vm);
3447 
3448  default:
3449  NextScriptCalling();
3450  return moMoldeoObject::ScriptCalling( vm, iFunctionNumber );
3451  }
3452 }
3453 
3454 
3455 
3456 int moEffectParticlesSimple::luaDrawPoint(moLuaVirtualMachine& vm)
3457 {
3458  lua_State *state = (lua_State *) vm;
3459 
3460  MOfloat x = (MOfloat) lua_tonumber (state, 1);
3461  MOfloat y = (MOfloat) lua_tonumber (state, 2);
3462 
3463  glDisable(GL_TEXTURE_2D);
3464 
3465  glColor4f( 1.0, 1.0, 1.0, 1.0);
3466  glPointSize(4.0);
3467 
3468  glBegin(GL_POINTS);
3469  glVertex2f( x, y );
3470  glEnd();
3471 
3472  return 0;
3473 }
3474 
3475 int moEffectParticlesSimple::luaGetDelta(moLuaVirtualMachine& vm)
3476 {
3477  lua_State *state = (lua_State *) vm;
3478 
3479  lua_pushnumber(state, (lua_Number) dt );
3480 
3481  return 1;
3482 }
3483 
3484 int moEffectParticlesSimple::luaGetParticleCount(moLuaVirtualMachine& vm)
3485 {
3486  lua_State *state = (lua_State *) vm;
3487 
3488  lua_pushnumber(state, (lua_Number) m_ParticlesSimpleArray.Count() );
3489 
3490  return 1;
3491 }
3492 
3493 
3494 
3495 int moEffectParticlesSimple::luaGetParticle(moLuaVirtualMachine& vm)
3496 {
3497  lua_State *state = (lua_State *) vm;
3498 
3499  MOint i = (MOint) lua_tonumber (state, 1);
3500 
3501  moParticlesSimple* Par;
3502 
3503  Par = m_ParticlesSimpleArray[i];
3504 
3505  if (Par) {
3506 
3507  lua_pushnumber(state, (lua_Number) Par->Age.Duration() );
3508  lua_pushnumber(state, (lua_Number) Par->Visible );
3509  lua_pushnumber(state, (lua_Number) Par->Mass );
3510  lua_pushnumber(state, (lua_Number) Par->MaxAge );
3511 
3512  }
3513 
3514  return 4;
3515 }
3516 
3517 
3518 int moEffectParticlesSimple::luaGetParticleRotation(moLuaVirtualMachine& vm)
3519 {
3520  lua_State *state = (lua_State *) vm;
3521 
3522  MOint i = (MOint) lua_tonumber (state, 1);
3523 
3524  moParticlesSimple* Par;
3525 
3526  moVector3f Rotation;
3527 
3528  Par = m_ParticlesSimpleArray[i];
3529 
3530  if (Par) {
3531 
3532  Rotation = Par->Rotation;
3533  lua_pushnumber(state, (lua_Number) Rotation.X() );
3534  lua_pushnumber(state, (lua_Number) Rotation.Y() );
3535  lua_pushnumber(state, (lua_Number) Rotation.Z() );
3536 
3537  } else {
3538  lua_pushnumber(state, (lua_Number) 0 );
3539  lua_pushnumber(state, (lua_Number) 0 );
3540  lua_pushnumber(state, (lua_Number) 0 );
3541  }
3542 
3543  return 3;
3544 }
3545 
3555 int moEffectParticlesSimple::luaGetParticleGraphics(moLuaVirtualMachine& vm)
3556 {
3557  lua_State *state = (lua_State *) vm;
3558 
3559  MOint i = (MOint) lua_tonumber (state, 1);
3560 
3561  moParticlesSimple* Par;
3562 
3563  moVector3f Rotation;
3564 
3565  Par = m_ParticlesSimpleArray[i];
3566 
3567  if (Par) {
3568  int frameactual = 0;
3569  int framecount = 0;
3570  int frameps = 0;
3571  int moid = -1;
3572 
3573  if (Par->MOId==-1) {
3574  //int moid = m_pResourceManager->GetTextureMan()->GetTextureMOId( (MOuint)Par->GLId );
3575  }
3576 
3577  moid = Par->MOId;
3578  frameactual = Par->ActualFrame;
3579  framecount = Par->FrameCount;
3580  frameps = Par->FramePS;
3581 
3582  //Rotation = Par->Rotation;
3583  lua_pushnumber(state, (lua_Number) moid );
3584  lua_pushnumber(state, (lua_Number) frameactual );
3585  lua_pushnumber(state, (lua_Number) framecount );
3586  lua_pushnumber(state, (lua_Number) frameps );
3587 
3588 
3589  } else {
3590 
3591  lua_pushnumber(state, (lua_Number) 0 );
3592  lua_pushnumber(state, (lua_Number) 0 );
3593  lua_pushnumber(state, (lua_Number) 0 );
3594  lua_pushnumber(state, (lua_Number) 0 );
3595  }
3596 
3597  return 4;
3598 }
3599 
3600 //TODO: do an absolute version, who calculates also the system translation and rotation....
3601 //this is a relative version o particle position
3602 
3603 int moEffectParticlesSimple::luaGetParticlePosition(moLuaVirtualMachine& vm)
3604 {
3605  lua_State *state = (lua_State *) vm;
3606 
3607  MOint i = (MOint) lua_tonumber (state, 1);
3608 
3609  moParticlesSimple* Par;
3610 
3611  moVector3f Position;
3612 
3613  Par = m_ParticlesSimpleArray[i];
3614 
3615  if (Par) {
3616 
3617  Position = Par->Pos3d;
3618  lua_pushnumber(state, (lua_Number) Position.X() );
3619  lua_pushnumber(state, (lua_Number) Position.Y() );
3620  lua_pushnumber(state, (lua_Number) Position.Z() );
3621 
3622  } else {
3623  lua_pushnumber(state, (lua_Number) 0 );
3624  lua_pushnumber(state, (lua_Number) 0 );
3625  lua_pushnumber(state, (lua_Number) 0 );
3626  }
3627 
3628  return 3;
3629 }
3630 
3631 int moEffectParticlesSimple::luaGetParticleSize(moLuaVirtualMachine& vm)
3632 {
3633  lua_State *state = (lua_State *) vm;
3634 
3635  MOint i = (MOint) lua_tonumber (state, 1);
3636 
3637  moParticlesSimple* Par;
3638 
3639  moVector2f Size;
3640 
3641  Par = m_ParticlesSimpleArray[i];
3642 
3643  if (Par) {
3644  Size = Par->Size;
3645  double part_timer = 0.001f * (double)(Par->Age.Duration());
3646 
3647  if (m_pParticleTime) {
3648  m_pParticleTime->GetData()->SetDouble(part_timer);
3649  m_pParticleTime->Update(true);
3650  }
3651 
3652  double sx = m_Config.Eval( moR(PARTICLES_SCALEX_PARTICLE) ) * Par->Scale * Par->ImageProportion;
3653  double sy = m_Config.Eval( moR(PARTICLES_SCALEY_PARTICLE) ) * Par->Scale;
3654 
3655  lua_pushnumber(state, (lua_Number) Size.X()*sx );
3656  lua_pushnumber(state, (lua_Number) Size.Y()*sy );
3657 
3658  } else {
3659  lua_pushnumber(state, (lua_Number) 0 );
3660  lua_pushnumber(state, (lua_Number) 0 );
3661  }
3662 
3663  return 2;
3664 }
3665 
3666 int moEffectParticlesSimple::luaGetParticleScale(moLuaVirtualMachine& vm)
3667 {
3668  lua_State *state = (lua_State *) vm;
3669 
3670  MOint i = (MOint) lua_tonumber (state, 1);
3671 
3672  moParticlesSimple* Par;
3673 
3674  double Scale;
3675 
3676  Par = m_ParticlesSimpleArray[i];
3677 
3678  if (Par) {
3679  Scale = Par->Scale;
3680  lua_pushnumber(state, (lua_Number) Scale );
3681  } else {
3682  lua_pushnumber(state, (lua_Number) 0 );
3683  }
3684 
3685  return 1;
3686 }
3687 
3688 int moEffectParticlesSimple::luaGetParticleVelocity(moLuaVirtualMachine& vm)
3689 {
3690  lua_State *state = (lua_State *) vm;
3691 
3692  MOint i = (MOint) lua_tonumber (state, 1);
3693 
3694  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3695 
3696  moVector3f Velocity = Par->Velocity;
3697 
3698  if (Par) {
3699 
3700  lua_pushnumber(state, (lua_Number) Velocity.X() );
3701  lua_pushnumber(state, (lua_Number) Velocity.Y() );
3702  lua_pushnumber(state, (lua_Number) Velocity.Z() );
3703 
3704  }
3705 
3706  return 3;
3707 }
3708 
3709 
3710 int moEffectParticlesSimple::luaGetParticleIntersection(moLuaVirtualMachine& vm)
3711 {
3712  lua_State *state = (lua_State *) vm;
3713 
3714  MOfloat x = (MOfloat) lua_tonumber (state, 1);
3715  MOfloat y = (MOfloat) lua_tonumber (state, 2);
3716 
3717  moParticlesSimple* Par;
3718 
3719  moVector3f Position;
3720  int index;
3721  bool a = false;
3722 
3723  float x1,x2,y1,y2;
3724  float xc,yc;
3725  float ux,uy;
3726  float vx,vy;
3727 
3728  float sizeu,sizev;
3729 
3730  index = -1;
3731 
3734 
3736 
3737  for( int i=0; i<m_ParticlesSimpleArray.Count(); i++ ) {
3738 
3739  Par = m_ParticlesSimpleArray[i];
3740 
3741  if (Par->Visible) {
3742  Position = Par->Pos3d;
3743 
3745 
3746  xc = Par->Pos3d.X()*sx*cos(rz/180) + tx;
3747  yc = Par->Pos3d.Y()*sy*sin(rz/180) + ty;
3748  x1 = ( Par->Pos3d.X() - Par->Size.X()/2 ) * sx + tx;
3749  x2 = ( Par->Pos3d.X() + Par->Size.X()/2 ) * sx + tx;
3750  y1 = ( Par->Pos3d.Y() - Par->Size.Y()/2 ) * sy + ty;
3751  y2 = ( Par->Pos3d.Y() + Par->Size.Y()/2 ) * sy + ty;
3752 
3753  ux = ( x1 - xc );
3754  uy = ( y1 - yc );
3755  vx = ( x2 - xc );
3756  vy = ( y2 - yc );
3757  sizeu = Par->Size.X()/2 * sx;
3758  sizev = Par->Size.Y()/2 * sx;
3759 
3760  moVector2f feat( x, y );
3761  moVector2f u( ux, uy );
3762  moVector2f v( vx, vy );
3763  moVector2f featuv;
3764  featuv = moVector2f ( fabs( feat.Dot(u)), fabs( feat.Dot(v) ) );
3765  if ( featuv.X() < sizeu && featuv.Y() < sizev ) {
3766  index = i;
3767  }
3768  }
3769  }
3770 
3771  lua_pushnumber(state, (lua_Number) index );
3772 
3773  return 1;
3774 }
3775 
3776 
3777 int moEffectParticlesSimple::luaUpdateParticle( moLuaVirtualMachine& vm ) {
3778  lua_State *state = (lua_State *) vm;
3779 
3780  MOint i = (MOint) lua_tonumber (state, 1);
3781 
3782  MOint age = (MOint) lua_tonumber (state, 2);
3783  MOint visible = (MOint) lua_tonumber (state, 3);
3784  MOint mass = (MOint) lua_tonumber (state, 4);
3785  MOint maxage = (MOint) lua_tonumber (state, 5);
3786 
3787  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3788 
3789  if (Par) {
3790  Par->Age.SetDuration( age);
3791  Par->Visible = visible;
3792  Par->Mass = mass;
3793  Par->MaxAge = maxage;
3794  }
3795 
3796  return 0;
3797 
3798 }
3799 
3800 int moEffectParticlesSimple::luaUpdateParticlePosition( moLuaVirtualMachine& vm ) {
3801  lua_State *state = (lua_State *) vm;
3802 
3803  MOint i = (MOint) lua_tonumber (state, 1);
3804 
3805  MOfloat x = (MOfloat) lua_tonumber (state, 2);
3806  MOfloat y = (MOfloat) lua_tonumber (state, 3);
3807  MOfloat z = (MOfloat) lua_tonumber (state, 4);
3808 
3809  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3810 
3811  if (Par) {
3812  Par->Pos3d = moVector3f( x, y, z );
3813  }
3814 
3815  return 0;
3816 
3817 }
3818 
3819 int moEffectParticlesSimple::luaUpdateParticleSize( moLuaVirtualMachine& vm ) {
3820  lua_State *state = (lua_State *) vm;
3821 
3822  MOint i = (MOint) lua_tonumber (state, 1);
3823 
3824  MOfloat x = (MOfloat) lua_tonumber (state, 2);
3825  MOfloat y = (MOfloat) lua_tonumber (state, 3);
3826 
3827 
3828  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3829 
3830  if (Par) {
3831  Par->Size = moVector2f( x, y );
3832  }
3833 
3834  return 0;
3835 
3836 }
3837 
3838 int moEffectParticlesSimple::luaUpdateParticleScale( moLuaVirtualMachine& vm ) {
3839  lua_State *state = (lua_State *) vm;
3840 
3841  MOint i = (MOint) lua_tonumber (state, 1);
3842 
3843  MOfloat scale = (MOfloat) lua_tonumber (state, 2);
3844 
3845  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3846 
3847  if (Par) {
3848  Par->Scale = scale;
3849  }
3850 
3851  return 0;
3852 
3853 }
3854 
3855 int moEffectParticlesSimple::luaUpdateParticleVelocity( moLuaVirtualMachine& vm ) {
3856  lua_State *state = (lua_State *) vm;
3857 
3858  MOint i = (MOint) lua_tonumber (state, 1);
3859 
3860  MOfloat x = (MOfloat) lua_tonumber (state, 2);
3861  MOfloat y = (MOfloat) lua_tonumber (state, 3);
3862  MOfloat z = (MOfloat) lua_tonumber (state, 4);
3863 
3864  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3865 
3866  if (Par) {
3867  Par->Velocity = moVector3f( x, y, z );
3868  }
3869 
3870  return 0;
3871 
3872 }
3873 
3874 int moEffectParticlesSimple::luaUpdateParticleRotation( moLuaVirtualMachine& vm ) {
3875  lua_State *state = (lua_State *) vm;
3876 
3877  MOint i = (MOint) lua_tonumber (state, 1);
3878 
3879  MOfloat rx = (MOfloat) lua_tonumber (state, 2);
3880  MOfloat ry = (MOfloat) lua_tonumber (state, 3);
3881  MOfloat rz = (MOfloat) lua_tonumber (state, 4);
3882 
3883  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3884 
3885  if (Par) {
3886  Par->Rotation = moVector3f( rx, ry, rz );
3887  }
3888 
3889  return 0;
3890 
3891 }
3892 
3893 int moEffectParticlesSimple::luaUpdateParticleGraphics( moLuaVirtualMachine& vm ) {
3894  lua_State *state = (lua_State *) vm;
3895 
3896  MOint i = (MOint) lua_tonumber (state, 1);
3897 
3898  MOuint moid = (MOuint) lua_tonumber (state, 2);
3899  MOuint actualframe = (MOuint) lua_tonumber (state, 3);
3900  MOuint frameps = (MOuint) lua_tonumber (state, 4);
3901  MOuint frameforced = (MOuint) lua_tonumber (state, 5);
3902 
3903  moParticlesSimple* Par = m_ParticlesSimpleArray[i];
3904 
3905  if (Par) {
3906  Par->MOId = moid;
3907  Par->ActualFrame = actualframe;
3908  Par->FramePS = frameps;
3909  Par->FrameForced = (bool)frameforced;
3910  }
3911 
3912  return 0;
3913 
3914 }
3915 
3916 
3917 int moEffectParticlesSimple::luaUpdateForce( moLuaVirtualMachine& vm ) {
3918 
3919 
3920  return 0;
3921 
3922 }
3923 
3924 
3925 
3926 int moEffectParticlesSimple::luaShot( moLuaVirtualMachine& vm) {
3927 
3928  lua_State *state = (lua_State *) vm;
3929 
3930  if (lua_isboolean(state,1)) {
3931  bool vb = lua_toboolean(state,1);
3932  vb ? MODebug2->Push(moText("true")) : MODebug2->Push(moText("false"));
3933  } else {
3934  char *text = (char *) lua_tostring (state, 1);
3935  int shot_type = lua_tonumber (state, 2);
3936  int shot_file = lua_tonumber (state, 3);
3937 
3938  moText source_to_shot = moText(text);
3939  this->Shot( source_to_shot, shot_type, shot_file );
3940  }
3941 
3942  return 0;
3943 }
3944 
3945 int moEffectParticlesSimple::luaReInit(moLuaVirtualMachine& vm ) {
3946 
3947  lua_State *state = (lua_State *) vm;
3948 
3949  this->ReInit();
3950 
3951  return 0;
3952 }
2: Volumétrico. Los lugares de nacimientos están diseminados dentro del volumen del emisor aleatoriam...
moVector3f U
particle orientation
moParticlesCreationMethod
Creation Method.
2: Many Different Textures Image for each Particle ( taken from texturefolder )
1: accelerate, reach and stop instantly
double Alpha
Transparency of the particle.
void Interaction(moIODeviceManager *)
Interacción.
moParticlesCreationMethod m_CreationMethod
5: each particle attract each one to a dot of the tracker
1: Esfera (una esfera de "width" longitudes y "height" latitudes) 3D
double Mass
Mass in g of the particle.
virtual ~moEffectParticlesSimple()
Destructor.
MOboolean Init()
Inicialización.
0: One Same Texture Image for each Particle (taken from texture)
2: 2: Tubo ( un tubo de "width" facetas y "height" segmentos) 3D
moVector3f Pos3d
Position absolute.
1: Superficial. Los lugares de nacimientos están diseminados sobre la superficie del emisor aleatoria...
3: Line shape emitter (3d) vector line (x,y,z)
moEffectParticlesSimple
MO_PLG_API void DestroyEffectFactory()
moTimer Age
Age of the particle.
0: Alineado. Los lugares de nacimientos están alineados con el orden de los vertices del emisor...
0: Grilla (un rectángulo de "width" x "height") 2D
moParticlesSimpleAttractorMode
Attractor Mode.
moVector2f TSize
particle texture size
moParticlesSimpleEmitterType m_EmitterType
1: each particle attract perp to a face of the grid
moVector2f Size
particle size
moParticlesSimpleAttractorType m_AttractorType
MO_PLG_API moEffectFactory * CreateEffectFactory()
MOboolean Finish()
Finalizacion.
5: constant speed to attractortype
0: each particle attract diretly to the same point
moVector3f Velocity
Speed or Velocity vector.
moVector2f Pos
Particles Vectors.
moConfigDefinition * GetDefinition(moConfigDefinition *p_configdefinition)
Definicion de campos.
moTextureMemory * pTextureMemory
8: Círculo ( una ronda de "width"X"height" partículas )
moParticlesSimple * m_pLastBordParticle
moParticlesRandomMethod
Random Method.
moParticlesSimpleEmitterType
Emitter Type.
moParticlesSimpleAttractorMode m_AttractorMode
1: Same Texture Image Divided In Different Fragments for each Particle (taken from texture...
moDefineDynamicArray(moParticlesSimpleArray) moEffectParticlesSimpleFactory *m_EffectParticlesSimpleFactory
float ImageProportion
Texture image proportion Width / Height ....
MOint GLId2
para asociar la textura al momento de la creación
void Shot(moText source=moText(""), int shot_type=0, int shot_file=0)
Foto de la cámara.
void Update(moEventList *p_eventlist)
Actualización del ciclo de eventos.
moVector3f Rotation
Angle of the particle.
moVector3f Destination
Destination.
moParticlesRandomMethod m_RandomMethod
void ReInit()
Reiniciar el analisis de la imagen.
moVector3f dpdt
Differentials of position (speed) and velocity (acceleration)
moParticlesOrientationMode m_OrientationMode
5: Trackeador ( reservado para información de sensado )
MOint GLId
Unique ID of OpenGL Texture.
6: Trackeador2 ( reservado para información de sensado )
4: Punto ( colapsados en un punto )
int ScriptCalling(moLuaVirtualMachine &vm, int iFunctionNumber)
Llamada de scripts.
3: Many textures/particle to construct a patched texture one ( taken from texturefolder, build the one defined on texture parameter, or from a folder, call to Shot(source) then ReInit to build... )
double Scale
Scale of the particle.
bool Visible
Exists but is invisible.
moVector2f TCoord
texture coordinate
moParticlesSimpleAttractorType
Attractor Type.
moVector3f Force
Self force (propulsion) of the particle.
7: Espiral ( forma de espiral, "width" ángulos que forman "height" ciclos )
3: Central. Los lugares de nacimiento están colapsados en el centro del emisor.
void Draw(moTempo *, moEffectState *parentstate=NULL)
Dibujado.
moParticlesOrientationMode
Orientation Method.