Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

VectorArrayInterpolator.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * ベクトル配列補間実装
00022  * @author Junpee
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     // コピーコンストラクタは強制的にNULL設定
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 == &copy){ return *this; }
00058     size_ = copy.size_;
00059     length_ = copy.length_;
00060     // 代入の際は解放してNULLを設定
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     // 補間の為には2以上のsizeが必要
00105     Assert(size > 1);
00106     size_ = size;
00107     length_ = (float)(size_ - 1);
00108     SafeArrayDelete(array_);
00109     array_ = new Vector3[size_];
00110 }
00111 //------------------------------------------------------------------------------
00112 } // End of namespace Lamp
00113 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:38 2005 for Lamp by doxygen 1.3.2