1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 #include "nel/misc/common.h"
20 #include "nel/3d/track_sampled_vector.h"
22 using namespace NLMISC
;
32 // ***************************************************************************
33 // ***************************************************************************
34 // CTrackSampledVector
35 // ***************************************************************************
36 // ***************************************************************************
39 // ***************************************************************************
40 CTrackSampledVector::CTrackSampledVector()
44 // ***************************************************************************
45 CTrackSampledVector::~CTrackSampledVector()
49 // ***************************************************************************
50 void CTrackSampledVector::serial(NLMISC::IStream
&f
)
56 (void)f
.serialVersion(0);
59 CTrackSampledCommon::serialCommon(f
);
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() );
74 uint numKeys
= (uint
)keyList
.size();
78 // Build Common time information
79 CTrackSampledCommon::buildCommon(timeList
, beginTime
, endTime
);
82 // Compute All Key values.
84 _Keys
.resize(numKeys
);
85 for(i
=0; i
<numKeys
;i
++)
87 // no compression for now
93 // ***************************************************************************
94 const IAnimatedValue
&CTrackSampledVector::eval (const TAnimationTime
& date
, CAnimatedValueBlock
&avBlock
)
96 // Eval time, and get key interpolation info
100 TEvalType evalType
= evalTime(date
, _Keys
.size(), keyId0
, keyId1
, interpValue
);
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
];
111 else if( evalType
==EvalInterpolate
)
113 const CVector
&valueKey0
= _Keys
[keyId0
];
114 const CVector
&valueKey1
= _Keys
[keyId1
];
117 avBlock
.ValVector
.Value
= valueKey0
*(1-interpValue
) + valueKey1
*interpValue
;
124 return avBlock
.ValVector
;
128 // ***************************************************************************
129 void CTrackSampledVector::applySampleDivisor(uint sampleDivisor
)
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
]];
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));*/