# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ps_plane_basis_maker.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 
00029 #include "3d/ps_plane_basis_maker.h"
00030 #include "3d/ps_register_plane_basis_attribs.h"
00031 
00032 namespace NL3D 
00033 {
00034 
00035 
00036 CPlaneBasis CPSPlaneBasisGradient::DefaultPlaneBasisTab[] = { CPlaneBasis(NLMISC::CVector::I), CPlaneBasis(NLMISC::CVector::J) };
00037 
00039 // CPSPlaneBasisFollowSpeed implementation //
00041 
00043 CPlaneBasis CPSPlaneBasisFollowSpeed::get(CPSLocated *loc, uint32 index)
00044 {
00045    return (CPlaneBasis(loc->getSpeed()[index]));
00046 }
00047 
00049 void *CPSPlaneBasisFollowSpeed::make(CPSLocated *loc,
00050                                                                          uint32 startIndex,
00051                                                                          void *tab, uint32 stride,
00052                                                                          uint32 numAttrib,
00053                                                                          bool enableNoCopy /* = false*/,
00054                                                                          uint32 srcStep /*= (1 << 16)*/
00055                                                                         ) const
00056 {
00057         nlassert(numAttrib);
00058         if (srcStep == (1 << 16))
00059         {               
00060                 TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin() + startIndex
00061                                                                                 , endSpeedIt = loc->getSpeed().begin() + startIndex + numAttrib;
00062                 uint8 *ptDat  = (uint8 *) tab; 
00063                 do
00064                 {
00065                         *(CPlaneBasis *) ptDat = CPlaneBasis(*speedIt);
00066                         ++ speedIt;
00067                         ptDat += stride;
00068                 }
00069                 while (speedIt != endSpeedIt);
00070                 return tab;
00071         }
00072         else
00073         {
00074                 uint32 fpIndex = startIndex * srcStep;
00075                 const TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin();                                                                                
00076                 uint8 *ptDat  = (uint8 *) tab; 
00077                 while (numAttrib --)
00078                 {
00079                         *(CPlaneBasis *) ptDat = CPlaneBasis(*(speedIt + (fpIndex >> 16)));                     
00080                         ptDat += stride;
00081                         fpIndex += srcStep;
00082                 }               
00083                 return tab;     
00084         }
00085 }
00086 
00088 void CPSPlaneBasisFollowSpeed::make4(CPSLocated *loc,
00089                                                                          uint32 startIndex,
00090                                                                          void *tab,
00091                                                                          uint32 stride,
00092                                                                          uint32 numAttrib,
00093                                                                          uint32 srcStep /*= (1 << 16)*/
00094                                                                         ) const
00095 {
00096         nlassert(numAttrib);
00097         if (srcStep == (1 << 16))
00098         {               
00099                 TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin() + startIndex
00100                                                                                 , endSpeedIt = loc->getSpeed().begin() + startIndex + numAttrib;        
00101                 uint8 *ptDat  = (uint8 *) tab;
00102                 do
00103                 {
00104                         *(CPlaneBasis *) ptDat = CPlaneBasis(*speedIt);
00105                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00106                         ptDat += stride;
00107                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00108                         ptDat += stride;
00109                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00110                         ptDat += stride << 1;
00111                         ++ speedIt;             
00112                 }
00113                 while (speedIt != endSpeedIt);
00114         }
00115         else
00116         {               
00117                 uint32 fpIndex = startIndex * srcStep;
00118                 const TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin();        
00119                 uint8 *ptDat  = (uint8 *) tab;
00120                 while (numAttrib --)
00121                 {
00122                         *(CPlaneBasis *) ptDat = CPlaneBasis(*(speedIt + (fpIndex >> 16)));
00123                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00124                         ptDat += stride;
00125                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00126                         ptDat += stride;
00127                         *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00128                         ptDat += stride << 1;
00129                         fpIndex += srcStep;
00130                 }               
00131         }
00132 }               
00133 
00135 void CPSPlaneBasisFollowSpeed::makeN(CPSLocated *loc,
00136                                                                          uint32 startIndex,
00137                                                                          void *tab,
00138                                                                          uint32 stride,
00139                                                                          uint32 numAttrib,
00140                                                                          uint32 nbReplicate,
00141                                                                          uint32 srcStep /*= (1 << 16) */
00142                                                                         ) const
00143 {
00144         nlassert(numAttrib);
00145         if (srcStep == (1 << 16))
00146         {
00147                 nlassert(nbReplicate > 1); 
00148                 TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin() + startIndex
00149                                                                                 , endSpeedIt = loc->getSpeed().begin() + startIndex + numAttrib;        
00150                 uint8 *ptDat  = (uint8 *) tab;
00151                 uint k; 
00152                 do
00153                 {
00154                         *(CPlaneBasis *) ptDat = CPlaneBasis(*speedIt);
00155                         
00156                         k = nbReplicate - 1;            
00157 
00158                         do
00159                         {
00160                                 *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00161                                 ptDat += stride;
00162                         }
00163                         while (--k);
00164                         ptDat += stride;
00165                 
00166                         ++ speedIt;             
00167                 }
00168                 while (speedIt != endSpeedIt);
00169         }
00170         else
00171         {
00172                 uint32 fpIndex = startIndex * srcStep;
00173                 nlassert(nbReplicate > 1); 
00174                 const TPSAttribVector::const_iterator speedIt = loc->getSpeed().begin();
00175                 uint8 *ptDat  = (uint8 *) tab;
00176                 uint k; 
00177                 while (numAttrib --)
00178                 {
00179                         *(CPlaneBasis *) ptDat = CPlaneBasis(*(speedIt + (fpIndex >> 16)));
00180                         
00181                         k = nbReplicate - 1;            
00182 
00183                         do
00184                         {
00185                                 *(CPlaneBasis *) (ptDat + stride) = *(CPlaneBasis *) ptDat;
00186                                 ptDat += stride;
00187                         }
00188                         while (--k);
00189                         ptDat += stride;
00190         
00191                         fpIndex += srcStep;
00192                 }               
00193         }
00194 }
00195 
00196 
00198 // CSpinnerFunctor implementation                  //
00200 
00201 
00203 CSpinnerFunctor::CSpinnerFunctor() : _NbSamples(16), _Axis(NLMISC::CVector::K)
00204 {
00205         updateSamples();
00206 }
00207 
00209 void CSpinnerFunctor::setAxis(const NLMISC::CVector &axis)
00210 {
00211         _Axis = axis;
00212         updateSamples();
00213 }
00214 
00216 const void CSpinnerFunctor::setNumSamples(uint32 nbSamples)
00217 {
00218         nlassert(nbSamples > 0);
00219         _NbSamples = nbSamples;
00220         updateSamples();
00221 }
00222 
00224 const uint32 CSpinnerFunctor::getNumSamples(void) const
00225 {
00226         return _NbSamples;
00227 }
00228 
00230 void CSpinnerFunctor::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00231 {
00232         f.serialVersion(1);
00233         f.serial(_Axis, _NbSamples);
00234         if (f.isReading()) updateSamples();
00235 }
00236 
00238 void CSpinnerFunctor::updateSamples(void)
00239 {
00240         // compute step between each angle
00241         const float angInc = (float) (2.f * NLMISC::Pi / _NbSamples);
00242         _PBTab.resize(_NbSamples + 1);
00243         NLMISC::CMatrix mat;
00244         // compute each sample
00245         for (uint32 k = 0; k < _NbSamples; ++k)
00246         {               
00247                 mat.setRot(NLMISC::CQuat(_Axis, k * angInc));
00248                 _PBTab[k] = CPlaneBasis(mat.getI(), mat.getJ());
00249         }
00250 }
00251 
00253 void PSRegisterPlaneBasisAttribs()
00254 {
00255         NLMISC_REGISTER_CLASS(CPSPlaneBasisBlender);
00256         NLMISC_REGISTER_CLASS(CPSPlaneBasisGradient);
00257         NLMISC_REGISTER_CLASS(CPSPlaneBasisMemory);
00258         NLMISC_REGISTER_CLASS(CPSPlaneBasisBinOp);
00259         NLMISC_REGISTER_CLASS(CPSPlaneBasisFollowSpeed);
00260         NLMISC_REGISTER_CLASS(CPSBasisSpinner);
00261 }
00262 
00263 } // NL3D
00264 
00265