Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / track_sampled_vector.cpp
blob3e19cac64ec4523ee863380c94247a2ab7bb2ef9
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
19 #include "nel/misc/common.h"
20 #include "nel/3d/track_sampled_vector.h"
22 using namespace NLMISC;
23 using namespace std;
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NL3D
32 // ***************************************************************************
33 // ***************************************************************************
34 // CTrackSampledVector
35 // ***************************************************************************
36 // ***************************************************************************
39 // ***************************************************************************
40 CTrackSampledVector::CTrackSampledVector()
44 // ***************************************************************************
45 CTrackSampledVector::~CTrackSampledVector()
49 // ***************************************************************************
50 void CTrackSampledVector::serial(NLMISC::IStream &f)
53 Version 0:
54 - base version.
56 (void)f.serialVersion(0);
58 // serial Time infos.
59 CTrackSampledCommon::serialCommon(f);
61 // serial Keys.
62 f.serial(_Keys);
65 // ***************************************************************************
66 void CTrackSampledVector::build(const std::vector<uint16> &timeList, const std::vector<CVector> &keyList,
67 float beginTime, float endTime)
69 nlassert( endTime>beginTime || (beginTime==endTime && keyList.size()<=1) );
70 nlassert( keyList.size()==timeList.size() );
71 uint i;
73 // reset.
74 uint numKeys= (uint)keyList.size();
75 _Keys.clear();
76 _TimeBlocks.clear();
78 // Build Common time information
79 CTrackSampledCommon::buildCommon(timeList, beginTime, endTime);
82 // Compute All Key values.
83 //===================
84 _Keys.resize(numKeys);
85 for(i=0; i<numKeys;i++)
87 // no compression for now
88 _Keys[i]= keyList[i];
93 // ***************************************************************************
94 const IAnimatedValue &CTrackSampledVector::eval (const TAnimationTime& date, CAnimatedValueBlock &avBlock)
96 // Eval time, and get key interpolation info
97 uint keyId0;
98 uint keyId1;
99 float interpValue;
100 TEvalType evalType= evalTime(date, _Keys.size(), keyId0, keyId1, interpValue);
102 // Discard?
103 if( evalType==EvalDiscard )
104 return avBlock.ValVector;
105 // One Key? easy, and quit.
106 else if( evalType==EvalKey0 )
108 avBlock.ValVector.Value= _Keys[keyId0];
110 // interpolate
111 else if( evalType==EvalInterpolate )
113 const CVector &valueKey0= _Keys[keyId0];
114 const CVector &valueKey1= _Keys[keyId1];
116 // interpolate
117 avBlock.ValVector.Value= valueKey0*(1-interpValue) + valueKey1*interpValue;
119 else
121 nlstop;
124 return avBlock.ValVector;
128 // ***************************************************************************
129 void CTrackSampledVector::applySampleDivisor(uint sampleDivisor)
131 if(sampleDivisor<=1)
132 return;
134 // **** build the key indices to keep, and rebuild the timeBlocks
135 static std::vector<uint32> keepKeys;
136 applySampleDivisorCommon(sampleDivisor, keepKeys);
138 // **** rebuild the keys
139 NLMISC::CObjectVector<CVector, false> newKeys;
140 newKeys.resize((uint32)keepKeys.size());
141 for(uint i=0;i<newKeys.size();i++)
143 newKeys[i]= _Keys[keepKeys[i]];
145 // copy
146 _Keys= newKeys;
148 // TestYoyo
149 /*nlinfo("ANIMQUAT:\t%d\t%d\t%d\t%d", sizeof(*this), _TimeBlocks.size(),
150 _TimeBlocks.size()?_TimeBlocks[0].Times.size():0,
151 _Keys.size() * sizeof(CVector));*/
155 } // NL3D