//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * 回転定数補間ヘッダ
 * @author Junpee
 */

#ifndef ROTATION_CONSTANT_INTERPOLATOR_H_
#define ROTATION_CONSTANT_INTERPOLATOR_H_

#include <Animation/RotationInterpolator/RotationInterpolator.h>

namespace Lamp{

//------------------------------------------------------------------------------
/**
 * 回転定数補間
 */
class RotationConstantInterpolator : public RotationInterpolator{
public:
	//--------------------------------------------------------------------------
	/**
	 * コンストラクタ
	 */
	RotationConstantInterpolator() : euler_(Vector3::zero),
		quaternion_(Quaternion::identity), length_(0.f){}

	/**
	 * デストラクタ
	 */
	virtual ~RotationConstantInterpolator(){}

	//--------------------------------------------------------------------------
	/**
	 * 複製
	 * @return 複製された回転補間。呼び出し元でdeleteする必要がある
	 */
	virtual RotationInterpolator* duplicate() const{
		RotationInterpolator* result = new RotationConstantInterpolator(*this);
		return result;
	}

	//--------------------------------------------------------------------------
	/**
	 * 同じ値かどうか
	 * @param target 比較対象
	 * @return 同じ値ならtrueをかえす
	 */
	virtual bool equals(const RotationInterpolator& target) const{
		RotationConstantInterpolator* interpolator =
			target.castRotationConstantInterpolator();
		if(interpolator == NULL){ return false; }
		return ((euler_ == interpolator->euler_) &&
			(quaternion_ == interpolator->quaternion_) &&
			(length_ == interpolator->length_));
	}

	//--------------------------------------------------------------------------
	// 長さ
	//--------------------------------------------------------------------------
	/**
	 * 長さの設定
	 * @param length 長さ
	 */
	virtual void setLength(float length){
		Assert(length >= 0.f);
		length_ = length;
	}

	/**
	 * 長さの取得
	 * @return 長さ
	 */
	virtual float getLength() const{ return length_; }

	//--------------------------------------------------------------------------
	// オイラー補間
	//--------------------------------------------------------------------------
	/**
	 * オイラー補間かどうか
	 * @return オイラー補間ならtrue
	 */
	virtual bool isEulerInterpolator() const{ return true; }

	/**
	 * オイラー補間
	 * @param time 時間
	 * @return 補間された回転
	 */
	virtual Vector3 eulerInterpolate(float time){ return euler_; }

	//--------------------------------------------------------------------------
	// 四元数補間
	//--------------------------------------------------------------------------
	/**
	 * 四元数補間かどうか
	 * @return 四元数補間ならtrue
	 */
	virtual bool isQuaternionInterpolator() const{ return true; }

	/**
	 * 四元数補間
	 * @param time 時間
	 * @return 補間された回転
	 */
	virtual Quaternion quaternionInterpolate(float time){ return quaternion_; }

	//--------------------------------------------------------------------------
	// 値
	//--------------------------------------------------------------------------
	/**
	 * XYZ回転の設定
	 * @param euler 設定するXYZ回転
	 */
	virtual void setEuler(const Vector3& euler){
		euler_ = euler;
		quaternion_.setRotationXYZ(euler_);
	}

	/**
	 * XYZ回転の取得
	 * @return 取得したXYZ回転
	 */
	virtual Vector3 getEuler(){ return euler_; }

	//--------------------------------------------------------------------------
	/**
	 * 四元数回転の設定
	 * @param quaternion 設定する四元数回転
	 */
	virtual void setQuaternion(const Quaternion& quaternion){
		quaternion_ = quaternion;
		quaternion_.getRotationXYZ(&euler_);
	}

	/**
	 * 四元数回転の取得
	 * @return 取得した四元数回転
	 */
	virtual Quaternion getQuaternion(){ return quaternion_; }

	//--------------------------------------------------------------------------
	// RTTI
	//--------------------------------------------------------------------------
	/**
	 * 回転定数補間かどうか
	 * @return 回転定数補間ならtrue
	 */
	virtual bool isRotationConstantInterpolator() const{ return true; }

	//--------------------------------------------------------------------------
private:
	// オイラー
	Vector3 euler_;
	// 四元数
	Quaternion quaternion_;
	// 長さ
	float length_;

};

//------------------------------------------------------------------------------
} // End of namespace Lamp
#endif // End of ROTATION_CONSTANT_INTERPOLATOR_H_
//------------------------------------------------------------------------------

