00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "LampBasic.h"
00026 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h"
00027
00028 namespace Lamp{
00029
00030
00031
00032 VectorArrayInterpolator::VectorArrayInterpolator() :
00033 array_(NULL), size_(0), length_(0.f){
00034 }
00035
00036
00037 VectorArrayInterpolator::~VectorArrayInterpolator(){
00038 SafeArrayDelete(array_);
00039 }
00040
00041
00042 VectorArrayInterpolator::VectorArrayInterpolator(
00043 const VectorArrayInterpolator& copy){
00044 size_ = copy.size_;
00045 length_ = copy.length_;
00046
00047 array_ = NULL;
00048 if(size_ == 0){ return; }
00049 array_ = new Vector3[size_];
00050 std::memcpy(array_, copy.array_, sizeof(Vector3) * size_);
00051 }
00052
00053
00054 VectorArrayInterpolator& VectorArrayInterpolator::operator =(
00055 const VectorArrayInterpolator& copy){
00056
00057 if(this == ©){ return *this; }
00058 size_ = copy.size_;
00059 length_ = copy.length_;
00060
00061 SafeArrayDelete(array_);
00062 if(size_ == 0){ return *this; }
00063 array_ = new Vector3[size_];
00064 std::memcpy(array_, copy.array_, sizeof(Vector3) * size_);
00065 return *this;
00066 }
00067
00068
00069
00070
00071 AxisAlignedBox VectorArrayInterpolator::getBoundingBox() const{
00072 AxisAlignedBox result(AxisAlignedBox::zero);
00073 if(size_ == 0){ return result; }
00074 result.set(array_[0], array_[0]);
00075 for(int i = 1; i < size_; i++){ result.merge(array_[i]); }
00076 return result;
00077 }
00078
00079
00080
00081
00082 Vector3 VectorArrayInterpolator::interpolate(float time){
00083 Assert(array_ != NULL);
00084
00085 if(time <= 0.f){ return array_[0]; }
00086
00087 if(time >= length_){ return array_[size_ - 1]; }
00088
00089 float integer, rate;
00090 rate = Math::modf(time, &integer);
00091 int index = (int)integer;
00092 Vector3 preValue = array_[index];
00093 preValue *= (1.f - rate);
00094 Vector3 postValue = array_[index + 1];
00095 postValue *= rate;
00096 preValue += postValue;
00097 return preValue;
00098 }
00099
00100
00101
00102
00103 void VectorArrayInterpolator::setSize(int size){
00104
00105 Assert(size > 1);
00106 size_ = size;
00107 length_ = (float)(size_ - 1);
00108 SafeArrayDelete(array_);
00109 array_ = new Vector3[size_];
00110 }
00111
00112 }
00113