diff options
author | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
commit | 0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch) | |
tree | 2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/a06287.html | |
download | nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip |
Initial commit
Diffstat (limited to '')
-rw-r--r-- | docs/doxygen/nel/a06287.html | 1474 |
1 files changed, 1474 insertions, 0 deletions
diff --git a/docs/doxygen/nel/a06287.html b/docs/doxygen/nel/a06287.html new file mode 100644 index 00000000..aa25e520 --- /dev/null +++ b/docs/doxygen/nel/a06287.html @@ -0,0 +1,1474 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> +<title>NeL: ps_zone.cpp Source File</title> +<link href="doxygen.css" rel="stylesheet" type="text/css"> +</head><body> +<!-- Generated by Doxygen 1.3.6 --> +<div class="qindex"> <form class="search" action="search.php" method="get"> +<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div> +<h1>ps_zone.cpp</h1><a href="a04864.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <span class="comment">/* Copyright, 2001 Nevrax Ltd.</span> +00008 <span class="comment"> *</span> +00009 <span class="comment"> * This file is part of NEVRAX NEL.</span> +00010 <span class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</span> +00011 <span class="comment"> * it under the terms of the GNU General Public License as published by</span> +00012 <span class="comment"> * the Free Software Foundation; either version 2, or (at your option)</span> +00013 <span class="comment"> * any later version.</span> +00014 <span class="comment"></span> +00015 <span class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</span> +00016 <span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span> +00017 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> +00018 <span class="comment"> * General Public License for more details.</span> +00019 <span class="comment"></span> +00020 <span class="comment"> * You should have received a copy of the GNU General Public License</span> +00021 <span class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</span> +00022 <span class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</span> +00023 <span class="comment"> * MA 02111-1307, USA.</span> +00024 <span class="comment"> */</span> +00025 +00026 <span class="preprocessor">#include "<a class="code" href="a05015.html">std3d.h</a>"</span> +00027 +00028 <span class="preprocessor">#include "<a class="code" href="a04865.html">3d/ps_zone.h</a>"</span> +00029 <span class="preprocessor">#include "<a class="code" href="a05288.html">3d/vertex_buffer.h</a>"</span> +00030 <span class="preprocessor">#include "<a class="code" href="a04775.html">3d/primitive_block.h</a>"</span> +00031 <span class="preprocessor">#include "<a class="code" href="a04546.html">3d/material.h</a>"</span> +00032 <span class="preprocessor">#include "<a class="code" href="a04863.html">3d/ps_util.h</a>"</span> +00033 <span class="preprocessor">#include "<a class="code" href="a04238.html">3d/dru.h</a>"</span> +00034 <span class="preprocessor">#include "<a class="code" href="a04720.html">3d/particle_system.h</a>"</span> +00035 <span class="preprocessor">#include "<a class="code" href="a04748.html">nel/misc/plane.h</a>"</span> +00036 +00037 <span class="comment">// tmp</span> +00038 +00039 <span class="preprocessor">#include "<a class="code" href="a04726.html">3d/particle_system_model.h</a>"</span> +00040 +00041 <span class="preprocessor">#include <math.h></span> +00042 <span class="preprocessor">#include <limits></span> +00043 +00044 <span class="keyword">namespace </span>NL3D { +00045 +00046 +00047 <span class="comment">/*</span> +00048 <span class="comment"> * Constructor</span> +00049 <span class="comment"> */</span> +<a name="l00050"></a><a class="code" href="a03255.html#NL3D_1_1CPSZonea6">00050</a> CPSZone::CPSZone() : _BounceFactor(1.f), _CollisionBehaviour(bounce) +00051 { +00052 } +00053 +<a name="l00054"></a><a class="code" href="a03255.html#NL3D_1_1CPSZonea43">00054</a> <span class="keywordtype">void</span> CPSZone::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +00055 { +00056 f.serialVersion(1); +00057 CPSTargetLocatedBindable::serial(f); +00058 f.serialEnum(_CollisionBehaviour); +00059 f.serial(_BounceFactor); +00060 <span class="keywordflow">if</span> (f.isReading()) +00061 { +00062 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +00063 { +00064 <span class="comment">// though this is not a force, this prevent parametric motion</span> +00065 (*it)->addNonIntegrableForceRef(); +00066 } +00067 } +00068 } +00069 +<a name="l00073"></a><a class="code" href="a03255.html#NL3D_1_1CPSZoneSpherea0">00073</a> <span class="keywordtype">void</span> CPSZone::attachTarget(<a class="code" href="a03214.html">CPSLocated</a> *ptr) +00074 { +00075 +00076 CPSTargetLocatedBindable::attachTarget(ptr); +00077 ptr-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda71">queryCollisionInfo</a>(); +00078 ptr-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda0">addNonIntegrableForceRef</a>(); +00079 } +00080 +00081 +00082 +00083 +00084 +<a name="l00086"></a><a class="code" href="a03255.html#NL3D_1_1CPSZoneSpherea47">00086</a> <span class="keywordtype">void</span> CPSZone::releaseTargetRsc(<a class="code" href="a03214.html">CPSLocated</a> *target) +00087 { +00088 <span class="comment">// tell the target that we were using collision infos and that we won't use them anymore</span> +00089 target-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda75">releaseCollisionInfo</a>(); +00090 target-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda76">releaseNonIntegrableForceRef</a>(); +00091 } +00092 +00093 +00094 +<a name="l00095"></a><a class="code" href="a03255.html#NL3D_1_1CPSZoneSpherea62">00095</a> <span class="keywordtype">void</span> CPSZone::step(TPSProcessPass pass, <a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime, <a class="code" href="a05363.html#a366">TAnimationTime</a> realEt) +00096 { +00097 <span class="comment">// for zone, the PSCollision pass and the PSToolRenderPass are processed</span> +00098 <span class="keywordflow">switch</span>(pass) +00099 { +00100 <span class="keywordflow">case</span> <a class="code" href="a05363.html#a556a213">PSCollision</a>: +00101 <a class="code" href="a03255.html#NL3D_1_1CPSZonea39">performMotion</a>(ellapsedTime); +00102 <span class="keywordflow">break</span>; +00103 <span class="keywordflow">case</span> <a class="code" href="a05363.html#a556a217">PSToolRender</a>: +00104 <a class="code" href="a03255.html#NL3D_1_1CPSZonea52">show</a>(ellapsedTime); +00105 <span class="keywordflow">break</span>; +00106 <span class="keywordflow">default</span>: <span class="keywordflow">break</span>; +00107 } +00108 } +00109 +00110 +00111 <span class="comment">// build a basis with K = the normal of the plane</span> +<a name="l00112"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb1">00112</a> <a class="code" href="a02851.html">CMatrix</a> CPSZonePlane::buildBasis(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +00113 <span class="keyword"></span>{ +00114 <a class="code" href="a02851.html">CMatrix</a> m; +00115 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>]); +00116 CPSUtil::buildSchmidtBasis(_Normal[<a class="code" href="a04223.html#a566">index</a>], m); +00117 <span class="keywordflow">return</span> m; +00118 } +00119 +00120 +00123 <span class="comment">/*void CPSZone::bounce(uint32 locatedIndex, const CVector &bouncePoint, const CVector &surfNormal, float elasticity, TAnimationTime ellapsedTime)</span> +00124 <span class="comment">{</span> +00125 <span class="comment"> CVector &speed = _Owner->getSpeed()[locatedIndex];</span> +00126 <span class="comment"> const CVector &pos = _Owner->getPos()[locatedIndex];</span> +00127 <span class="comment"> CVector &bounceVect = elasticity * (speed - 2.0f * (speed * surfNormal) * surfNormal); // speed vector after collision</span> +00128 <span class="comment"> // now check where the located will be after integration</span> +00129 <span class="comment"> CVector d = bouncePoint - pos;</span> +00130 <span class="comment"> TAnimationTime collideDelay = speed.norm() / d.norm();</span> +00131 <span class="comment"> CVector finalPos = bouncePoint + (ellapsedTime - collideDelay) * bounceVect;</span> +00132 <span class="comment"> // now, we must have pos + ellapsedTime * newSpeed = finalPos </span> +00133 <span class="comment"> // newSpeed = alpha * (finalPos - pos)</span> +00134 <span class="comment"> // so alpha = 1 / ellapsedTime</span> +00135 <span class="comment"></span> +00136 <span class="comment"> speed = (1.0f / ellapsedTime) * (finalPos - pos); </span> +00137 <span class="comment">}*/</span> +00138 +00139 +<a name="l00140"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea60">00140</a> <span class="keywordtype">void</span> CPSZonePlane::show(<a class="code" href="a05363.html#a366">TAnimationTime</a>) +00141 { +00142 <span class="keyword">const</span> <span class="keywordtype">float</span> planeSize = 2.0f; +00143 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00144 +00145 <a class="code" href="a02434.html">IDriver</a> *driver = <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(); +00146 <a class="code" href="a04558.html#a15">uint</a> k = 0; +00147 +00148 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00149 +00150 <a class="code" href="a03214.html">CPSLocated</a> *loc; +00151 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>; +00152 <a class="code" href="a02691.html">CPSLocatedBindable</a> *lb; +00153 _Owner-><a class="code" href="a03054.html#NL3D_1_1CPSLocateda39">getOwner</a>()-><a class="code" href="a03041.html#NL3D_1_1CParticleSystemz588_0">getCurrentEditedElement</a>(loc, <a class="code" href="a04223.html#a566">index</a>, lb); +00154 +00155 +00156 +00157 +00158 +00159 <span class="keywordflow">for</span> (TPSAttribVector::const_iterator it = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); it != _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); ++it, ++k) +00160 { +00161 <span class="keyword">const</span> <a class="code" href="a03337.html">CRGBA</a> col = ((lb == NULL || <span class="keyword">this</span> == lb) && loc == _Owner && <a class="code" href="a04223.html#a566">index</a> == k ? CRGBA::Red : <a class="code" href="a03337.html">CRGBA</a>(127, 127, 127)); +00162 <a class="code" href="a02851.html">CMatrix</a> mat = <a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb1">buildBasis</a>(k); +00163 +00164 CPSUtil::displayBasis(<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea22">getLocalToWorldMatrix</a>(), mat, 1.f, *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea17">getFontGenerator</a>(), *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea19">getFontManager</a>()); +00165 +00166 +00167 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00168 +00169 CDRU::drawLine(*it + (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() + planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00170 , *it - (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() + planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00171 , col +00172 , *driver); +00173 +00174 CDRU::drawLine(*it + (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() - planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00175 , *it - (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() - planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00176 , col +00177 , *driver); +00178 +00179 CDRU::drawLine(*it + planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() + (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00180 , *it + planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() - (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00181 , col +00182 , *driver); +00183 CDRU::drawLine(*it - planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() + (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00184 , *it - planeSize * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>() - (planeSize + 3) * mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>() +00185 , col +00186 , *driver); +00187 } +00188 +00189 +00190 } +00191 +00192 +00193 +<a name="l00194"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb6">00194</a> <span class="keywordtype">void</span> CPSZonePlane::resize(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>) +00195 { +00196 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a587">size</a> < (1 << 16)); +00197 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +00198 } +00199 +00200 +<a name="l00201"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb4">00201</a> <span class="keywordtype">void</span> CPSZonePlane::newElement(<a class="code" href="a03214.html">CPSLocated</a> *emitterLocated, <a class="code" href="a04558.html#a11">uint32</a> emitterIndex) +00202 { +00203 <a class="code" href="a04199.html#a6">nlassert</a>(_Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>() != _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_0">getMaxSize</a>()); +00204 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(<a class="code" href="a03128.html">CVector</a>(0, 0, 1)); +00205 } +00206 +00207 +<a name="l00208"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb2">00208</a> <span class="keywordtype">void</span> CPSZonePlane::deleteElement(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +00209 { +00210 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +00211 } +00212 +00213 +00214 +<a name="l00215"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea43">00215</a> <span class="keywordtype">void</span> CPSZonePlane::performMotion(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00216 { +00217 <a class="code" href="a04726.html#a0">MINI_TIMER</a>(<a class="code" href="a05363.html#a200">PSStatsZonePlane</a>) +00218 <span class="comment">// for each target, we must check wether they are going through the plane</span> +00219 <span class="comment">// if so they must bounce</span> +00220 TPSAttribVector::const_iterator planePosIt, planePosEnd, normalIt, targetPosIt, targetPosEnd; +00221 <a class="code" href="a03128.html">CVector</a> dest; +00222 <a class="code" href="a03151.html">CPSCollisionInfo</a> ci; +00223 <a class="code" href="a03128.html">CVector</a> startEnd; +00224 <a class="code" href="a04558.html#a11">uint32</a> k; +00225 <span class="keyword">const</span> <a class="code" href="a03135.html">TPSAttribVector</a> *speedAttr; +00226 <span class="keywordtype">float</span> posSide, negSide; +00227 +00228 <span class="comment">// alpha is the ratio that gives the percent of endPos - startPos that hit the plane</span> +00229 <span class="keywordtype">float</span> <a class="code" href="a04223.html#a663">alpha</a>; +00230 +00231 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +00232 { +00233 +00234 speedAttr = &((*it)->getSpeed()); +00235 <span class="comment">// cycle through the planes</span> +00236 +00237 planePosEnd = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +00238 <span class="keywordflow">for</span> (planePosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), normalIt = _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); planePosIt != planePosEnd +00239 ; ++planePosIt, ++normalIt) +00240 { +00241 +00242 <span class="comment">// we must setup the plane in the good basis</span> +00243 +00244 <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m = CPSLocated::getConversionMatrix(*it, this->_Owner); +00245 <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 0.5f * <a class="code" href="a05363.html#a273">PSCollideEpsilon</a>; +00246 +00247 +00248 <a class="code" href="a03082.html">NLMISC::CPlane</a> p; +00249 p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_2">make</a>(m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(*normalIt), m * (*planePosIt)); +00250 +00251 <span class="comment">// deals with each particle</span> +00252 +00253 targetPosEnd = (*it)->getPos().end(); +00254 TPSAttribCollisionInfo::const_iterator ciIt = (*it)->getCollisionInfo().begin(); +00255 <span class="keywordflow">for</span> (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k, ++ciIt) +00256 { +00257 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &speed = (*speedAttr)[k]; +00258 <span class="comment">// check whether the located is going through the plane</span> +00259 dest = *targetPosIt + ellapsedTime * speed * ciIt->TimeSliceRatio; +00260 +00261 +00262 posSide = p * *targetPosIt; +00263 negSide = p * dest; +00264 +00265 <span class="keywordflow">if</span> (posSide >= - epsilon && negSide <= epsilon) +00266 { +00267 <span class="keywordflow">if</span> (fabsf(posSide - negSide) > <a class="code" href="a04061.html#a0">std::numeric_limits<float>::min</a>()) +00268 { +00269 <a class="code" href="a04223.html#a663">alpha</a> = posSide / (posSide - negSide); +00270 } +00271 <span class="keywordflow">else</span> +00272 { +00273 <a class="code" href="a04223.html#a663">alpha</a> = 0.f; +00274 } +00275 startEnd = <a class="code" href="a04223.html#a663">alpha</a> * (dest - *targetPosIt); +00276 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +00277 <span class="comment">// we translate the particle from an epsilon so that it won't get hooked to the plane</span> +00278 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = *targetPosIt + startEnd + <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>(); +00279 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = _BounceFactor * (speed - 2.0f * (speed * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()) * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()); +00280 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +00281 (*it)->collisionUpdate(ci, k); +00282 } +00283 } +00284 } +00285 } +00286 } +00287 +<a name="l00288"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea53">00288</a> <span class="keywordtype">void</span> CPSZonePlane::setMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m) +00289 { +00290 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a566">index</a> < _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>()); +00291 _Normal[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_4">getK</a>(); +00292 _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>(); +00293 } +00294 +<a name="l00295"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea23">00295</a> <a class="code" href="a02851.html">CMatrix</a> CPSZonePlane::getMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +00296 <span class="keyword"></span>{ +00297 <span class="keywordflow">return</span> <a class="code" href="a03258.html#NL3D_1_1CPSZonePlaneb1">buildBasis</a>(<a class="code" href="a04223.html#a566">index</a>); +00298 } +00299 +00300 +<a name="l00301"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea26">00301</a> <a class="code" href="a03128.html">CVector</a> CPSZonePlane::getNormal(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +00302 { +00303 <span class="keywordflow">return</span> _Normal[<a class="code" href="a04223.html#a566">index</a>]; +00304 } +<a name="l00305"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea55">00305</a> <span class="keywordtype">void</span> CPSZonePlane::setNormal(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <a class="code" href="a03128.html">CVector</a> n) +00306 { +00307 _Normal[<a class="code" href="a04223.html#a566">index</a>] = n; +00308 } +00309 +00310 +00311 +00312 +<a name="l00313"></a><a class="code" href="a03258.html#NL3D_1_1CPSZonePlanea47">00313</a> <span class="keywordtype">void</span> CPSZonePlane::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +00314 { +00315 f.serialVersion(1); +00316 CPSZone::serial(f); +00317 f.serial(_Normal); +00318 } +00319 +00320 +00321 +00323 <span class="comment">// sphere implementation //</span> +00325 <span class="comment"></span> +00326 +00327 +00328 +<a name="l00329"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea44">00329</a> <span class="keywordtype">void</span> CPSZoneSphere::performMotion(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00330 { +00331 <a class="code" href="a04726.html#a0">MINI_TIMER</a>(<a class="code" href="a05363.html#a201">PSStatsZoneSphere</a>) +00332 <span class="comment">// for each target, we must check wether they are going through the plane</span> +00333 <span class="comment">// if so they must bounce</span> +00334 +00335 TPSAttribRadiusPair::const_iterator radiusIt = _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +00336 TPSAttribVector::const_iterator spherePosIt, spherePosEnd, targetPosIt, targetPosEnd; +00337 <a class="code" href="a03128.html">CVector</a> dest; +00338 <a class="code" href="a03151.html">CPSCollisionInfo</a> ci; +00339 <a class="code" href="a04558.html#a11">uint32</a> k; +00340 <span class="keyword">const</span> <a class="code" href="a03135.html">TPSAttribVector</a> *speedAttr; +00341 +00342 +00343 <span class="keywordtype">float</span> rOut, rIn; +00344 +00345 +00346 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +00347 { +00348 +00349 speedAttr = &((*it)->getSpeed()); +00350 +00351 +00352 <span class="comment">// cycle through the spheres</span> +00353 +00354 spherePosEnd = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +00355 <span class="keywordflow">for</span> (spherePosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), radiusIt = _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); spherePosIt != spherePosEnd +00356 ; ++spherePosIt, ++radiusIt) +00357 { +00358 +00359 <span class="comment">// we must setup the sphere in the good basis</span> +00360 +00361 <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m = CPSLocated::getConversionMatrix(*it, this->_Owner); +00362 +00363 +00364 +00365 <a class="code" href="a03128.html">CVector</a> center = m * *spherePosIt; +00366 +00367 <span class="comment">// deals with each particle</span> +00368 +00369 +00370 targetPosEnd = (*it)-><a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>().end(); +00371 TPSAttribCollisionInfo::const_iterator ciIt = (*it)->getCollisionInfo().begin(); +00372 <span class="keywordflow">for</span> (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k, ++ciIt) +00373 { +00374 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &speed = (*speedAttr)[k]; +00375 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &pos = *targetPosIt; +00376 <span class="comment">// check whether the located is going through the sphere</span> +00377 +00378 <span class="comment">// we don't use raytracing for now because it is too slow ...</span> +00379 +00380 +00381 rOut = (pos - center) * (pos - center); +00382 +00383 <span class="comment">// initial position outside the sphere ?</span> +00384 <span class="keywordflow">if</span> (rOut > radiusIt->R2) +00385 { +00386 dest = pos + ellapsedTime * speed * ciIt->TimeSliceRatio; +00387 rIn = (dest - center) * (dest - center); +00388 +00389 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> D = dest - pos; +00390 +00391 <span class="comment">// final position inside the sphere ?</span> +00392 +00393 <span class="keywordflow">if</span> ( rIn <= radiusIt->R2) +00394 { +00395 <span class="comment">// discriminant of the intersection equation</span> +00396 <span class="keyword">const</span> <span class="keywordtype">float</span> b = 2.f * (pos * D - D * center), a = D * D +00397 , c = (pos * pos) + (center * center) - 2.f * (pos * center) - radiusIt->R2; +00398 <span class="keywordtype">float</span> d = b * b - 4 * a * c; +00399 +00400 +00401 <span class="keywordflow">if</span> (d <= 0.f) <span class="keywordflow">continue</span>; <span class="comment">// should never happen, but we never know ...</span> +00402 +00403 +00404 d = sqrtf(d); +00405 +00406 <span class="comment">// roots of the equation, we take the smallest </span> +00407 +00408 +00409 <span class="keyword">const</span> <span class="keywordtype">float</span> r1 = .5f * (-b + 2.f * d) * a +00410 , r2 = .5f * (-b - 2.f * d) * a; +00411 +00412 <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="a04223.html#a628">r</a> = <a class="code" href="a04061.html#a0">std::min</a>(r1, r2); +00413 +00414 <span class="comment">// collision point </span> +00415 +00416 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> C = pos + <a class="code" href="a04223.html#a628">r</a> * D; +00417 +00418 +00419 +00420 +00421 +00422 +00423 <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="a04223.html#a663">alpha</a> = ((C - pos) * D) * a; +00424 +00425 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> startEnd = <a class="code" href="a04223.html#a663">alpha</a> * (dest - pos); +00426 +00427 <a class="code" href="a03128.html">CVector</a> normal = C - center; +00428 normal = normal * (1.f / radiusIt->R); +00429 +00430 +00431 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +00432 <span class="comment">// we translate the particle from an epsilon so that it won't get hooked to the sphere</span> +00433 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = pos + startEnd + <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * normal; +00434 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = _BounceFactor * (speed - 2.0f * (speed * normal) * normal); +00435 +00436 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +00437 (*it)->collisionUpdate(ci, k); +00438 +00439 } +00440 } +00441 } +00442 } +00443 } +00444 } +00445 +00446 +00447 +<a name="l00448"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea61">00448</a> <span class="keywordtype">void</span> CPSZoneSphere::show(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00449 { +00450 +00451 <a class="code" href="a03214.html">CPSLocated</a> *loc; +00452 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>; +00453 <a class="code" href="a02691.html">CPSLocatedBindable</a> *lb; +00454 _Owner-><a class="code" href="a03054.html#NL3D_1_1CPSLocateda39">getOwner</a>()-><a class="code" href="a03041.html#NL3D_1_1CParticleSystemz588_0">getCurrentEditedElement</a>(loc, <a class="code" href="a04223.html#a566">index</a>, lb); +00455 +00456 +00457 TPSAttribRadiusPair::const_iterator radiusIt = _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +00458 TPSAttribVector::const_iterator posIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), endPosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +00459 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00460 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a15">uint</a> k = 0; posIt != endPosIt; ++posIt, ++radiusIt, ++k) +00461 { +00462 <span class="keyword">const</span> <a class="code" href="a03337.html">CRGBA</a> col = ((lb == NULL || <span class="keyword">this</span> == lb) && loc == _Owner && <a class="code" href="a04223.html#a566">index</a> == k ? CRGBA::Red : <a class="code" href="a03337.html">CRGBA</a>(127, 127, 127)); +00463 CPSUtil::displaySphere(*<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), radiusIt->R, *posIt, 5, col); +00464 } +00465 } +00466 +<a name="l00467"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea54">00467</a> <span class="keywordtype">void</span> CPSZoneSphere::setMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m) +00468 { +00469 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a566">index</a> < _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>()); +00470 +00471 <span class="comment">// compute new pos</span> +00472 _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>(); +00473 +00474 } +00475 +00476 +<a name="l00477"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea24">00477</a> <a class="code" href="a02851.html">CMatrix</a> CPSZoneSphere::getMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +00478 <span class="keyword"></span>{ +00479 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a566">index</a> < _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>()); +00480 <a class="code" href="a02851.html">CMatrix</a> m; +00481 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_0">identity</a>(); +00482 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1965_7">translate</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>]); +00483 <span class="keywordflow">return</span> m; +00484 } +00485 +<a name="l00486"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea58">00486</a> <span class="keywordtype">void</span> CPSZoneSphere::setScale(<a class="code" href="a04558.html#a11">uint32</a> k, <span class="keywordtype">float</span> scale) +00487 { +00488 _Radius[k].R = scale; +00489 _Radius[k].R2 = scale * scale; +00490 } +<a name="l00491"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea31">00491</a> <a class="code" href="a03128.html">CVector</a> CPSZoneSphere::getScale(<a class="code" href="a04558.html#a11">uint32</a> k)<span class="keyword"> const</span> +00492 <span class="keyword"></span>{ +00493 <span class="keywordflow">return</span> <a class="code" href="a03128.html">CVector</a>(_Radius[k].R, _Radius[k].R, _Radius[k].R); +00494 } +00495 +00496 +<a name="l00497"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSpherea48">00497</a> <span class="keywordtype">void</span> CPSZoneSphere::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +00498 { +00499 f.serialVersion(1); +00500 CPSZone::serial(f); +00501 f.serial(_Radius); +00502 } +00503 +00504 +00505 +00506 +00507 +00508 +<a name="l00509"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSphereb6">00509</a> <span class="keywordtype">void</span> CPSZoneSphere::resize(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>) +00510 { +00511 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a587">size</a> < (1 << 16)); +00512 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +00513 } +00514 +<a name="l00515"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSphereb4">00515</a> <span class="keywordtype">void</span> CPSZoneSphere::newElement(<a class="code" href="a03214.html">CPSLocated</a> *emitterLocated, <a class="code" href="a04558.html#a11">uint32</a> emitterIndex) +00516 { +00517 <a class="code" href="a03299.html">CRadiusPair</a> rp; +00518 rp.<a class="code" href="a03299.html#NL3D_1_1CRadiusPairo0">R</a> = rp.<a class="code" href="a03299.html#NL3D_1_1CRadiusPairo1">R2</a> = 1.f; +00519 <a class="code" href="a04199.html#a6">nlassert</a>(_Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>() != _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_0">getMaxSize</a>()); +00520 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(rp); +00521 } +00522 +<a name="l00523"></a><a class="code" href="a03260.html#NL3D_1_1CPSZoneSphereb2">00523</a> <span class="keywordtype">void</span> CPSZoneSphere::deleteElement(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +00524 { +00525 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +00526 } +00527 +00528 +00530 <span class="comment">// CPSZoneDisc implementation //</span> +00532 <span class="comment"></span> +<a name="l00533"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca44">00533</a> <span class="keywordtype">void</span> CPSZoneDisc::performMotion(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00534 { +00535 <a class="code" href="a04726.html#a0">MINI_TIMER</a>(<a class="code" href="a05363.html#a202">PSStatsZoneDisc</a>) +00536 <span class="comment">// for each target, we must check wether they are going through the disc</span> +00537 <span class="comment">// if so they must bounce</span> +00538 TPSAttribVector::const_iterator discPosIt, discPosEnd, normalIt, targetPosIt, targetPosEnd; +00539 TPSAttribRadiusPair::const_iterator radiusIt; +00540 <a class="code" href="a03128.html">CVector</a> dest; +00541 <a class="code" href="a03151.html">CPSCollisionInfo</a> ci; +00542 <a class="code" href="a03128.html">CVector</a> startEnd; +00543 <a class="code" href="a04558.html#a11">uint32</a> k; +00544 <span class="keyword">const</span> <a class="code" href="a03135.html">TPSAttribVector</a> *speedAttr; +00545 <span class="keywordtype">float</span> posSide, negSide; +00546 +00547 <span class="comment">// the square of radius at the hit point</span> +00548 <span class="keywordtype">float</span> hitRadius2; +00549 +00550 <span class="comment">// alpha is the ratio that gives the percent of endPos - startPos that hit the disc</span> +00551 <span class="keywordtype">float</span> <a class="code" href="a04223.html#a663">alpha</a>; +00552 +00553 <a class="code" href="a03128.html">CVector</a> center; +00554 +00555 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +00556 { +00557 +00558 speedAttr = &((*it)->getSpeed()); +00559 <span class="comment">// cycle through the disc</span> +00560 +00561 discPosEnd = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +00562 <span class="keywordflow">for</span> (discPosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), radiusIt = _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), normalIt = _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); discPosIt != discPosEnd +00563 ; ++discPosIt, ++normalIt, ++radiusIt) +00564 { +00565 +00566 <span class="comment">// we must setup the disc in the good basis</span> +00567 +00568 <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m = CPSLocated::getConversionMatrix(*it, this->_Owner); +00569 +00570 +00571 +00572 <a class="code" href="a03082.html">NLMISC::CPlane</a> p; +00573 center = m * (*discPosIt); +00574 p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_2">make</a>(m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(*normalIt), center); +00575 +00576 <span class="comment">// deals with each particle</span> +00577 +00578 <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 0.5f * <a class="code" href="a05363.html#a273">PSCollideEpsilon</a>; +00579 +00580 targetPosEnd = (*it)->getPos().end(); +00581 TPSAttribCollisionInfo::const_iterator ciIt = (*it)->getCollisionInfo().begin(); +00582 <span class="keywordflow">for</span> (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k, ++ciIt) +00583 { +00584 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &speed = (*speedAttr)[k]; +00585 <span class="comment">// check whether the located is going through the disc</span> +00586 dest = *targetPosIt + ellapsedTime * speed * ciIt->TimeSliceRatio; +00587 +00588 +00589 posSide = p * *targetPosIt; +00590 negSide = p * dest; +00591 +00592 <span class="keywordflow">if</span> (posSide >= - epsilon && negSide <= epsilon) +00593 { +00594 <span class="keywordflow">if</span> (fabsf(posSide - negSide) > <a class="code" href="a04061.html#a0">std::numeric_limits<float>::min</a>()) +00595 { +00596 <a class="code" href="a04223.html#a663">alpha</a> = posSide / (posSide - negSide); +00597 } +00598 <span class="keywordflow">else</span> +00599 { +00600 <a class="code" href="a04223.html#a663">alpha</a> = 0.f; +00601 } +00602 startEnd = <a class="code" href="a04223.html#a663">alpha</a> * (dest - *targetPosIt); +00603 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +00604 <span class="comment">// we translate the particle from an epsilon so that it won't get hooked to the disc</span> +00605 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = *targetPosIt + startEnd + <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>(); +00606 +00607 +00608 <span class="comment">// now, check the collision pos against radius</span> +00609 +00610 hitRadius2 = (ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> - center) * (ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> - center); +00611 +00612 <span class="keywordflow">if</span> (hitRadius2 < radiusIt->R2) <span class="comment">// check collision against disc</span> +00613 { +00614 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = _BounceFactor * (speed - 2.0f * (speed * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()) * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()); +00615 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +00616 (*it)->collisionUpdate(ci, k); +00617 } +00618 +00619 } +00620 } +00621 } +00622 } +00623 } +00624 +<a name="l00625"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca61">00625</a> <span class="keywordtype">void</span> CPSZoneDisc::show(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00626 { +00627 TPSAttribRadiusPair::const_iterator radiusIt = _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +00628 TPSAttribVector::const_iterator posIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), endPosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>() +00629 , normalIt = _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +00630 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00631 <a class="code" href="a02851.html">CMatrix</a> mat; +00632 +00633 +00634 +00635 <a class="code" href="a03214.html">CPSLocated</a> *loc; +00636 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>; +00637 <a class="code" href="a02691.html">CPSLocatedBindable</a> *lb; +00638 _Owner-><a class="code" href="a03054.html#NL3D_1_1CPSLocateda39">getOwner</a>()-><a class="code" href="a03041.html#NL3D_1_1CParticleSystemz588_0">getCurrentEditedElement</a>(loc, <a class="code" href="a04223.html#a566">index</a>, lb); +00639 +00640 +00641 +00642 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a15">uint</a> k = 0; posIt != endPosIt; ++posIt, ++radiusIt, ++normalIt, ++k) +00643 { +00644 <span class="keyword">const</span> <a class="code" href="a03337.html">CRGBA</a> col = ((lb == NULL || <span class="keyword">this</span> == lb) && loc == _Owner && <a class="code" href="a04223.html#a566">index</a> == k ? CRGBA::Red : <a class="code" href="a03337.html">CRGBA</a>(127, 127, 127)); +00645 CPSUtil::buildSchmidtBasis(*normalIt, mat); +00646 CPSUtil::displayDisc(*<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), radiusIt->R, *posIt, mat, 32, col); +00647 +00648 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(*posIt); +00649 CPSUtil::displayBasis(<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>() ,<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea22">getLocalToWorldMatrix</a>(), mat, 1.f, *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea17">getFontGenerator</a>(), *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea19">getFontManager</a>()); +00650 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +00651 } +00652 } +00653 +00654 +00655 +00656 +00657 +00658 +<a name="l00659"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca54">00659</a> <span class="keywordtype">void</span> CPSZoneDisc::setMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m) +00660 { +00661 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a566">index</a> < _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>()); +00662 <span class="comment">// compute new pos</span> +00663 _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>(); +00664 <span class="comment">// compute new normal</span> +00665 _Normal[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_4">getK</a>(); +00666 } +00667 +<a name="l00668"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca24">00668</a> <a class="code" href="a02851.html">CMatrix</a> CPSZoneDisc::getMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +00669 <span class="keyword"></span>{ +00670 <a class="code" href="a02851.html">CMatrix</a> m, b; +00671 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1965_7">translate</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>]); +00672 CPSUtil::buildSchmidtBasis(_Normal[<a class="code" href="a04223.html#a566">index</a>], b); +00673 m = m * b; +00674 <span class="keywordflow">return</span> m; +00675 } +00676 +<a name="l00677"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca27">00677</a> <a class="code" href="a03128.html">CVector</a> CPSZoneDisc::getNormal(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +00678 { +00679 <span class="keywordflow">return</span> _Normal[<a class="code" href="a04223.html#a566">index</a>]; +00680 } +<a name="l00681"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca56">00681</a> <span class="keywordtype">void</span> CPSZoneDisc::setNormal(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <a class="code" href="a03128.html">CVector</a> n) +00682 { +00683 _Normal[<a class="code" href="a04223.html#a566">index</a>] = n; +00684 } +00685 +<a name="l00686"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca58">00686</a> <span class="keywordtype">void</span> CPSZoneDisc::setScale(<a class="code" href="a04558.html#a11">uint32</a> k, <span class="keywordtype">float</span> scale) +00687 { +00688 _Radius[k].R = scale; +00689 _Radius[k].R2 = scale * scale; +00690 } +00691 +<a name="l00692"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca31">00692</a> <a class="code" href="a03128.html">CVector</a> CPSZoneDisc::getScale(<a class="code" href="a04558.html#a11">uint32</a> k)<span class="keyword"> const</span> +00693 <span class="keyword"></span>{ +00694 <span class="keywordflow">return</span> <a class="code" href="a03128.html">CVector</a>(_Radius[k].R, _Radius[k].R, _Radius[k].R); +00695 } +00696 +00697 +<a name="l00698"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDisca48">00698</a> <span class="keywordtype">void</span> CPSZoneDisc::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +00699 { +00700 f.serialVersion(1); +00701 CPSZone::serial(f); +00702 f.serial(_Normal); +00703 f.serial(_Radius); +00704 } +00705 +<a name="l00706"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDiscb6">00706</a> <span class="keywordtype">void</span> CPSZoneDisc::resize(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>) +00707 { +00708 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a587">size</a> < (1 << 16)); +00709 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +00710 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +00711 } +00712 +<a name="l00713"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDiscb4">00713</a> <span class="keywordtype">void</span> CPSZoneDisc::newElement(<a class="code" href="a03214.html">CPSLocated</a> *emitterLocated, <a class="code" href="a04558.html#a11">uint32</a> emitterIndex) +00714 { +00715 <a class="code" href="a03299.html">CRadiusPair</a> rp; +00716 rp.<a class="code" href="a03299.html#NL3D_1_1CRadiusPairo0">R</a> = rp.<a class="code" href="a03299.html#NL3D_1_1CRadiusPairo1">R2</a> = 1.f; +00717 <a class="code" href="a04199.html#a6">nlassert</a>(_Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_1">getSize</a>() != _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_0">getMaxSize</a>()); +00718 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(rp); +00719 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(CVector::K); +00720 } +00721 +<a name="l00722"></a><a class="code" href="a03257.html#NL3D_1_1CPSZoneDiscb2">00722</a> <span class="keywordtype">void</span> CPSZoneDisc::deleteElement(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +00723 { +00724 _Radius.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +00725 _Normal.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +00726 } +00727 +00728 +00730 <span class="comment">// CPSZoneCylinder implementation //</span> +00732 <span class="comment"></span> +00733 +00734 <span class="comment">/*</span> +00735 <span class="comment">void CPSZoneCylinder::performMotion(TAnimationTime ellapsedTime)</span> +00736 <span class="comment">{</span> +00737 <span class="comment"> TPSAttribVector::const_iterator dimIt = _Dim.begin();</span> +00738 <span class="comment"> CPSAttrib<CPlaneBasis>::const_iterator basisIt = _Basis.begin();</span> +00739 <span class="comment"> TPSAttribVector::const_iterator cylinderPosIt, cylinderPosEnd, targetPosIt, targetPosEnd;</span> +00740 <span class="comment"> CVector dest;</span> +00741 <span class="comment"> CPSCollisionInfo ci;</span> +00742 <span class="comment"> CVector startEnd;</span> +00743 <span class="comment"> uint32 k;</span> +00744 <span class="comment"> const TPSAttribVector *speedAttr;</span> +00745 <span class="comment"></span> +00746 <span class="comment"></span> +00747 <span class="comment"></span> +00748 <span class="comment"> for (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it)</span> +00749 <span class="comment"> {</span> +00750 <span class="comment"></span> +00751 <span class="comment"> speedAttr = &((*it)->getSpeed());</span> +00752 <span class="comment"></span> +00753 <span class="comment"></span> +00754 <span class="comment"> // cycle through the cylinders</span> +00755 <span class="comment"></span> +00756 <span class="comment"> cylinderPosEnd = _Owner->getPos().end();</span> +00757 <span class="comment"> for (cylinderPosIt = _Owner->getPos().begin(); cylinderPosIt != cylinderPosEnd</span> +00758 <span class="comment"> ; ++cylinderPosIt, ++dimIt, ++basisIt)</span> +00759 <span class="comment"> {</span> +00760 <span class="comment"> </span> +00761 <span class="comment"> // we must setup the cylinder in the good basis</span> +00762 <span class="comment"></span> +00763 <span class="comment"> const CMatrix &m = CPSLocated::getConversionMatrix(*it, this->_Owner);</span> +00764 <span class="comment"></span> +00765 <span class="comment"> </span> +00766 <span class="comment"></span> +00767 <span class="comment"> // compute the new center pos</span> +00768 <span class="comment"> CVector center = m * *cylinderPosIt;</span> +00769 <span class="comment"></span> +00770 <span class="comment"> // compute a basis for the cylinder</span> +00771 <span class="comment"> CVector I = m.mulVector(basisIt->X);</span> +00772 <span class="comment"> CVector J = m.mulVector(basisIt->Y);</span> +00773 <span class="comment"> CVector K = m.mulVector(basisIt->X ^ basisIt->Y);</span> +00774 <span class="comment"></span> +00775 <span class="comment"> </span> +00776 <span class="comment"> // the pos projected (and scale) over the plane basis of the cylinder, the pos minus the center</span> +00777 <span class="comment"> CVector projectedPos, tPos;</span> +00778 <span class="comment"></span> +00779 <span class="comment"> // the same, but with the final position</span> +00780 <span class="comment"> CVector destProjectedPos, destTPos;</span> +00781 <span class="comment"></span> +00782 <span class="comment"></span> +00783 <span class="comment"> // deals with each particle</span> +00784 <span class="comment"> targetPosEnd = (*it)->getPos().end();</span> +00785 <span class="comment"> for (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k)</span> +00786 <span class="comment"> { </span> +00787 <span class="comment"> const CVector &speed = (*speedAttr)[k];</span> +00788 <span class="comment"> const CVector &pos = *targetPosIt;</span> +00789 <span class="comment"></span> +00790 <span class="comment"> </span> +00791 <span class="comment"> </span> +00792 <span class="comment"> // check wether current pos was outside the cylinder</span> +00793 <span class="comment"></span> +00794 <span class="comment"></span> +00795 <span class="comment"> tPos = pos - center;</span> +00796 <span class="comment"> projectedPos = (1 / dimIt->x) * (I * tPos) * I + (1 / dimIt->y) * (J * tPos) * J;</span> +00797 <span class="comment"> </span> +00798 <span class="comment"> if (!</span> +00799 <span class="comment"> (</span> +00800 <span class="comment"> ((tPos * K) < dimIt->z)</span> +00801 <span class="comment"> && ((tPos * K) > -dimIt->z)</span> +00802 <span class="comment"> && (projectedPos * projectedPos < 1.f) </span> +00803 <span class="comment"> )</span> +00804 <span class="comment"> )</span> +00805 <span class="comment"> {</span> +00806 <span class="comment"> dest = pos + ellapsedTime * speed;</span> +00807 <span class="comment"> destTPos = dest - center;</span> +00808 <span class="comment"> destProjectedPos = (1.f / dimIt->x) * (I * tPos) * I + (1.f / dimIt->y) * (J * tPos) * J;</span> +00809 <span class="comment"></span> +00810 <span class="comment"> // test wether the new position is inside the cylinder</span> +00811 <span class="comment"></span> +00812 <span class="comment"> </span> +00813 <span class="comment"> if (!</span> +00814 <span class="comment"> (</span> +00815 <span class="comment"> ((destTPos * K) < dimIt->z)</span> +00816 <span class="comment"> && ((destTPos * K) > -dimIt->z)</span> +00817 <span class="comment"> && (destProjectedPos * destProjectedPos < 1.f) </span> +00818 <span class="comment"> )</span> +00819 <span class="comment"> )</span> +00820 <span class="comment"> {</span> +00821 <span class="comment"> // now, detect the closest hit point (the smallest alpha, with alpha, the percent of the move vector</span> +00822 <span class="comment"> // to reach the hit point)</span> +00823 <span class="comment"></span> +00824 <span class="comment"> const float epsilon = 10E-6f;</span> +00825 <span class="comment"></span> +00826 <span class="comment"> float alphaTop, alphaBottom, alphaCyl;</span> +00827 <span class="comment"></span> +00828 <span class="comment"> const float denum = (dest - pos) * K;</span> +00829 <span class="comment"></span> +00830 <span class="comment"> // top plane</span> +00831 <span class="comment"></span> +00832 <span class="comment"> if (fabs(denum) < epsilon)</span> +00833 <span class="comment"> {</span> +00834 <span class="comment"> alphaTop = (dimIt->z - (tPos * K)) / denum;</span> +00835 <span class="comment"> if (alphaTop < 0.f) alphaTop = 1.f;</span> +00836 <span class="comment"> }</span> +00837 <span class="comment"> else</span> +00838 <span class="comment"> {</span> +00839 <span class="comment"> alphaTop = 1.f;</span> +00840 <span class="comment"> }</span> +00841 <span class="comment"></span> +00842 <span class="comment"> // bottom plane</span> +00843 <span class="comment"></span> +00844 <span class="comment"> if (fabs(denum) < epsilon)</span> +00845 <span class="comment"> {</span> +00846 <span class="comment"> alphaBottom = (- dimIt->z - (tPos * K)) / denum;</span> +00847 <span class="comment"> if (alphaBottom < 0.f) alphaBottom = 1.f;</span> +00848 <span class="comment"> }</span> +00849 <span class="comment"> else</span> +00850 <span class="comment"> {</span> +00851 <span class="comment"> alphaBottom = 1.f;</span> +00852 <span class="comment"> }</span> +00853 <span class="comment"></span> +00854 <span class="comment"> // cylinder</span> +00855 <span class="comment"></span> +00856 <span class="comment"> //expressed the src and dest positions in the cylinder basis</span> +00857 <span class="comment"></span> +00858 <span class="comment"> const float ox = tPos * I, oy = tPos * J, dx = (destTPos - tPos) * I, dy = (destTPos - tPos) * J;</span> +00859 <span class="comment"></span> +00860 <span class="comment"> // coefficients of the equation : a * alpha ^ 2 + b * alpha + c = 0</span> +00861 <span class="comment"> const float a = (dx * dx) / (dimIt->x * dimIt->x)</span> +00862 <span class="comment"> + (dy * dy) / (dimIt->y * dimIt->y);</span> +00863 <span class="comment"> const float b = 2.f * (ox * dx) / (dimIt->x * dimIt->x)</span> +00864 <span class="comment"> + (oy * dy) / (dimIt->y * dimIt->y);</span> +00865 <span class="comment"> const float c = ox * ox + oy * oy - 1;</span> +00866 <span class="comment"></span> +00867 <span class="comment"> // discriminant</span> +00868 <span class="comment"> const float delta = b * b - 4.f * a * c;</span> +00869 <span class="comment"></span> +00870 <span class="comment"> if (delta < epsilon)</span> +00871 <span class="comment"> {</span> +00872 <span class="comment"> alphaCyl = 1.f;</span> +00873 <span class="comment"> }</span> +00874 <span class="comment"> else</span> +00875 <span class="comment"> {</span> +00876 <span class="comment"> const float deltaRoot = sqrtf(delta);</span> +00877 <span class="comment"> const float r1 = (- b - deltaRoot) / (2.f / a);</span> +00878 <span class="comment"> const float r2 = (- b - deltaRoot) / (2.f / a);</span> +00879 <span class="comment"></span> +00880 <span class="comment"> if (r1 < 0.f) alphaCyl = r2;</span> +00881 <span class="comment"> else if (r2 < 0.f) alphaCyl = r1;</span> +00882 <span class="comment"> else alphaCyl = r1 < r2 ? r1 : r2;</span> +00883 <span class="comment"> }</span> +00884 <span class="comment"></span> +00885 <span class="comment"></span> +00886 <span class="comment"> // now, choose the minimum positive dist</span> +00887 <span class="comment"> </span> +00888 <span class="comment"> if (alphaTop < alphaBottom && alphaTop < alphaCyl)</span> +00889 <span class="comment"> {</span> +00890 <span class="comment"> // collision with the top plane</span> +00891 <span class="comment"> CVector startEnd = alphaTop * (dest - pos);</span> +00892 <span class="comment"> ci.newPos = pos + startEnd + PSCollideEpsilon * K;</span> +00893 <span class="comment"> ci.dist = startEnd.norm();</span> +00894 <span class="comment"> ci.newSpeed = (-2.f * (speed * K)) * K + speed;</span> +00895 <span class="comment"> ci.collisionZone = this;</span> +00896 <span class="comment"> </span> +00897 <span class="comment"> (*it)->collisionUpdate(ci, k);</span> +00898 <span class="comment"> }</span> +00899 <span class="comment"> else</span> +00900 <span class="comment"> if (alphaBottom < alphaCyl)</span> +00901 <span class="comment"> { </span> +00902 <span class="comment"> // collision with the bottom plane</span> +00903 <span class="comment"> CVector startEnd = alphaBottom * (dest - pos);</span> +00904 <span class="comment"> ci.newPos = pos + startEnd - PSCollideEpsilon * K;</span> +00905 <span class="comment"> ci.dist = startEnd.norm();</span> +00906 <span class="comment"> ci.newSpeed = (-2.f * (speed * K)) * K + speed;</span> +00907 <span class="comment"> ci.collisionZone = this;</span> +00908 <span class="comment"> </span> +00909 <span class="comment"> </span> +00910 <span class="comment"> (*it)->collisionUpdate(ci, k);</span> +00911 <span class="comment"> }</span> +00912 <span class="comment"> else</span> +00913 <span class="comment"> {</span> +00914 <span class="comment"> // collision with the cylinder</span> +00915 <span class="comment"></span> +00916 <span class="comment"> CVector startEnd = alphaCyl * (dest - pos);</span> +00917 <span class="comment"></span> +00918 <span class="comment"> // normal at the hit point. It is the gradient of the implicit equation x^2 / a^2 + y^2 / b^2 - R^ 2= 0</span> +00919 <span class="comment"> // so we got unormalized n = (2 x / a ^ 2, 2 y / b ^ 2, 0) in the basis of the cylinder</span> +00920 <span class="comment"> // As we'll normalize it, we don't need the 2 factor</span> +00921 <span class="comment"> </span> +00922 <span class="comment"> float px = ox + alphaCyl * dx;</span> +00923 <span class="comment"> float py = oy + alphaCyl * dy;</span> +00924 <span class="comment"></span> +00925 <span class="comment"> CVector normal = px / (dimIt->x * dimIt->x) * I + py / (dimIt->y * dimIt->y) * J;</span> +00926 <span class="comment"> normal.normalize();</span> +00927 <span class="comment"></span> +00928 <span class="comment"> ci.newPos = pos + startEnd - PSCollideEpsilon * normal;</span> +00929 <span class="comment"> ci.dist = startEnd.norm();</span> +00930 <span class="comment"> ci.newSpeed = (-2.f * (speed * normal)) * normal + speed;</span> +00931 <span class="comment"> ci.collisionZone = this;</span> +00932 <span class="comment"></span> +00933 <span class="comment"> (*it)->collisionUpdate(ci, k);</span> +00934 <span class="comment"> } </span> +00935 <span class="comment"></span> +00936 <span class="comment"> }</span> +00937 <span class="comment"> } </span> +00938 <span class="comment"> }</span> +00939 <span class="comment"> }</span> +00940 <span class="comment"> }</span> +00941 <span class="comment">}</span> +00942 <span class="comment">*/</span> +00943 +00944 +00945 +<a name="l00946"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera44">00946</a> <span class="keywordtype">void</span> CPSZoneCylinder::performMotion(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +00947 { +00948 <a class="code" href="a04726.html#a0">MINI_TIMER</a>(<a class="code" href="a05363.html#a204">PSStatsZoneCylinder</a>) +00949 TPSAttribVector::const_iterator dimIt; +00950 <a class="code" href="a03135.html">CPSAttrib<CPlaneBasis></a>::const_iterator basisIt; +00951 TPSAttribVector::const_iterator cylinderPosIt, cylinderPosEnd, targetPosIt, targetPosEnd; +00952 <a class="code" href="a03128.html">CVector</a> dest; +00953 <a class="code" href="a03151.html">CPSCollisionInfo</a> ci; +00954 <a class="code" href="a04558.html#a11">uint32</a> k; +00955 <span class="keyword">const</span> <a class="code" href="a03135.html">TPSAttribVector</a> *speedAttr; +00956 +00957 +00958 +00959 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +00960 { +00961 +00962 speedAttr = &((*it)->getSpeed()); +00963 +00964 +00965 <span class="comment">// cycle through the cylinders</span> +00966 +00967 cylinderPosEnd = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +00968 <span class="keywordflow">for</span> (cylinderPosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), basisIt = _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(), dimIt = <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>() +00969 ; cylinderPosIt != cylinderPosEnd +00970 ; ++cylinderPosIt, ++dimIt, ++basisIt) +00971 { +00972 +00973 <span class="comment">// we must setup the cylinder in the good basis</span> +00974 +00975 <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m = CPSLocated::getConversionMatrix(*it, this->_Owner); +00976 +00977 +00978 +00979 <span class="comment">// compute the new center pos</span> +00980 <a class="code" href="a03128.html">CVector</a> center = m * *cylinderPosIt; +00981 +00982 <span class="comment">// compute a basis for the cylinder</span> +00983 <a class="code" href="a03128.html">CVector</a> I = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(basisIt->X); +00984 <a class="code" href="a03128.html">CVector</a> J = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(basisIt->Y); +00985 <a class="code" href="a03128.html">CVector</a> K = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(basisIt->X ^ basisIt->Y); +00986 +00987 +00988 <span class="comment">// the pos projected (and scale) over the plane basis of the cylinder, the pos minus the center</span> +00989 <a class="code" href="a03128.html">CVector</a> projectedPos, tPos; +00990 +00991 <span class="comment">// the same, but with the final position</span> +00992 <a class="code" href="a03128.html">CVector</a> destProjectedPos, destTPos; +00993 +00994 +00995 <span class="comment">// deals with each particle</span> +00996 targetPosEnd = (*it)->getPos().end(); +00997 TPSAttribCollisionInfo::const_iterator ciIt = (*it)->getCollisionInfo().begin(); +00998 <span class="keywordflow">for</span> (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k, ++ciIt) +00999 { +01000 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &speed = (*speedAttr)[k]; +01001 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &pos = *targetPosIt; +01002 +01003 +01004 +01005 <span class="comment">// check wether current pos was outside the cylinder</span> +01006 +01007 +01008 tPos = pos - center; +01009 projectedPos = (1 / dimIt->x) * (I * tPos) * I + (1 / dimIt->y) * (J * tPos) * J; +01010 +01011 <span class="keywordflow">if</span> (! +01012 ( +01013 ((tPos * K) < dimIt->z) +01014 && ((tPos * K) > -dimIt->z) +01015 && (projectedPos * projectedPos < 1.f) +01016 ) +01017 ) +01018 { +01019 dest = pos + ellapsedTime * speed * ciIt->TimeSliceRatio; +01020 destTPos = dest - center; +01021 destProjectedPos = (1.f / dimIt->x) * (I * destTPos) * I + (1.f / dimIt->y) * (J * destTPos) * J; +01022 +01023 <span class="comment">// test wether the new position is inside the cylinder</span> +01024 +01025 +01026 <span class="keywordflow">if</span> ( +01027 ( +01028 ((destTPos * K) < dimIt->z) +01029 && ((destTPos * K) > -dimIt->z) +01030 && (destProjectedPos * destProjectedPos < 1.f) +01031 ) +01032 ) +01033 { +01034 <span class="comment">// now, detect the closest hit point (the smallest alpha, with alpha, the percent of the move vector</span> +01035 <span class="comment">// to reach the hit point)</span> +01036 +01037 <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 10E-3f; +01038 +01039 <span class="keywordtype">float</span> alphaTop, alphaBottom, alphaCyl; +01040 +01041 <span class="keyword">const</span> <span class="keywordtype">float</span> denum = (dest - pos) * K; +01042 +01043 <span class="comment">// top plane</span> +01044 +01045 <span class="keywordflow">if</span> (fabs(denum) < epsilon) +01046 { +01047 alphaTop = (dimIt->z - (tPos * K)) / denum; +01048 <span class="keywordflow">if</span> (alphaTop < 0.f) alphaTop = 1.f; +01049 } +01050 <span class="keywordflow">else</span> +01051 { +01052 alphaTop = 1.f; +01053 } +01054 +01055 <span class="comment">// bottom plane</span> +01056 +01057 <span class="keywordflow">if</span> (fabs(denum) < epsilon) +01058 { +01059 alphaBottom = (- dimIt->z - (tPos * K)) / denum; +01060 <span class="keywordflow">if</span> (alphaBottom < 0.f) alphaBottom = 1.f; +01061 } +01062 <span class="keywordflow">else</span> +01063 { +01064 alphaBottom = 1.f; +01065 } +01066 +01067 <span class="comment">// cylinder</span> +01068 +01069 <span class="comment">//expressed the src and dest positions in the cylinder basis</span> +01070 +01071 <span class="keyword">const</span> <span class="keywordtype">float</span> ox = tPos * I, oy = tPos * J, dx = (destTPos - tPos) * I, dy = (destTPos - tPos) * J; +01072 +01073 <span class="comment">// coefficients of the equation : a * alpha ^ 2 + b * alpha + c = 0</span> +01074 <span class="keyword">const</span> <span class="keywordtype">float</span> a = (dx * dx) / (dimIt->x * dimIt->x) +01075 + (dy * dy) / (dimIt->y * dimIt->y); +01076 <span class="keyword">const</span> <span class="keywordtype">float</span> b = 2.f * ((ox * dx) / (dimIt->x * dimIt->x) +01077 + (oy * dy) / (dimIt->y * dimIt->y)); +01078 <span class="keyword">const</span> <span class="keywordtype">float</span> c = (ox * ox) / (dimIt->x * dimIt->x) + (oy * oy) / (dimIt->y * dimIt->y) - 1; +01079 +01080 <span class="comment">// discriminant</span> +01081 <span class="keyword">const</span> <span class="keywordtype">float</span> delta = b * b - 4.f * a * c; +01082 +01083 <span class="keywordflow">if</span> (delta < epsilon) +01084 { +01085 alphaCyl = 1.f; +01086 } +01087 <span class="keywordflow">else</span> +01088 { +01089 <span class="keyword">const</span> <span class="keywordtype">float</span> deltaRoot = sqrtf(delta); +01090 <span class="keyword">const</span> <span class="keywordtype">float</span> r1 = (- b + 2.f * deltaRoot) / (2.f * a); +01091 <span class="keyword">const</span> <span class="keywordtype">float</span> r2 = (- b - 2.f * deltaRoot) / (2.f * a); +01092 +01093 <span class="keywordflow">if</span> (r1 < 0.f) alphaCyl = r2; +01094 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (r2 < 0.f) alphaCyl = r1; +01095 <span class="keywordflow">else</span> alphaCyl = r1 < r2 ? r1 : r2; +01096 +01097 <span class="keywordflow">if</span> (alphaCyl < 0.f) alphaCyl = 1.f; +01098 } +01099 +01100 +01101 <span class="comment">// now, choose the minimum positive dist</span> +01102 +01103 +01104 +01105 <span class="keywordflow">if</span> (alphaTop < alphaBottom && alphaTop < alphaCyl) +01106 { +01107 <span class="comment">// collision with the top plane</span> +01108 <a class="code" href="a03128.html">CVector</a> startEnd = alphaTop * (dest - pos); +01109 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = pos + startEnd + <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * K; +01110 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +01111 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = (-2.f * (speed * K)) * K + speed; +01112 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +01113 +01114 (*it)->collisionUpdate(ci, k); +01115 } +01116 <span class="keywordflow">else</span> +01117 <span class="keywordflow">if</span> (alphaBottom < alphaCyl) +01118 { +01119 <span class="comment">// collision with the bottom plane</span> +01120 <a class="code" href="a03128.html">CVector</a> startEnd = alphaBottom * (dest - pos); +01121 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = pos + startEnd - <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * K; +01122 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +01123 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = (-2.f * (speed * K)) * K + speed; +01124 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +01125 +01126 +01127 (*it)->collisionUpdate(ci, k); +01128 } +01129 <span class="keywordflow">else</span> +01130 { +01131 <span class="comment">// collision with the cylinder</span> +01132 +01133 <a class="code" href="a03128.html">CVector</a> startEnd = alphaCyl * (dest - pos); +01134 +01135 <span class="comment">// normal at the hit point. It is the gradient of the implicit equation x^2 / a^2 + y^2 / b^2 - R^ 2= 0</span> +01136 <span class="comment">// so we got unormalized n = (2 x / a ^ 2, 2 y / b ^ 2, 0) in the basis of the cylinder</span> +01137 <span class="comment">// As we'll normalize it, we don't need the 2 factor</span> +01138 +01139 <span class="keywordtype">float</span> px = ox + alphaCyl * dx; +01140 <span class="keywordtype">float</span> py = oy + alphaCyl * dy; +01141 +01142 <a class="code" href="a03128.html">CVector</a> normal = px / (dimIt->x * dimIt->x) * I + py / (dimIt->y * dimIt->y) * J; +01143 normal.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_1">normalize</a>(); +01144 +01145 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = pos + startEnd + <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * normal; +01146 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +01147 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = (-2.f * (speed * normal)) * normal + speed; +01148 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +01149 +01150 (*it)->collisionUpdate(ci, k); +01151 } +01152 +01153 } +01154 } +01155 } +01156 } +01157 } +01158 } +01159 +<a name="l01160"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera61">01160</a> <span class="keywordtype">void</span> CPSZoneCylinder::show(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +01161 { +01162 TPSAttribVector::const_iterator dimIt = <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>() +01163 ,posIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>() +01164 , endPosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +01165 +01166 <a class="code" href="a03135.html">CPSAttrib<CPlaneBasis></a>::const_iterator basisIt = _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +01167 +01168 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +01169 <a class="code" href="a02851.html">CMatrix</a> mat; +01170 +01171 +01172 +01173 <a class="code" href="a03214.html">CPSLocated</a> *loc; +01174 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>; +01175 <a class="code" href="a02691.html">CPSLocatedBindable</a> *lb; +01176 _Owner-><a class="code" href="a03054.html#NL3D_1_1CPSLocateda39">getOwner</a>()-><a class="code" href="a03041.html#NL3D_1_1CParticleSystemz588_0">getCurrentEditedElement</a>(loc, <a class="code" href="a04223.html#a566">index</a>, lb); +01177 +01178 +01179 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a11">uint32</a> k = 0; posIt != endPosIt; ++posIt, ++dimIt, ++basisIt, ++k) +01180 { +01181 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_10">setRot</a>(basisIt->X, basisIt->Y, basisIt->X ^ basisIt->Y); +01182 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(CVector::Null); +01183 +01184 <span class="keyword">const</span> <a class="code" href="a03337.html">CRGBA</a> col = ((lb == NULL || <span class="keyword">this</span> == lb) && loc == _Owner && <a class="code" href="a04223.html#a566">index</a> == k ? CRGBA::Red : <a class="code" href="a03337.html">CRGBA</a>(127, 127, 127)); +01185 +01186 +01187 CPSUtil::displayCylinder(*<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), *posIt, mat, *dimIt, 32, col); +01188 +01189 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(*posIt); +01190 CPSUtil::displayBasis(<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>() ,<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea22">getLocalToWorldMatrix</a>(), mat, 1.f, *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea17">getFontGenerator</a>(), *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea19">getFontManager</a>()); +01191 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +01192 +01193 } +01194 } +01195 +01196 +01197 +<a name="l01198"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera54">01198</a> <span class="keywordtype">void</span> CPSZoneCylinder::setMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m) +01199 { +01200 <span class="comment">// transform the basis </span> +01201 _Basis[<a class="code" href="a04223.html#a566">index</a>].X = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>(); +01202 _Basis[<a class="code" href="a04223.html#a566">index</a>].Y = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>(); +01203 +01204 <span class="comment">// compute new pos</span> +01205 _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>(); +01206 +01207 +01208 } +01209 +01210 +01211 +<a name="l01212"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera24">01212</a> <a class="code" href="a02851.html">CMatrix</a> CPSZoneCylinder::getMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +01213 <span class="keyword"></span>{ +01214 <a class="code" href="a02851.html">CMatrix</a> m; +01215 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_10">setRot</a>(_Basis[<a class="code" href="a04223.html#a566">index</a>].X, _Basis[<a class="code" href="a04223.html#a566">index</a>].Y, _Basis[<a class="code" href="a04223.html#a566">index</a>].X ^_Basis[<a class="code" href="a04223.html#a566">index</a>].Y); +01216 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>]); +01217 <span class="keywordflow">return</span> m; +01218 } +01219 +01220 +<a name="l01221"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera58">01221</a> <span class="keywordtype">void</span> CPSZoneCylinder::setScale(<a class="code" href="a04558.html#a11">uint32</a> k, <span class="keywordtype">float</span> scale) +01222 { +01223 <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>[k] = <a class="code" href="a03128.html">CVector</a>(scale, scale, scale); +01224 } +01225 +<a name="l01226"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera31">01226</a> <a class="code" href="a03128.html">CVector</a> CPSZoneCylinder::getScale(<a class="code" href="a04558.html#a11">uint32</a> k)<span class="keyword"> const</span> +01227 <span class="keyword"></span>{ +01228 <span class="keywordflow">return</span> <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>[k]; +01229 } +01230 +<a name="l01231"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera57">01231</a> <span class="keywordtype">void</span> CPSZoneCylinder::setScale(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &<a class="code" href="a04223.html#a626">s</a>) +01232 { +01233 <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>[<a class="code" href="a04223.html#a566">index</a>] = <a class="code" href="a04223.html#a626">s</a>; +01234 } +01235 +01236 +<a name="l01237"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylindera48">01237</a> <span class="keywordtype">void</span> CPSZoneCylinder::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +01238 { +01239 f.serialVersion(1); +01240 CPSZone::serial(f); +01241 f.serial(_Basis); +01242 f.serial(_Dim); +01243 } +01244 +01245 +01246 +<a name="l01247"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderb6">01247</a> <span class="keywordtype">void</span> CPSZoneCylinder::resize(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>) +01248 { +01249 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a587">size</a> < (1 << 16)); +01250 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +01251 <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +01252 } +01253 +<a name="l01254"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderb4">01254</a> <span class="keywordtype">void</span> CPSZoneCylinder::newElement(<a class="code" href="a03214.html">CPSLocated</a> *emitterLocated, <a class="code" href="a04558.html#a11">uint32</a> emitterIndex) +01255 { +01256 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(<a class="code" href="a03083.html">CPlaneBasis</a>(CVector::K)); +01257 <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(<a class="code" href="a03128.html">CVector</a>(1, 1, 1)); +01258 } +01259 +<a name="l01260"></a><a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderb2">01260</a> <span class="keywordtype">void</span> CPSZoneCylinder::deleteElement(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +01261 { +01262 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +01263 <a class="code" href="a03256.html#NL3D_1_1CPSZoneCylinderp4">_Dim</a>.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +01264 } +01265 +01266 +01268 <span class="comment">// implementation of CPSZoneRectangle //</span> +01270 <span class="comment"></span> +01271 +01272 +01273 +01274 +<a name="l01275"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea44">01275</a> <span class="keywordtype">void</span> CPSZoneRectangle::performMotion(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +01276 { +01277 <a class="code" href="a04726.html#a0">MINI_TIMER</a>(<a class="code" href="a05363.html#a203">PSStatsZoneRectangle</a>) +01278 <span class="comment">// for each target, we must check wether they are going through the rectangle</span> +01279 <span class="comment">// if so they must bounce</span> +01280 TPSAttribVector::const_iterator rectanglePosIt, rectanglePosEnd, targetPosIt, targetPosEnd; +01281 <a class="code" href="a03135.html">CPSAttrib<CPlaneBasis></a>::const_iterator basisIt; +01282 TPSAttribFloat::const_iterator widthIt, heightIt; +01283 +01284 <a class="code" href="a03128.html">CVector</a> dest; +01285 <a class="code" href="a03151.html">CPSCollisionInfo</a> ci; +01286 <a class="code" href="a03128.html">CVector</a> startEnd; +01287 <a class="code" href="a04558.html#a11">uint32</a> k; +01288 <span class="keyword">const</span> <a class="code" href="a03135.html">TPSAttribVector</a> *speedAttr; +01289 <span class="keywordtype">float</span> posSide, negSide; +01290 +01291 <span class="comment">// alpha is the ratio that gives the percent of endPos - startPos that hit the rectangle</span> +01292 <span class="keywordtype">float</span> <a class="code" href="a04223.html#a663">alpha</a>; +01293 +01294 <a class="code" href="a03128.html">CVector</a> center; +01295 +01296 <span class="keywordflow">for</span> (TTargetCont::iterator it = _Targets.begin(); it != _Targets.end(); ++it) +01297 { +01298 +01299 basisIt = _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +01300 heightIt = _Height.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +01301 widthIt = _Width.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); +01302 +01303 speedAttr = &((*it)->getSpeed()); +01304 <span class="comment">// cycle through the rectangle</span> +01305 +01306 rectanglePosEnd = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_3">end</a>(); +01307 <span class="keywordflow">for</span> (rectanglePosIt = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>().<a class="code" href="a03135.html#NL3D_1_1CPSAttribz708_1">begin</a>(); rectanglePosIt != rectanglePosEnd +01308 ; ++rectanglePosIt, ++basisIt, ++widthIt, ++heightIt) +01309 { +01310 +01311 <span class="comment">// we must setup the rectangle in the good basis</span> +01312 +01313 <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m = CPSLocated::getConversionMatrix(*it, this->_Owner); +01314 +01315 +01316 +01317 <a class="code" href="a03082.html">NLMISC::CPlane</a> p; +01318 center = m * (*rectanglePosIt); +01319 +01320 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> X = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(basisIt->X); +01321 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> Y = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1968_1">mulVector</a>(basisIt->Y); +01322 +01323 p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_2">make</a>(X ^ Y, center); +01324 +01325 <span class="comment">// deals with each particle</span> +01326 +01327 <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 0.5f * <a class="code" href="a05363.html#a273">PSCollideEpsilon</a>; +01328 +01329 targetPosEnd = (*it)->getPos().end(); +01330 TPSAttribCollisionInfo::const_iterator ciIt = (*it)->getCollisionInfo().begin(); +01331 <span class="keywordflow">for</span> (targetPosIt = (*it)->getPos().begin(), k = 0; targetPosIt != targetPosEnd; ++targetPosIt, ++k, ++ciIt) +01332 { +01333 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &pos = *targetPosIt; +01334 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &speed = (*speedAttr)[k]; +01335 <span class="comment">// check whether the located is going through the rectangle</span> +01336 dest = pos + ellapsedTime * speed * ciIt->TimeSliceRatio; +01337 +01338 +01339 posSide = p * pos; +01340 negSide = p * dest; +01341 +01342 <span class="keywordflow">if</span> (posSide >= - epsilon && negSide <= epsilon) +01343 { +01344 <span class="keywordflow">if</span> (fabsf(posSide - negSide) > <a class="code" href="a04061.html#a0">std::numeric_limits<float>::min</a>()) +01345 { +01346 <a class="code" href="a04223.html#a663">alpha</a> = posSide / (posSide - negSide); +01347 } +01348 <span class="keywordflow">else</span> +01349 { +01350 <a class="code" href="a04223.html#a663">alpha</a> = 0.f; +01351 } +01352 startEnd = <a class="code" href="a04223.html#a663">alpha</a> * (dest - pos); +01353 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo1">dist</a> = startEnd.<a class="code" href="a03128.html#NLMISC_1_1CVectorz2049_0">norm</a>(); +01354 <span class="comment">// we translate the particle from an epsilon so that it won't get hooked to the rectangle</span> +01355 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> = pos + startEnd; +01356 +01357 +01358 +01359 +01360 <span class="keywordflow">if</span> ( fabs( (pos - center) * X ) < *widthIt && fabs( (pos - center) * Y ) < *heightIt) <span class="comment">// check collision against rectangle</span> +01361 { +01362 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo2">newPos</a> += <a class="code" href="a05363.html#a273">PSCollideEpsilon</a> * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>(); +01363 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo3">newSpeed</a> = _BounceFactor * (speed - 2.0f * (speed * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()) * p.<a class="code" href="a03082.html#NLMISC_1_1CPlanez1990_0">getNormal</a>()); +01364 ci.<a class="code" href="a03151.html#NL3D_1_1CPSCollisionInfoo0">collisionZone</a> = <span class="keyword">this</span>; +01365 (*it)->collisionUpdate(ci, k); +01366 } +01367 +01368 } +01369 } +01370 } +01371 } +01372 } +01373 +01374 +<a name="l01375"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea61">01375</a> <span class="keywordtype">void</span> CPSZoneRectangle::show(<a class="code" href="a05363.html#a366">TAnimationTime</a> ellapsedTime) +01376 { +01377 <a class="code" href="a04199.html#a6">nlassert</a>(_Owner); +01378 <span class="keyword">const</span> <a class="code" href="a04558.html#a15">uint</a> <a class="code" href="a04223.html#a587">size</a> = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda44">getSize</a>(); +01379 <span class="keywordflow">if</span> (!<a class="code" href="a04223.html#a587">size</a>) <span class="keywordflow">return</span>; +01380 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +01381 <a class="code" href="a02851.html">CMatrix</a> mat; +01382 +01383 <a class="code" href="a03214.html">CPSLocated</a> *loc; +01384 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>; +01385 <a class="code" href="a02691.html">CPSLocatedBindable</a> *lb; +01386 _Owner-><a class="code" href="a03054.html#NL3D_1_1CPSLocateda39">getOwner</a>()-><a class="code" href="a03041.html#NL3D_1_1CParticleSystemz588_0">getCurrentEditedElement</a>(loc, <a class="code" href="a04223.html#a566">index</a>, lb); +01387 +01388 <span class="keywordflow">for</span> (<a class="code" href="a04558.html#a15">uint</a> k = 0; k < <a class="code" href="a04223.html#a587">size</a>; ++k) +01389 { +01390 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &I = _Basis[k].X; +01391 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &J = _Basis[k].Y; +01392 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_10">setRot</a>(I, J , I ^J); +01393 mat.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[k]); +01394 CPSUtil::displayBasis(<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea22">getLocalToWorldMatrix</a>(), mat, 1.f, *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea17">getFontGenerator</a>(), *<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea19">getFontManager</a>()); +01395 <a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea59">setupDriverModelMatrix</a>(); +01396 +01397 <span class="keyword">const</span> <a class="code" href="a03337.html">CRGBA</a> col = ((lb == NULL || <span class="keyword">this</span> == lb) && loc == _Owner && <a class="code" href="a04223.html#a566">index</a> == k ? CRGBA::Red : <a class="code" href="a03337.html">CRGBA</a>(127, 127, 127)); +01398 +01399 +01400 +01401 <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &pos = _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[k]; +01402 CPSUtil::display3DQuad(*<a class="code" href="a02691.html#NL3D_1_1CPSZoneSpherea14">getDriver</a>(), pos + I * _Width[k] + J * _Height[k] +01403 , pos + I * _Width[k] - J * _Height[k] +01404 , pos - I * _Width[k] - J * _Height[k] +01405 , pos - I * _Width[k] + J * _Height[k], col); +01406 } +01407 } +01408 +<a name="l01409"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea54">01409</a> <span class="keywordtype">void</span> CPSZoneRectangle::setMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a02851.html">CMatrix</a> &m) +01410 { +01411 <a class="code" href="a04199.html#a6">nlassert</a>(_Owner); +01412 +01413 _Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>] = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_6">getPos</a>(); +01414 _Basis[<a class="code" href="a04223.html#a566">index</a>].X = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_2">getI</a>(); +01415 _Basis[<a class="code" href="a04223.html#a566">index</a>].Y = m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1963_3">getJ</a>(); +01416 } +01417 +01418 +<a name="l01419"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea24">01419</a> <a class="code" href="a02851.html">CMatrix</a> CPSZoneRectangle::getMatrix(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +01420 <span class="keyword"></span>{ +01421 <a class="code" href="a04199.html#a6">nlassert</a>(_Owner); +01422 <a class="code" href="a02851.html">CMatrix</a> m; +01423 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_10">setRot</a>(_Basis[<a class="code" href="a04223.html#a566">index</a>].X, _Basis[<a class="code" href="a04223.html#a566">index</a>].Y, _Basis[<a class="code" href="a04223.html#a566">index</a>].X ^ _Basis[<a class="code" href="a04223.html#a566">index</a>].Y); +01424 m.<a class="code" href="a02851.html#NLMISC_1_1CMatrixz1961_4">setPos</a>(_Owner-><a class="code" href="a03214.html#NL3D_1_1CPSLocateda42">getPos</a>()[<a class="code" href="a04223.html#a566">index</a>]); +01425 <span class="keywordflow">return</span> m; +01426 } +01427 +<a name="l01428"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea58">01428</a> <span class="keywordtype">void</span> CPSZoneRectangle::setScale(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keywordtype">float</span> scale) +01429 { +01430 _Width[<a class="code" href="a04223.html#a566">index</a>] = scale; +01431 _Height[<a class="code" href="a04223.html#a566">index</a>] = scale; +01432 } +<a name="l01433"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea57">01433</a> <span class="keywordtype">void</span> CPSZoneRectangle::setScale(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>, <span class="keyword">const</span> <a class="code" href="a03128.html">CVector</a> &<a class="code" href="a04223.html#a626">s</a>) +01434 { +01435 _Width[<a class="code" href="a04223.html#a566">index</a>] = <a class="code" href="a04223.html#a626">s</a>.x; +01436 _Height[<a class="code" href="a04223.html#a566">index</a>] = <a class="code" href="a04223.html#a626">s</a>.y; +01437 } +<a name="l01438"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea31">01438</a> <a class="code" href="a03128.html">CVector</a> CPSZoneRectangle::getScale(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>)<span class="keyword"> const</span> +01439 <span class="keyword"></span>{ +01440 <span class="keywordflow">return</span> <a class="code" href="a03128.html">CVector</a>(_Width[<a class="code" href="a04223.html#a566">index</a>], _Height[<a class="code" href="a04223.html#a566">index</a>], 1.f); +01441 } +01442 +01443 +01444 +<a name="l01445"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectanglea48">01445</a> <span class="keywordtype">void</span> CPSZoneRectangle::serial(<a class="code" href="a02270.html">NLMISC::IStream</a> &f) <span class="keywordflow">throw</span>(<a class="code" href="a03781.html">NLMISC::EStream</a>) +01446 { +01447 f.serialVersion(1); +01448 CPSZone::serial(f); +01449 f.serial(_Basis); +01450 f.serial(_Width); +01451 f.serial(_Height); +01452 } +01453 +01454 +<a name="l01455"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectangleb6">01455</a> <span class="keywordtype">void</span> CPSZoneRectangle::resize(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a587">size</a>) +01456 { +01457 <a class="code" href="a04199.html#a6">nlassert</a>(<a class="code" href="a04223.html#a587">size</a> < (1 << 16)); +01458 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +01459 _Width.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +01460 _Height.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz704_2">resize</a>(<a class="code" href="a04223.html#a587">size</a>); +01461 } +01462 +<a name="l01463"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectangleb4">01463</a> <span class="keywordtype">void</span> CPSZoneRectangle::newElement(<a class="code" href="a03214.html">CPSLocated</a> *emitterLocated, <a class="code" href="a04558.html#a11">uint32</a> emitterIndex) +01464 { +01465 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(<a class="code" href="a03083.html">CPlaneBasis</a>(CVector::K)); +01466 _Width.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(1.f); +01467 _Height.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_1">insert</a>(1.f); +01468 } +01469 +<a name="l01470"></a><a class="code" href="a03259.html#NL3D_1_1CPSZoneRectangleb2">01470</a> <span class="keywordtype">void</span> CPSZoneRectangle::deleteElement(<a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a566">index</a>) +01471 { +01472 _Basis.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +01473 _Width.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +01474 _Height.<a class="code" href="a03135.html#NL3D_1_1CPSAttribz710_2">remove</a>(<a class="code" href="a04223.html#a566">index</a>); +01475 } +01476 +01477 +01478 +01479 } <span class="comment">// NL3D</span> +</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 06:35:02 2004 for NeL by +<a href="http://www.doxygen.org/index.html"> +<img src="doxygen.png" alt="doxygen" align="middle" border=0 > +</a>1.3.6 </small></address> +</body> +</html> |