V-ART
naturalinterpolator.cpp
Go to the documentation of this file.
1 // The NaturalInterpolator has been replaced with NoisyDofMover
5 
7 #include <cmath>
8 
9 // FORMULA:
10 // (sin((x*overshoot+1.5)*pi)+1)/2*offset
11 // where overshot is in [1..2]
12 // if "< 1", causes a kind of offset
13 // 1 causes no overshoot
14 // 2 causes 100% overshoot (goes back to initial position)
15 // offset is in [0..2]
16 // 0 causes no movement
17 // 0.7 causes 70% movement
18 // 1 causes no offset
19 // 1.2 cause +20% error
20 // 2 causes +100% error
21 
22 using namespace std;
23 
25 {
26 }
27 
28 VART::NaturalInterpolator::NaturalInterpolator(float offsetLevel, float overshootLevel)
29 {
30  offset = offsetLevel;
31  overshoot = overshootLevel;
32  peakTime = 0.9f;
33 }
34 
35 void VART::NaturalInterpolator::SetNoise(float newNoiseAmplitude, float newNoiseWaveLenght)
36 {
37  float position = newNoiseWaveLenght;
38  float randomFloat; // a random number in the range [-0.5 .. 0.5]
39 
40  assert(noisePositionPeaks.empty());
41  noisePositionPeaks.push_back(0.0f);
42  noiseAmplitudePeaks.push_back(0.0f); // no noise at starting position
43  while (position < 1.0f)
44  {
45  // create a noise peak
46  randomFloat = (static_cast<float>(rand())/RAND_MAX) - 0.5;
47  noisePositionPeaks.push_back(position);
48  noiseAmplitudePeaks.push_back(randomFloat * newNoiseAmplitude);
49  position += newNoiseWaveLenght;
50  }
51  // no noise at end
52  noisePositionPeaks.push_back(1.0f);
53  noiseAmplitudePeaks.push_back(0.0f);
54  prevPeakItr = no
55 }
56 
57 float VART::NaturalInterpolator::GetNoise()
58 {
59  if (noisePositionPeaks.empty())
60  return 0.0f;
61  else
62  {
63  SineInterpolator::GetValue();
64  }
65 }
66 
67 float VART::NaturalInterpolator::GetValue(float linearIndex, float initialValue, float range) const
68 // virtual method
69 {
70  float result;
71  float newLinearIndex;
72  float newRange;
73 
74  if (linearIndex < peakTime)
75  { // interpolating to peak
76  newLinearIndex = linearIndex / peakTime;
77  newRange = range + offset + overshoot;
78  result = SineInterpolator::GetValue(newLinearIndex, initialValue, newRange);
79  if (hasNoise)
80  result += GetNoise(linearIndex);
81  }
82  else
83  { // interpolating from peak to target
84  result = SineInterpolator::GetValue((linearIndex-peakTime)/(1-peakTime),
85  initialPos+range+offset+overshoot,
86  -overshoot);
87  }
88  return result;
89 }
NaturalInterpolator()
Creates an unitialized natural interpolator.
virtual float GetValue(float linearIndex, float initialValue, float range) const
Evaluates a goal position for DOF interpolation.
Header file for V-ART class "NaturalInterpolator".
void SetNoise(float newNoiseAmplitude, float newNoiseWaveLenght)