aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/animation__optimizer_8cpp-source.html
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
committerneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
commit0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch)
tree2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/animation__optimizer_8cpp-source.html
downloadnevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz
nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip
Initial commit
Diffstat (limited to 'docs/doxygen/nel/animation__optimizer_8cpp-source.html')
-rw-r--r--docs/doxygen/nel/animation__optimizer_8cpp-source.html694
1 files changed, 694 insertions, 0 deletions
diff --git a/docs/doxygen/nel/animation__optimizer_8cpp-source.html b/docs/doxygen/nel/animation__optimizer_8cpp-source.html
new file mode 100644
index 00000000..44086727
--- /dev/null
+++ b/docs/doxygen/nel/animation__optimizer_8cpp-source.html
@@ -0,0 +1,694 @@
+<!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="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
+ <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
+ <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
+ </TABLE>
+ </TD></TR></TABLE></TD></TR></TABLE>
+ <!------ End Box ------>
+
+ </TD>
+ <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
+
+<!-- title -->
+<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
+<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
+</td><td><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/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:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
+<hr><h1>animation_optimizer.cpp</h1><a href="animation__optimizer_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
+00007 <font class="comment">/* Copyright, 2000-2002 Nevrax Ltd.</font>
+00008 <font class="comment"> *</font>
+00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
+00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
+00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
+00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
+00013 <font class="comment"> * any later version.</font>
+00014 <font class="comment"></font>
+00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
+00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
+00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
+00018 <font class="comment"> * General Public License for more details.</font>
+00019 <font class="comment"></font>
+00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
+00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
+00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
+00023 <font class="comment"> * MA 02111-1307, USA.</font>
+00024 <font class="comment"> */</font>
+00025
+00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
+00027
+00028 <font class="preprocessor">#include "<a class="code" href="animation__optimizer_8h.html">3d/animation_optimizer.h</a>"</font>
+00029 <font class="preprocessor">#include "<a class="code" href="mem__stream_8h.html">nel/misc/mem_stream.h</a>"</font>
+00030 <font class="preprocessor">#include "<a class="code" href="vectord_8h.html">nel/misc/vectord.h</a>"</font>
+00031 <font class="preprocessor">#include "<a class="code" href="track_8h.html">3d/track.h</a>"</font>
+00032 <font class="preprocessor">#include "<a class="code" href="track__keyframer_8h.html">3d/track_keyframer.h</a>"</font>
+00033 <font class="preprocessor">#include "<a class="code" href="animation_8h.html">3d/animation.h</a>"</font>
+00034 <font class="preprocessor">#include "<a class="code" href="track__sampled__quat_8h.html">3d/track_sampled_quat.h</a>"</font>
+00035 <font class="preprocessor">#include "<a class="code" href="track__sampled__vector_8h.html">3d/track_sampled_vector.h</a>"</font>
+00036
+00037
+00038 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
+00039 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
+00040
+00041
+00042 <font class="keyword">namespace </font>NL3D
+00043 {
+00044
+00045
+00046 <font class="comment">// ***************************************************************************</font>
+<a name="l00047"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a0">00047</a> CAnimationOptimizer::CAnimationOptimizer()
+00048 {
+00049 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>= 30;
+00050 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>= 1.0 - 0.0001;
+00051 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>= 1.0 - 0.000001;
+00052 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>= 0.001;
+00053 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>= 0.0001;
+00054 }
+00055
+00056
+00057 <font class="comment">// ***************************************************************************</font>
+<a name="l00058"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a1">00058</a> <font class="keywordtype">void</font> CAnimationOptimizer::setQuaternionThreshold(<font class="keywordtype">double</font> lowPrecThre, <font class="keywordtype">double</font> highPrecThre)
+00059 {
+00060 <a class="code" href="debug_8h.html#a6">nlassert</a>(lowPrecThre&gt;=0);
+00061 <a class="code" href="debug_8h.html#a6">nlassert</a>(highPrecThre&gt;=0);
+00062 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>= 1.0 - lowPrecThre;
+00063 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>= 1.0 - highPrecThre;
+00064 }
+00065
+00066
+00067 <font class="comment">// ***************************************************************************</font>
+<a name="l00068"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a2">00068</a> <font class="keywordtype">void</font> CAnimationOptimizer::setVectorThreshold(<font class="keywordtype">double</font> lowPrecThre, <font class="keywordtype">double</font> highPrecThre)
+00069 {
+00070 <a class="code" href="debug_8h.html#a6">nlassert</a>(lowPrecThre&gt;=0);
+00071 <a class="code" href="debug_8h.html#a6">nlassert</a>(highPrecThre&gt;=0);
+00072 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>= lowPrecThre;
+00073 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>= highPrecThre;
+00074 }
+00075
+00076
+00077 <font class="comment">// ***************************************************************************</font>
+<a name="l00078"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a5">00078</a> <font class="keywordtype">void</font> CAnimationOptimizer::setSampleFrameRate(<font class="keywordtype">float</font> frameRate)
+00079 {
+00080 <a class="code" href="debug_8h.html#a6">nlassert</a>(frameRate&gt;0);
+00081 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>= frameRate;
+00082 }
+00083
+00084
+00085 <font class="comment">// ***************************************************************************</font>
+<a name="l00086"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a6">00086</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimize(<font class="keyword">const</font> CAnimation &amp;animIn, CAnimation &amp;animOut)
+00087 {
+00088 <font class="comment">// reset animOut</font>
+00089 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(animOut);
+00090
+00091 <font class="comment">// Parse all tracks of the animation.</font>
+00092 set&lt;string&gt; setString;
+00093 animIn.getTrackNames (setString);
+00094 set&lt;string&gt;::iterator it;
+00095
+00096 <font class="keywordflow">for</font>(it=setString.begin();it!=setString.end();it++)
+00097 {
+00098 <font class="keyword">const</font> string &amp;trackName= *it;
+00099 uint trackId= animIn.getIdTrackByName(trackName);
+00100 <a class="code" href="debug_8h.html#a6">nlassert</a>(trackId!=CAnimation::NotFound);
+00101 <font class="keyword">const</font> ITrack *track= animIn.getTrack(trackId);
+00102
+00103 <font class="comment">// If the track is optimisable.</font>
+00104 ITrack *newTrack;
+00105 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c1">isTrackOptimisable</a>(track))
+00106 {
+00107 <font class="comment">// choose the threshold according to precision wanted</font>
+00108 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c3">isLowPrecisionTrack</a>(trackName) )
+00109 {
+00110 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o1">_QuaternionThresholdLowPrec</a>;
+00111 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o4">_VectorThresholdLowPrec</a>;
+00112 }
+00113 <font class="keywordflow">else</font>
+00114 {
+00115 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o2">_QuaternionThresholdHighPrec</a>;
+00116 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o5">_VectorThresholdHighPrec</a>;
+00117 }
+00118
+00119 <font class="comment">// optimize it.</font>
+00120 newTrack= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c2">optimizeTrack</a>(track);
+00121 }
+00122 <font class="keywordflow">else</font>
+00123 {
+00124 <font class="comment">// just clone it.</font>
+00125 newTrack= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">cloneTrack</a>(track);
+00126 }
+00127
+00128 <font class="comment">// Add it to the animation</font>
+00129 animOut.addTrack(trackName, newTrack);
+00130 }
+00131
+00132 <font class="comment">// Set min animation length</font>
+00133 animOut.setMinEndTime (animIn.getEndTime ());
+00134 <a class="code" href="debug_8h.html#a6">nlassert</a> (animOut.getEndTime() == animIn.getEndTime());
+00135 }
+00136
+00137 <font class="comment">// ***************************************************************************</font>
+<a name="l00138"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">00138</a> ITrack *CAnimationOptimizer::cloneTrack(<font class="keyword">const</font> ITrack *trackIn)
+00139 {
+00140 CMemStream memStream;
+00141
+00142 <font class="comment">// write to the stream.</font>
+00143 ITrack *trackInSerial= const_cast&lt;ITrack*&gt;(trackIn);
+00144 memStream.serialPolyPtr(trackInSerial);
+00145
+00146 <font class="comment">// read from the stream.</font>
+00147 memStream.invert();
+00148 ITrack *ret= NULL;
+00149 memStream.serialPolyPtr(ret);
+00150
+00151 <font class="keywordflow">return</font> ret;
+00152 }
+00153
+00154
+00155 <font class="comment">// ***************************************************************************</font>
+<a name="l00156"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c1">00156</a> <font class="keywordtype">bool</font> CAnimationOptimizer::isTrackOptimisable(<font class="keyword">const</font> ITrack *trackIn)
+00157 {
+00158 <a class="code" href="debug_8h.html#a6">nlassert</a>(trackIn);
+00159
+00160 <font class="comment">// If the track is a Linear, Bezier or a TCB track, suppose we can optimize it. Constant may not be interressant....</font>
+00161 <font class="keywordflow">if</font>( dynamic_cast&lt;const CTrackKeyFramerTCBQuat*&gt;(trackIn) ||
+00162 dynamic_cast&lt;const CTrackKeyFramerBezierQuat*&gt;(trackIn) ||
+00163 dynamic_cast&lt;const CTrackKeyFramerLinearQuat*&gt;(trackIn) )
+00164 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00165
+00166 <font class="comment">// If the track is a Linear, Bezier or a TCB track, suppose we can optimize it. Constant may not be interressant....</font>
+00167 <font class="keywordflow">if</font>( dynamic_cast&lt;const CTrackKeyFramerTCBVector*&gt;(trackIn) ||
+00168 dynamic_cast&lt;const CTrackKeyFramerBezierVector*&gt;(trackIn) ||
+00169 dynamic_cast&lt;const CTrackKeyFramerLinearVector*&gt;(trackIn) )
+00170 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00171
+00172 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00173 }
+00174
+00175
+00176 <font class="comment">// ***************************************************************************</font>
+<a name="l00177"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c2">00177</a> ITrack *CAnimationOptimizer::optimizeTrack(<font class="keyword">const</font> ITrack *trackIn)
+00178 {
+00179 <font class="comment">// Get track param.</font>
+00180 <font class="keywordtype">float</font> beginTime= trackIn-&gt;getBeginTime();
+00181 <font class="keywordtype">float</font> endTime= trackIn-&gt;getEndTime();
+00182 <a class="code" href="debug_8h.html#a6">nlassert</a>(endTime&gt;=beginTime);
+00183
+00184 <font class="comment">// Get num Sample </font>
+00185 uint numSamples= (uint)ceil( (endTime-beginTime)*<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o0">_SampleFrameRate</a>);
+00186 numSamples= max(1U, numSamples);
+00187 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples&lt;65535);
+00188
+00189
+00190 <font class="comment">// Optimize Quaternion track??</font>
+00191 <font class="comment">//================</font>
+00192 <font class="keywordflow">if</font>( dynamic_cast&lt;const CAnimatedValueQuat *&gt;(&amp;trackIn-&gt;getValue()) )
+00193 {
+00194 <font class="comment">// sample the animation. Store result in _TimeList/_QuatKeyList</font>
+00195 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_0">sampleQuatTrack</a>(trackIn, beginTime, endTime, numSamples);
+00196
+00197 <font class="comment">// check if the sampled track can be reduced to a TrackDefaultQuat. Test _QuatKeyList.</font>
+00198 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_1">testConstantQuatTrack</a>() )
+00199 {
+00200 <font class="comment">// create a default Track Quat.</font>
+00201 CTrackDefaultQuat *trackDefault= <font class="keyword">new</font> CTrackDefaultQuat;
+00202 <font class="comment">// setup the uniform value.</font>
+00203 trackDefault-&gt;setValue(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0]);
+00204
+00205 <font class="comment">// return the result.</font>
+00206 <font class="keywordflow">return</font> trackDefault;
+00207 }
+00208 <font class="comment">// else optimize the sampled animation, and build.</font>
+00209 <font class="keywordflow">else</font>
+00210 {
+00211 <font class="comment">// optimize.</font>
+00212 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_2">optimizeQuatTrack</a>();
+00213
+00214 <font class="comment">// Create a sampled quaternion track</font>
+00215 CTrackSampledQuat *trackSQ= <font class="keyword">new</font> CTrackSampledQuat;
+00216
+00217 <font class="comment">// Copy loop from track.</font>
+00218 trackSQ-&gt;setLoopMode(trackIn-&gt;getLoopMode());
+00219
+00220 <font class="comment">// Build it.</font>
+00221 trackSQ-&gt;build(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>, beginTime, endTime);
+00222
+00223 <font class="comment">// return result.</font>
+00224 <font class="keywordflow">return</font> trackSQ;
+00225 }
+00226 }
+00227 <font class="comment">// Optimize Position track??</font>
+00228 <font class="comment">//================</font>
+00229 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( dynamic_cast&lt;const CAnimatedValueVector *&gt;(&amp;trackIn-&gt;getValue()) )
+00230 {
+00231 <font class="comment">// sample the animation. Store result in _TimeList/_VectorKeyList</font>
+00232 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_0">sampleVectorTrack</a>(trackIn, beginTime, endTime, numSamples);
+00233
+00234 <font class="comment">// check if the sampled track can be reduced to a TrackDefaultVector. Test _VectorKeyList.</font>
+00235 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_1">testConstantVectorTrack</a>() )
+00236 {
+00237 <font class="comment">// create a default Track Vector.</font>
+00238 CTrackDefaultVector *trackDefault= <font class="keyword">new</font> CTrackDefaultVector;
+00239 <font class="comment">// setup the uniform value.</font>
+00240 trackDefault-&gt;setValue(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0]);
+00241
+00242 <font class="comment">// return the result.</font>
+00243 <font class="keywordflow">return</font> trackDefault;
+00244 }
+00245 <font class="comment">// else optimize the sampled animation, and build.</font>
+00246 <font class="keywordflow">else</font>
+00247 {
+00248 <font class="comment">// optimize.</font>
+00249 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_2">optimizeVectorTrack</a>();
+00250
+00251 <font class="comment">// Create a sampled Vector track</font>
+00252 CTrackSampledVector *trackSV= <font class="keyword">new</font> CTrackSampledVector;
+00253
+00254 <font class="comment">// Copy loop from track.</font>
+00255 trackSV-&gt;setLoopMode(trackIn-&gt;getLoopMode());
+00256
+00257 <font class="comment">// Build it.</font>
+00258 trackSV-&gt;build(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>, beginTime, endTime);
+00259
+00260 <font class="comment">// return result.</font>
+00261 <font class="keywordflow">return</font> trackSV;
+00262 }
+00263 }
+00264 <font class="keywordflow">else</font>
+00265 {
+00266 <font class="comment">// Must be a quaternion track or vector track for now.</font>
+00267 <a class="code" href="debug_8h.html#a12">nlstop</a>;
+00268 <font class="comment">// Avoid warning.</font>
+00269 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c0">cloneTrack</a>(trackIn);
+00270 }
+00271 }
+00272
+00273
+00274 <font class="comment">// ***************************************************************************</font>
+00275 <font class="comment">// ***************************************************************************</font>
+00276 <font class="comment">// Quaternion optimisation</font>
+00277 <font class="comment">// ***************************************************************************</font>
+00278 <font class="comment">// ***************************************************************************</font>
+00279
+00280
+00281 <font class="comment">// ***************************************************************************</font>
+<a name="l00282"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_0">00282</a> <font class="keywordtype">void</font> CAnimationOptimizer::sampleQuatTrack(<font class="keyword">const</font> ITrack *trackIn, <font class="keywordtype">float</font> beginTime, <font class="keywordtype">float</font> endTime, uint numSamples)
+00283 {
+00284 <font class="comment">// resize tmp samples</font>
+00285 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>.resize(numSamples);
+00286 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.resize(numSamples);
+00287
+00288 <font class="comment">// Sample the animation.</font>
+00289 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= beginTime;
+00290 <font class="keywordtype">float</font> dt= 0;
+00291 <font class="keywordflow">if</font>(numSamples&gt;1)
+00292 dt= (endTime-beginTime)/(numSamples-1);
+00293 <font class="keywordflow">for</font>(uint i=0;i&lt;numSamples; i++, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=dt)
+00294 {
+00295 CQuat quat;
+00296
+00297 <font class="comment">// make exact endTime match (avoid precision problem)</font>
+00298 <font class="keywordflow">if</font>(i==numSamples-1)
+00299 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= endTime;
+00300
+00301 <font class="comment">// evaluate the track</font>
+00302 const_cast&lt;ITrack*&gt;(trackIn)-&gt;interpolate(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, quat);
+00303
+00304 <font class="comment">// normalize this quaternion</font>
+00305 quat.normalize();
+00306
+00307 <font class="comment">// force on same hemisphere according to precedent frame.</font>
+00308 <font class="keywordflow">if</font>(i&gt;0)
+00309 {
+00310 quat.makeClosest(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i-1]);
+00311 }
+00312
+00313 <font class="comment">// store time and key.</font>
+00314 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]= i;
+00315 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]= quat;
+00316 }
+00317
+00318 }
+00319
+00320 <font class="comment">// ***************************************************************************</font>
+<a name="l00321"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_1">00321</a> <font class="keywordtype">bool</font> CAnimationOptimizer::testConstantQuatTrack()
+00322 {
+00323 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.size();
+00324 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples&gt;0);
+00325
+00326 <font class="comment">// Get the first sample as the reference quaternion, and test others from this one.</font>
+00327 CQuat quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0];
+00328 <font class="keywordflow">for</font>(uint i=0;i&lt;numSamples;i++)
+00329 {
+00330 <font class="comment">// All values must be nearly equal to the reference quaternion.</font>
+00331 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]))
+00332 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00333 }
+00334
+00335 <font class="comment">// ok.</font>
+00336 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00337 }
+00338
+00339
+00340 <font class="comment">// ***************************************************************************</font>
+<a name="l00341"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_2">00341</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimizeQuatTrack()
+00342 {
+00343 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>.size();
+00344 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples&gt;0);
+00345
+00346 <font class="comment">// &lt;=2 key? =&gt; no opt possible..</font>
+00347 <font class="keywordflow">if</font>(numSamples&lt;=2)
+00348 <font class="keywordflow">return</font>;
+00349
+00350 <font class="comment">// prepare dest opt</font>
+00351 std::vector&lt;uint16&gt; optTimeList;
+00352 std::vector&lt;CQuat&gt; optKeyList;
+00353 optTimeList.reserve(numSamples);
+00354 optKeyList.reserve(numSamples);
+00355
+00356 <font class="comment">// Add the first key.</font>
+00357 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0]);
+00358 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0]);
+00359 <font class="keywordtype">double</font> timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0];
+00360 CQuatD quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[0];
+00361
+00362 <font class="comment">// For all keys, but the first and the last, test if can remove them.</font>
+00363 <font class="keywordflow">for</font>(uint i=1; i&lt;numSamples-1; i++)
+00364 {
+00365 CQuatD quatCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i];
+00366 CQuatD quatNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i+1];
+00367 <font class="keywordtype">double</font> timeCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
+00368 <font class="keywordtype">double</font> timeNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i+1];
+00369
+00370 <font class="comment">// must add the key?</font>
+00371 <font class="keywordtype">bool</font> mustAdd= <font class="keyword">false</font>;
+00372
+00373 <font class="comment">// If the Delta time are too big, abort (CTrackSampledQuat limitation)</font>
+00374 <font class="keywordflow">if</font>(timeNext-timeRef&gt;255)
+00375 {
+00376 mustAdd= <font class="keyword">true</font>;
+00377 }
+00378 <font class="comment">// If the next quaternion or the current quaternion are not on same hemisphere than ref, abort.</font>
+00379 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( CQuatD::dotProduct(quatCur, quatRef)&lt;0 || CQuatD::dotProduct(quatNext, quatRef)&lt;0 )
+00380 {
+00381 mustAdd= <font class="keyword">true</font>;
+00382 }
+00383 <font class="comment">// else, test interpolation</font>
+00384 <font class="keywordflow">else</font>
+00385 {
+00386 <font class="comment">// If the 3 quats are nearly equals, it is ok (avoid interpolation)</font>
+00387 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, quatCur) &amp;&amp; <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatRef, quatNext) )
+00388 mustAdd= <font class="keyword">false</font>;
+00389 <font class="keywordflow">else</font>
+00390 {
+00391 <font class="comment">// interpolate.</font>
+00392 CQuatD quatInterpolated;
+00393 <font class="keywordtype">double</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (timeCur-timeRef)/(timeNext/timeRef);
+00394 quatInterpolated= CQuatD::slerp(quatRef, quatNext, (<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
+00395
+00396 <font class="comment">// test if cur and interpolate are equal.</font>
+00397 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">nearlySameQuaternion</a>(quatCur, quatInterpolated) )
+00398 mustAdd= <font class="keyword">true</font>;
+00399 }
+00400 }
+00401
+00402 <font class="comment">// If must add the key to the optimized track.</font>
+00403 <font class="keywordflow">if</font>(mustAdd)
+00404 {
+00405 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]);
+00406 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i]);
+00407 timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
+00408 quatRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[i];
+00409 }
+00410 }
+00411
+00412 <font class="comment">// Add the last key.</font>
+00413 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[numSamples-1]);
+00414 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>[numSamples-1]);
+00415
+00416 <font class="comment">// copy the optimized track to the main one.</font>
+00417 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>= optTimeList;
+00418 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o9">_QuatKeyList</a>= optKeyList;
+00419 }
+00420
+00421
+00422 <font class="comment">// ***************************************************************************</font>
+<a name="l00423"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z379_3">00423</a> <font class="keywordtype">bool</font> CAnimationOptimizer::nearlySameQuaternion(<font class="keyword">const</font> CQuatD &amp;quat0, <font class="keyword">const</font> CQuatD &amp;quat1)
+00424 {
+00425 <font class="comment">// true if exactly same, or exactly inverse</font>
+00426 <font class="keywordflow">if</font>(quat0==quat1 || quat0==-quat1)
+00427 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00428
+00429 <font class="comment">// Else compute the rotation to go from qRef to q. Use double for better presion.</font>
+00430 CQuatD quatDif;
+00431 quatDif= quat1 * quat0.conjugate();
+00432 <font class="comment">// inverse the quaternion if necessary. ie make closest to the identity quaternion.</font>
+00433 <font class="keywordflow">if</font>(quatDif.w&lt;0)
+00434 quatDif= -quatDif;
+00435
+00436 <font class="comment">// compare "angle threshold"</font>
+00437 <font class="keywordflow">return</font> (quatDif.w &gt;= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o3">_QuaternionThreshold</a>);
+00438 }
+00439
+00440
+00441 <font class="comment">// ***************************************************************************</font>
+00442 <font class="comment">// ***************************************************************************</font>
+00443 <font class="comment">// Vector optimisation</font>
+00444 <font class="comment">// ***************************************************************************</font>
+00445 <font class="comment">// ***************************************************************************</font>
+00446
+00447
+00448 <font class="comment">// ***************************************************************************</font>
+<a name="l00449"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_0">00449</a> <font class="keywordtype">void</font> CAnimationOptimizer::sampleVectorTrack(<font class="keyword">const</font> ITrack *trackIn, <font class="keywordtype">float</font> beginTime, <font class="keywordtype">float</font> endTime, uint numSamples)
+00450 {
+00451 <font class="comment">// resize tmp samples</font>
+00452 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>.resize(numSamples);
+00453 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.resize(numSamples);
+00454
+00455 <font class="comment">// Sample the animation.</font>
+00456 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= beginTime;
+00457 <font class="keywordtype">float</font> dt= 0;
+00458 <font class="keywordflow">if</font>(numSamples&gt;1)
+00459 dt= (endTime-beginTime)/(numSamples-1);
+00460 <font class="keywordflow">for</font>(uint i=0;i&lt;numSamples; i++, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=dt)
+00461 {
+00462 CVector vector;
+00463
+00464 <font class="comment">// make exact endTime match (avoid precision problem)</font>
+00465 <font class="keywordflow">if</font>(i==numSamples-1)
+00466 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= endTime;
+00467
+00468 <font class="comment">// evaluate the track</font>
+00469 const_cast&lt;ITrack*&gt;(trackIn)-&gt;interpolate(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, vector);
+00470
+00471 <font class="comment">// store time and key.</font>
+00472 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]= i;
+00473 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]= vector;
+00474 }
+00475
+00476 }
+00477
+00478 <font class="comment">// ***************************************************************************</font>
+<a name="l00479"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_1">00479</a> <font class="keywordtype">bool</font> CAnimationOptimizer::testConstantVectorTrack()
+00480 {
+00481 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.size();
+00482 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples&gt;0);
+00483
+00484 <font class="comment">// Get the first sample as the reference Vectorer, and test others from this one.</font>
+00485 CVector vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0];
+00486 <font class="keywordflow">for</font>(uint i=0;i&lt;numSamples;i++)
+00487 {
+00488 <font class="comment">// All values must be nearly equal to the reference vector.</font>
+00489 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]))
+00490 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00491 }
+00492
+00493 <font class="comment">// ok.</font>
+00494 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00495 }
+00496
+00497
+00498 <font class="comment">// ***************************************************************************</font>
+<a name="l00499"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_2">00499</a> <font class="keywordtype">void</font> CAnimationOptimizer::optimizeVectorTrack()
+00500 {
+00501 uint numSamples= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>.size();
+00502 <a class="code" href="debug_8h.html#a6">nlassert</a>(numSamples&gt;0);
+00503
+00504 <font class="comment">// &lt;=2 key? =&gt; no opt possible..</font>
+00505 <font class="keywordflow">if</font>(numSamples&lt;=2)
+00506 <font class="keywordflow">return</font>;
+00507
+00508 <font class="comment">// prepare dest opt</font>
+00509 std::vector&lt;uint16&gt; optTimeList;
+00510 std::vector&lt;CVector&gt; optKeyList;
+00511 optTimeList.reserve(numSamples);
+00512 optKeyList.reserve(numSamples);
+00513
+00514 <font class="comment">// Add the first key.</font>
+00515 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0]);
+00516 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0]);
+00517 <font class="keywordtype">double</font> timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[0];
+00518 CVectorD vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[0];
+00519
+00520 <font class="comment">// For all keys, but the first and the last, test if can remove them.</font>
+00521 <font class="keywordflow">for</font>(uint i=1; i&lt;numSamples-1; i++)
+00522 {
+00523 CVectorD vectorCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i];
+00524 CVectorD vectorNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i+1];
+00525 <font class="keywordtype">double</font> timeCur= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
+00526 <font class="keywordtype">double</font> timeNext= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i+1];
+00527
+00528 <font class="comment">// must add the key?</font>
+00529 <font class="keywordtype">bool</font> mustAdd= <font class="keyword">false</font>;
+00530
+00531 <font class="comment">// If the Delta time are too big, abort (CTrackSampledVector limitation)</font>
+00532 <font class="keywordflow">if</font>(timeNext-timeRef&gt;255)
+00533 {
+00534 mustAdd= <font class="keyword">true</font>;
+00535 }
+00536 <font class="comment">// else, test interpolation</font>
+00537 <font class="keywordflow">else</font>
+00538 {
+00539 <font class="comment">// If the 3 Vectors are nearly equals, it is ok (avoid interpolation)</font>
+00540 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, vectorCur) &amp;&amp; <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorRef, vectorNext) )
+00541 mustAdd= <font class="keyword">false</font>;
+00542 <font class="keywordflow">else</font>
+00543 {
+00544 <font class="comment">// interpolate.</font>
+00545 CVectorD vectorInterpolated;
+00546 <font class="keywordtype">double</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (timeCur-timeRef)/(timeNext/timeRef);
+00547 vectorInterpolated= vectorRef*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) + vectorNext*<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
+00548
+00549 <font class="comment">// test if cur and interpolate are equal.</font>
+00550 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">nearlySameVector</a>(vectorCur, vectorInterpolated) )
+00551 mustAdd= <font class="keyword">true</font>;
+00552 }
+00553 }
+00554
+00555 <font class="comment">// If must add the key to the optimized track.</font>
+00556 <font class="keywordflow">if</font>(mustAdd)
+00557 {
+00558 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i]);
+00559 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i]);
+00560 timeRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[i];
+00561 vectorRef= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[i];
+00562 }
+00563 }
+00564
+00565 <font class="comment">// Add the last key.</font>
+00566 optTimeList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>[numSamples-1]);
+00567 optKeyList.push_back(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>[numSamples-1]);
+00568
+00569 <font class="comment">// copy the optimized track to the main one.</font>
+00570 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o8">_TimeList</a>= optTimeList;
+00571 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o10">_VectorKeyList</a>= optKeyList;
+00572 }
+00573
+00574
+00575 <font class="comment">// ***************************************************************************</font>
+<a name="l00576"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#z380_3">00576</a> <font class="keywordtype">bool</font> CAnimationOptimizer::nearlySameVector(<font class="keyword">const</font> CVectorD &amp;v0, <font class="keyword">const</font> CVectorD &amp;v1)
+00577 {
+00578 <font class="comment">// true if exactly same</font>
+00579 <font class="keywordflow">if</font>(v0==v1)
+00580 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00581
+00582 <font class="comment">// Else compute the dif, use double for better precision</font>
+00583 CVectorD vDif;
+00584 vDif= v1-v0;
+00585
+00586 <font class="comment">// compare norm</font>
+00587 <font class="keywordflow">return</font> (vDif.norm() &lt;= <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o6">_VectorThreshold</a>);
+00588 }
+00589
+00590
+00591 <font class="comment">// ***************************************************************************</font>
+00592 <font class="comment">// ***************************************************************************</font>
+00593 <font class="comment">// LowPrecisionTrack</font>
+00594 <font class="comment">// ***************************************************************************</font>
+00595 <font class="comment">// ***************************************************************************</font>
+00596
+00597
+00598 <font class="comment">// ***************************************************************************</font>
+<a name="l00599"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a3">00599</a> <font class="keywordtype">void</font> CAnimationOptimizer::addLowPrecisionTrack(<font class="keyword">const</font> std::string &amp;name)
+00600 {
+00601 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.push_back(name);
+00602 }
+00603
+00604 <font class="comment">// ***************************************************************************</font>
+<a name="l00605"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#a4">00605</a> <font class="keywordtype">void</font> CAnimationOptimizer::clearLowPrecisionTracks()
+00606 {
+00607 <a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.clear();
+00608 }
+00609
+00610 <font class="comment">// ***************************************************************************</font>
+<a name="l00611"></a><a class="code" href="classNL3D_1_1CAnimationOptimizer.html#c3">00611</a> <font class="keywordtype">bool</font> CAnimationOptimizer::isLowPrecisionTrack(<font class="keyword">const</font> std::string &amp;trackName)
+00612 {
+00613 <font class="keywordflow">for</font>(uint i=0; i&lt;<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>.size(); i++)
+00614 {
+00615 <font class="comment">// if find a substr of the key, it is a low prec track</font>
+00616 <font class="keywordflow">if</font>( trackName.find(<a class="code" href="classNL3D_1_1CAnimationOptimizer.html#o7">_LowPrecTrackKeyName</a>[i]) != string::npos )
+00617 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00618 }
+00619
+00620 <font class="comment">// no key found</font>
+00621 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00622 }
+00623
+00624
+00625 } <font class="comment">// NL3D</font>
+</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=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
+</TR>
+</TABLE>
+</BODY>
+</HTML>