aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/seg__remanence_8cpp-source.html
blob: 5d0594538e63e66113a30b4803610f3b6d988e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>seg_remanence.cpp</h1><a href="seg__remanence_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00006 <font class="comment">/* Copyright, 2000, 2001, 2002 Nevrax Ltd.</font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00009 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00010 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00011 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00012 <font class="comment"> * any later version.</font>
00013 <font class="comment"></font>
00014 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00015 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00017 <font class="comment"> * General Public License for more details.</font>
00018 <font class="comment"></font>
00019 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00020 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00021 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00022 <font class="comment"> * MA 02111-1307, USA.</font>
00023 <font class="comment"> */</font>
00024 
00025 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00026 
00027 <font class="preprocessor">#include "<a class="code" href="seg__remanence_8h.html">3d/seg_remanence.h</a>"</font>
00028 <font class="preprocessor">#include "<a class="code" href="seg__remanence__shape_8h.html">3d/seg_remanence_shape.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="vertex__buffer_8h.html">3d/vertex_buffer.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="driver_8h.html">3d/driver.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="scene_8h.html">3d/scene.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="anim__detail__trav_8h.html">3d/anim_detail_trav.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="skeleton__model_8h.html">3d/skeleton_model.h</a>"</font>
00034 
00035 
00036 
00037 
00038 <font class="keyword">namespace </font>NL3D
00039 {
00040 
00042 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a450">BuildHermiteVector</a>(<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;P0,
00043                                                            <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;P1,
00044                                                            <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;T0,
00045                                                            <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;T1,
00046                                                                          <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;dest,                                                                  
00047                                                            <font class="keywordtype">float</font> lambda
00048                                                            )
00049 {       
00050         <font class="keyword">const</font> <font class="keywordtype">float</font> lambda2 = lambda * lambda;
00051         <font class="keyword">const</font> <font class="keywordtype">float</font> lambda3 = lambda2 * lambda;
00052         <font class="keyword">const</font> <font class="keywordtype">float</font> h1 = 2 * lambda3 - 3 * lambda2 + 1; 
00053         <font class="keyword">const</font> <font class="keywordtype">float</font> h2 = - 2 * lambda3 + 3 * lambda2; 
00054         <font class="keyword">const</font> <font class="keywordtype">float</font> h3 = lambda3 - 2 * lambda2 + lambda; 
00055         <font class="keyword">const</font> <font class="keywordtype">float</font> h4 = lambda3 - lambda2;
00057         dest.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (h1 * P0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a> + h2 * P1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a> + h3 * T0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a> + h4 * T1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>,
00058                           h1 * P0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a> + h2 * P1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a> + h3 * T0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a> + h4 * T1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>,
00059                           h1 * P0.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> + h2 * P1.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> + h3 * T0.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> + h4 * T1.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a>);
00060 
00061 }
00062 
00063 <font class="comment">//===============================================================</font>
<a name="l00064"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z787_0">00064</a> CSegRemanence::CSegRemanence() : _NumSlice(0),
00065                                                                  _Started(false),
00066                                                                  _Stopping(false),
00067                                                                  _Restarted(false),
00068                                                                  _UnrollRatio(0),
00069                                                                  _AniMat(NULL)
00070 {       
00071         IAnimatable::resize(<a class="code" href="classNL3D_1_1CSegRemanence.html#s2s1">AnimValueLast</a>);
00072 }
00073 
00074 <font class="comment">//===============================================================</font>
<a name="l00075"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z787_1">00075</a> CSegRemanence::~CSegRemanence()
00076 {
00077         <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>;
00078         <font class="comment">// Auto detach me from skeleton. Must do it here, not in ~CTransform().</font>
00079         <font class="keywordflow">if</font>(_FatherSkeletonModel)
00080         {
00081                 <font class="comment">// detach me from the skeleton.</font>
00082                 <font class="comment">// Observers hierarchy is modified.</font>
00083                 <a class="code" href="classNL3D_1_1CTransform.html#z851_7">_FatherSkeletonModel</a>-&gt;detachSkeletonSon(<font class="keyword">this</font>);
00084                 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CTransform.html#z851_7">_FatherSkeletonModel</a>==NULL);
00085         }
00086 }
00087 
00088 <font class="comment">//===============================================================</font>
<a name="l00089"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z787_2">00089</a> CSegRemanence::CSegRemanence(CSegRemanence &amp;other)      : CTransformShape(other), _AniMat(NULL)
00090 {
00091         <a class="code" href="classNL3D_1_1CSegRemanence.html#c1">copyFromOther</a>(other);
00092 }
00093 
00094 <font class="comment">//===============================================================</font>
<a name="l00095"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z787_3">00095</a> CSegRemanence &amp;CSegRemanence::operator = (CSegRemanence &amp;other)
00096 {
00097         <font class="keywordflow">if</font> (<font class="keyword">this</font> != &amp;other)
00098         {       
00099                 (<a class="code" href="classNL3D_1_1CTransformShape.html#b0">CTransformShape</a> &amp;) *<font class="keyword">this</font> = (<a class="code" href="classNL3D_1_1CTransformShape.html#b0">CTransformShape</a> &amp;) other; <font class="comment">// copy base</font>
00100                 <a class="code" href="classNL3D_1_1CSegRemanence.html#c1">copyFromOther</a>(other);
00101         }
00102         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00103 }
00104 
00105 <font class="comment">//===============================================================</font>
<a name="l00106"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#c1">00106</a> <font class="keywordtype">void</font> CSegRemanence::copyFromOther(CSegRemanence &amp;other)
00107 {
00108         <font class="keywordflow">if</font> (<font class="keyword">this</font> == &amp;other) <font class="keywordflow">return</font>;
00109         
00110         CAnimatedMaterial   *otherMat = other._AniMat != NULL ? <font class="keyword">new</font> CAnimatedMaterial(*other._AniMat)
00111                                                                                                                   : NULL;
00112         <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>;
00113         <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a> = otherMat;
00114 
00115         <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>        = other._Ribbons; <font class="comment">// sampled positions at each extremities of segment</font>
00116         <a class="code" href="classNL3D_1_1CSegRemanence.html#o1">_NumSlice</a>       = other._NumSlice;
00117         <a class="code" href="classNL3D_1_1CSegRemanence.html#o2">_NumCorners</a> = other._NumCorners;
00118         <a class="code" href="classNL3D_1_1CSegRemanence.html#o3">_Started</a>    = other._Started;
00119         <a class="code" href="classNL3D_1_1CSegRemanence.html#o5">_Restarted</a>  = other._Restarted;
00120         <a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a>   = other._Stopping;
00121         <a class="code" href="classNL3D_1_1CSegRemanence.html#o6">_StartDate</a>  = other._StartDate;
00122         <a class="code" href="classNL3D_1_1CSegRemanence.html#o7">_CurrDate</a>   = other._CurrDate;
00123         
00124 }
00125 
00126 <font class="comment">//===============================================================</font>
<a name="l00127"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#d0">00127</a> <font class="keywordtype">void</font> CSegRemanence::registerBasic()
00128 {
00129         CMOT::registerModel(<a class="code" href="namespaceNL3D.html#a457">SegRemanenceShapeId</a>, <a class="code" href="namespaceNL3D.html#a277">TransformShapeId</a>, CSegRemanence::creator);     
00130 <font class="comment">//      CMOT::registerObs (HrcTravId, SegRemanenceShapeId, CSegRemanenceHrcObs::creator);</font>
00131         CMOT::registerObs(<a class="code" href="namespaceNL3D.html#a3">AnimDetailTravId</a>, <a class="code" href="namespaceNL3D.html#a457">SegRemanenceShapeId</a>, CSegRemanenceAnimDetailObs::creator);
00132 }
00133 
00134 
00135 <font class="comment">//===============================================================</font>
<a name="l00136"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#a0">00136</a> <font class="keywordtype">void</font> CSegRemanence::render(IDriver *drv, CVertexBuffer &amp;vb, CPrimitiveBlock &amp;pb, CMaterial &amp;mat)
00137 {
00138         CSegRemanenceShape *srs = NLMISC::safe_cast&lt;CSegRemanenceShape *&gt;((IShape *) <a class="code" href="classNL3D_1_1CTransformShape.html#m0">Shape</a>);            
00139         <font class="keyword">const</font> uint vertexSize = vb.getVertexSize();
00140         uint8 *datas = (uint8 *) vb.getVertexCoordPointer();
00141         uint numCorners = <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>.size();
00142         <font class="keywordflow">for</font>(uint k = 0; k &lt; numCorners; ++k)
00143         {
00144                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>[k].fillVB(datas, vertexSize, srs-&gt;getNumSlices(), srs-&gt;getSliceTime());
00145                 datas += (<a class="code" href="classNL3D_1_1CSegRemanence.html#o1">_NumSlice</a> + 1) * vertexSize;
00146         }       
00147         
00148         <font class="comment">// roll / unroll using texture matrix</font>
00149         CMatrix texMat; 
00150         texMat.setPos(<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(1.f - <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a>, 0, 0));
00151         <font class="keywordflow">if</font> (mat.getTexture(0) != NULL)
00152                 mat.setUserTexMat(0, texMat);
00153         
00154         
00155         
00156         drv-&gt;activeVertexBuffer(vb);    
00157         drv-&gt;render(pb, mat);
00158 
00159         CScene *scene = NLMISC::safe_cast&lt;ITravScene *&gt;(<a class="code" href="classNL3D_1_1CTransform.html#n0">_HrcObs</a>-&gt;Trav)-&gt;Scene;
00160         <font class="comment">// change unroll ratio</font>
00161         <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a>)
00162         {
00163                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> != 1.f)
00164                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(1.f, <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> + scene-&gt;getEllapsedTime() / (srs-&gt;getNumSlices() * srs-&gt;getSliceTime()));
00165         }
00166         <font class="keywordflow">else</font>
00167         {
00168                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> = std::max(0.f, <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> - srs-&gt;getRollupRatio() * scene-&gt;getEllapsedTime() / (srs-&gt;getNumSlices() * srs-&gt;getSliceTime()));
00169                 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> == 0.f)
00170                 {
00171                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a> = <font class="keyword">false</font>;
00172                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o3">_Started</a> = <font class="keyword">false</font>;
00173                 }
00174         }
00175 }
00176 
00177 <font class="comment">//===============================================================</font>
<a name="l00178"></a><a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#a0">00178</a> CSegRemanence::CRibbon::CRibbon() : _LastSamplingDate(0)
00179 {
00180 }
00181 
00182 <font class="comment">//===============================================================</font>
<a name="l00183"></a><a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#a3">00183</a> <font class="keywordtype">void</font> CSegRemanence::CRibbon::fillVB(uint8 *dest, uint <a class="code" href="driver__opengl__extension__def_8h.html#a374">stride</a>, uint nbSegs, <font class="keywordtype">float</font> sliceTime)
00184 {               
00185         TSampledPosVect::iterator currIt      = <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.begin();                        
00186 
00187         <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> t0 = (currIt + 1)-&gt;Pos - currIt-&gt;Pos;
00188         <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> t1 = 0.5f * ((currIt + 2)-&gt;Pos - currIt-&gt;Pos);
00189 
00190         uint leftToDo = nbSegs + 1;
00191 
00192         <font class="keywordtype">float</font> lambda = 0.f;
00193         <font class="keywordtype">float</font> lambdaStep = 1.f;
00194 
00195 <font class="comment">/*      nlinfo("===============================");</font>
00196 <font class="comment">        for(uint k = 0; k &lt; _Ribbon.size(); ++k)</font>
00197 <font class="comment">        {</font>
00198 <font class="comment">                nlinfo("pos = (%.2f, %.2f, %.2f)", _Ribbon[k].Pos.x, _Ribbon[k].Pos.y, _Ribbon[k].Pos.z);</font>
00199 <font class="comment">        }*/</font>
00200 
00201         <font class="keywordflow">for</font> (;;)
00202         {               
00203                 <font class="keywordtype">float</font> dt = currIt-&gt;SamplingDate - (currIt + 1)-&gt;SamplingDate;
00204 
00205                 <font class="keywordflow">if</font> (dt &lt; 10E-6f) <font class="comment">// we reached the start of ribbon</font>
00206                 {
00207 
00208                         <font class="keywordflow">do</font>
00209                         {
00210                                 (<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;) *dest = currIt-&gt;Pos;
00211                                 dest  += <a class="code" href="driver__opengl__extension__def_8h.html#a374">stride</a>;
00212                         }
00213                         <font class="keywordflow">while</font> (--leftToDo);                     
00214                         <font class="keywordflow">return</font>;
00215                 }
00216 
00217                 <font class="keywordtype">float</font> newLambdaStep = sliceTime / dt;
00218                 <font class="comment">// readapt lambda</font>
00219                 lambda *= newLambdaStep / lambdaStep;
00220                 lambdaStep = newLambdaStep;
00221                 <font class="keywordflow">for</font>(;;)
00222                 {
00223                         <font class="keywordflow">if</font> (lambda &gt;= 1.f) <font class="keywordflow">break</font>;
00225                         <a class="code" href="namespaceNL3D.html#a450">BuildHermiteVector</a>(currIt-&gt;Pos, (currIt + 1)-&gt;Pos, t0, t1, (<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;) *dest, lambda);
00226                         dest  += <a class="code" href="driver__opengl__extension__def_8h.html#a374">stride</a>;
00227                         -- leftToDo;
00228                         <font class="keywordflow">if</font> (!leftToDo) <font class="keywordflow">return</font>;                                                                                          
00229                         lambda += lambdaStep;                   
00230                 }
00231                 
00232                 lambda -= 1.f;
00233 
00234                 <font class="comment">// Start new segment and compute new tangents</font>
00235                 t0 = t1;
00236                 ++currIt;               
00237                 t1 = 0.5f * ((currIt + 2)-&gt;Pos - currIt-&gt;Pos);
00238         }        
00239 }
00240 
00241 <font class="comment">//===============================================================</font>
<a name="l00242"></a><a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#a4">00242</a> <font class="keywordtype">void</font> CSegRemanence::CRibbon::duplicateFirstPos()
00243 {
00244         uint ribSize = <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.size();
00245         <font class="keywordflow">for</font>(uint k = 1; k &lt; ribSize; ++k)
00246         {
00247                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>[k] = <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>[0];
00248         }
00249 }
00250 
00251 <font class="comment">//===============================================================</font>
<a name="l00252"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#a2">00252</a> <font class="keywordtype">void</font> CSegRemanence::setupFromShape()
00253 {
00254         CSegRemanenceShape *srs = NLMISC::safe_cast&lt;CSegRemanenceShape *&gt;((IShape *) <a class="code" href="classNL3D_1_1CTransformShape.html#m0">Shape</a>);            
00255         <font class="keywordflow">if</font> (srs-&gt;getNumCorners() != <a class="code" href="classNL3D_1_1CSegRemanence.html#o2">_NumCorners</a> || srs-&gt;getNumSlices() != <a class="code" href="classNL3D_1_1CSegRemanence.html#o1">_NumSlice</a>)
00256         {
00257                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>.resize(srs-&gt;getNumCorners());
00258                 <font class="keywordflow">for</font>(uint k = 0; k &lt; <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>.size(); ++k)
00259                 {
00260                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>[k].setNumSlices(srs-&gt;getNumSlices());
00261                 }               
00262                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o2">_NumCorners</a> = srs-&gt;getNumCorners();
00263                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o1">_NumSlice</a>  = srs-&gt;getNumSlices();
00264         }
00265         <a class="code" href="classNL3D_1_1CSegRemanence.html#c0">updateOpacityFromShape</a>();
00266 }
00267 
00268 
00269 <font class="comment">//===============================================================</font>
<a name="l00270"></a><a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#a1">00270</a> <font class="keywordtype">void</font> CSegRemanence::CRibbon::setNumSlices(uint numSegs)
00271 {       
00272         <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.resize(numSegs + 3);
00273 }
00274 
00275 <font class="comment">//===============================================================</font>
<a name="l00276"></a><a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#a2">00276</a> <font class="keywordtype">void</font> CSegRemanence::CRibbon::samplePos(<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;pos, <font class="keywordtype">float</font> date, <font class="keywordtype">float</font> sliceDuration)
00277 {
00278         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.size() != 0);
00279         <font class="keywordflow">if</font> (date - <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o1">_LastSamplingDate</a> &gt; sliceDuration)
00280         {
00281                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.pop_back();
00282                 CSampledPos sp(pos, date);
00283                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.push_front(sp);
00284                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o1">_LastSamplingDate</a> = date;
00285         }
00286         <font class="keywordflow">else</font>
00287         {
00288                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.front().Pos = pos;
00289                 <a class="code" href="classNL3D_1_1CSegRemanence_1_1CRibbon.html#o0">_Ribbon</a>.front().SamplingDate = date;
00290         }
00291 }
00292 
00293 <font class="comment">//===============================================================</font>
<a name="l00294"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#a1">00294</a> <font class="keywordtype">void</font> CSegRemanence::samplePos(<font class="keywordtype">float</font> date)
00295 {
00296         <font class="keywordflow">if</font> (_Started)
00297         {       
00298                 IBaseHrcObs *bho = (IBaseHrcObs *) <a class="code" href="classNL3D_1_1IModel.html#b3">getObs</a>(<a class="code" href="namespaceNL3D.html#a41">HrcTravId</a>);
00299                 CSegRemanenceShape *srs = NLMISC::safe_cast&lt;CSegRemanenceShape *&gt;((IShape *) <a class="code" href="classNL3D_1_1CTransformShape.html#m0">Shape</a>);
00300                 uint numCorners = <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>.size();
00301                 <font class="keywordflow">for</font>(uint k = 0; k &lt; numCorners; ++k)
00302                 {               
00303                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>[k].samplePos(bho-&gt;WorldMatrix * srs-&gt;getCorner(k), date, srs-&gt;getSliceTime());
00304                 }
00305                 <font class="keywordflow">if</font> (_Restarted)
00306                 {
00307                         <font class="keywordflow">for</font>(uint k = 0; k &lt; numCorners; ++k)
00308                         {
00309                                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o0">_Ribbons</a>[k].duplicateFirstPos();
00310                         }
00311                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o5">_Restarted</a> = <font class="keyword">false</font>;
00312                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o6">_StartDate</a> = date;
00313                 }
00314                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o7">_CurrDate</a> = date;
00315         }
00316 }
00317 
00318 <font class="comment">//===============================================================</font>
00319 <font class="comment">/*</font>
00320 <font class="comment">void CSegRemanenceHrcObs::traverse(IObs *caller)</font>
00321 <font class="comment">{</font>
00322 <font class="comment">        CTransformHrcObs::traverse (caller);</font>
00323 <font class="comment">        CSegRemanence *sr = static_cast&lt;CSegRemanence *&gt;(this-&gt;Model);</font>
00324 <font class="comment">        if (sr-&gt;isStarted())</font>
00325 <font class="comment">        {       </font>
00326 <font class="comment">                CScene *scene = NLMISC::safe_cast&lt;ITravScene *&gt;(Trav)-&gt;Scene;</font>
00327 <font class="comment">                if (scene-&gt;getNumRender() != (_LastSampleFrame + 1))</font>
00328 <font class="comment">                {</font>
00329 <font class="comment">                        if (!sr-&gt;isStopping())</font>
00330 <font class="comment">                        {                       </font>
00331 <font class="comment">                                // if wasn't visible at previous frame, must invalidate position</font>
00332 <font class="comment">                                sr-&gt;restart();</font>
00333 <font class="comment">                        }</font>
00334 <font class="comment">                        else</font>
00335 <font class="comment">                        {</font>
00336 <font class="comment">                                // ribbon started unrolling when it disapperaed from screen so simply remove it</font>
00337 <font class="comment">                                sr-&gt;stopNoUnroll();</font>
00338 <font class="comment">                        }</font>
00339 <font class="comment">                }               </font>
00340 <font class="comment">                _LastSampleFrame = scene-&gt;getNumRender();</font>
00341 <font class="comment">                sr-&gt;setupFromShape();</font>
00342 <font class="comment">                sr-&gt;samplePos((float) scene-&gt;getCurrentTime());</font>
00343 <font class="comment">        }</font>
00344 <font class="comment">}</font>
00345 <font class="comment">*/</font>
00346 
00347 <font class="comment">/*</font>
00348 <font class="comment">//===============================================================</font>
00349 <font class="comment">CSegRemanenceHrcObs::CSegRemanenceHrcObs() : _LastSampleFrame(0)</font>
00350 <font class="comment">{       </font>
00351 <font class="comment">}</font>
00352 <font class="comment">*/</font>
00353 
00354 <font class="comment">//===============================================================</font>
<a name="l00355"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z788_1">00355</a> <font class="keywordtype">void</font> CSegRemanence::start()
00356 {
00357         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CSegRemanence.html#o3">_Started</a> &amp;&amp; !<a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a>) <font class="keywordflow">return</font>;
00358         <a class="code" href="classNL3D_1_1CSegRemanence.html#z788_6">restart</a>();              
00359 }
00360 
00361 <font class="comment">//===============================================================</font>
<a name="l00362"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z788_6">00362</a> <font class="keywordtype">void</font> CSegRemanence::restart()
00363 {
00364         CSegRemanenceShape *srs = NLMISC::safe_cast&lt;CSegRemanenceShape *&gt;((IShape *) <a class="code" href="classNL3D_1_1CTransformShape.html#m0">Shape</a>);    
00365         <font class="keywordflow">if</font> (!srs-&gt;getTextureShifting())
00366         {       
00367                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> = 1.f;
00368         }
00369         <font class="keywordflow">else</font>
00370         {
00371                 <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a>)
00372                         <a class="code" href="classNL3D_1_1CSegRemanence.html#o8">_UnrollRatio</a> = 0.f;
00373         }
00374         <a class="code" href="classNL3D_1_1CSegRemanence.html#o3">_Started</a> = <a class="code" href="classNL3D_1_1CSegRemanence.html#o5">_Restarted</a> = <font class="keyword">true</font>;
00375         <a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a> = <font class="keyword">false</font>;      
00376 }
00377 
00378 <font class="comment">//===============================================================</font>
<a name="l00379"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z788_2">00379</a> <font class="keywordtype">void</font> CSegRemanence::stop()
00380 {
00381         <a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a> = <font class="keyword">true</font>;
00382 }
00383 
00384 <font class="comment">//===============================================================</font>
<a name="l00385"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#z788_3">00385</a> <font class="keywordtype">void</font> CSegRemanence::stopNoUnroll()
00386 {
00387         <a class="code" href="classNL3D_1_1CSegRemanence.html#o3">_Started</a> = <a class="code" href="classNL3D_1_1CSegRemanence.html#o5">_Restarted</a> = <a class="code" href="classNL3D_1_1CSegRemanence.html#o4">_Stopping</a> = <font class="keyword">false</font>;
00388 }
00389 
00390 <font class="comment">//===============================================================</font>
<a name="l00391"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#c0">00391</a> <font class="keywordtype">void</font> CSegRemanence::updateOpacityFromShape()
00392 {
00393         CSegRemanenceShape *srs = NLMISC::safe_cast&lt;CSegRemanenceShape *&gt;((IShape *) <a class="code" href="classNL3D_1_1CTransformShape.html#m0">Shape</a>);
00394         <font class="keywordtype">bool</font> transparent = srs-&gt;getMaterial().getBlend();
00395         <a class="code" href="classNL3D_1_1CTransform.html#a0">setTransparency</a>(transparent);
00396         <a class="code" href="classNL3D_1_1CTransform.html#a1">setOpacity</a>(!transparent);
00397 }
00398 
00399 <font class="comment">//===============================================================</font>
<a name="l00400"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#a3">00400</a> <font class="keywordtype">void</font> CSegRemanence::setAnimatedMaterial(CAnimatedMaterial *mat)
00401 {
00402         <font class="keywordflow">if</font> (mat == <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>) <font class="keywordflow">return</font>;
00403         <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>;
00404         <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a> = mat;
00405         <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>-&gt;setFather(<font class="keyword">this</font>, <a class="code" href="classNL3D_1_1CSegRemanence.html#s2s0">OwnerBit</a>);
00406 }
00407 
00408 <font class="comment">//===============================================================</font>
<a name="l00409"></a><a class="code" href="classNL3D_1_1CSegRemanence.html#a5">00409</a> <font class="keywordtype">void</font> CSegRemanence::registerToChannelMixer(CChannelMixer *chanMixer, <font class="keyword">const</font> std::string &amp;prefix)
00410 {       
00411         CTransformShape::registerToChannelMixer(chanMixer, prefix);
00412         <font class="keywordflow">if</font> (_AniMat)
00413         {
00414                 <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>-&gt;registerToChannelMixer(chanMixer, prefix + <a class="code" href="classNL3D_1_1CSegRemanence.html#o9">_AniMat</a>-&gt;getMaterialName() + <font class="stringliteral">"."</font>)   ;
00415         }
00416 }
00417 
00418 <font class="comment">//===============================================================</font>
<a name="l00419"></a><a class="code" href="classNL3D_1_1CSegRemanenceAnimDetailObs.html#a1">00419</a> <font class="keywordtype">void</font> CSegRemanenceAnimDetailObs::traverse(IObs *caller)
00420 {
00421         CTransformAnimDetailObs::traverse(caller);
00422         CSegRemanence *sr = NLMISC::safe_cast&lt;CSegRemanence *&gt;(Model);
00423         <font class="keywordflow">if</font> (sr-&gt;isStarted())
00424         {       
00427 
00428                 CScene *scene = NLMISC::safe_cast&lt;ITravScene *&gt;(Trav)-&gt;Scene;
00429                 <font class="keywordflow">if</font> (scene-&gt;getNumRender() != (<a class="code" href="classNL3D_1_1CSegRemanenceAnimDetailObs.html#o0">_LastSampleFrame</a> + 1))
00430                 {
00431                         <font class="keywordflow">if</font> (!sr-&gt;isStopping())
00432                         {                       
00433                                 <font class="comment">// if wasn't visible at previous frame, must invalidate position</font>
00434                                 sr-&gt;restart();
00435                         }
00436                         <font class="keywordflow">else</font>
00437                         {
00438                                 <font class="comment">// ribbon started unrolling when it disapperaed from screen so simply remove it</font>
00439                                 sr-&gt;stopNoUnroll();
00440                         }
00441                 }               
00442                 <a class="code" href="classNL3D_1_1CSegRemanenceAnimDetailObs.html#o0">_LastSampleFrame</a> = scene-&gt;getNumRender();
00443                 sr-&gt;setupFromShape();
00444                 sr-&gt;samplePos((<font class="keywordtype">float</font>) scene-&gt;getCurrentTime());
00445 
00448 
00449         
00450                 <font class="comment">// test if animated material must be updated.</font>
00451                 <font class="keywordflow">if</font>(sr-&gt;IAnimatable::isTouched(CSegRemanence::OwnerBit))
00452                 {
00453                         <font class="keywordflow">if</font> (sr-&gt;getAnimatedMaterial())
00454                                 sr-&gt;getAnimatedMaterial()-&gt;update();                    
00455                         sr-&gt;clearAnimatedMatFlag();
00456                 }
00457         }
00458 }
00459 
<a name="l00460"></a><a class="code" href="classNL3D_1_1CSegRemanenceAnimDetailObs.html#a0">00460</a> CSegRemanenceAnimDetailObs::CSegRemanenceAnimDetailObs() : _LastSampleFrame(0)
00461 {       
00462 }
00463 
00464 
00465 
00466 }
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>