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

Axis3.h

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 #ifndef AXIS_3_H_
00026 #define AXIS_3_H_
00027 
00028 #include <Core/Primitive/Matrix34.h>
00029 #include <Core/Primitive/Vector3.h>
00030 #include <Core/Primitive/Quaternion.h>
00031 
00032 namespace Lamp{
00033 
00034 //------------------------------------------------------------------------------
00035 /**
00036  * 三次元軸
00037  */
00038 class Axis3{
00039 public:
00040     /**
00041      * コンストラクタ
00042      */
00043     Axis3() : matrix_(Matrix34::unit), quaternion_(Quaternion::identity),
00044         scale_(Vector3::unitScale), euler_(Vector3::zero),
00045         translation_(Vector3::zero),
00046         validEuler_(true), validQuaternion_(true), isChanged_(true){
00047         // isChanged_(true) 初回の計算は強要する
00048     }
00049 
00050     /**
00051      * コピーコンストラクタ
00052      * @param source コピー元
00053      */
00054     Axis3(const Axis3& source) : matrix_(source.matrix_),
00055         quaternion_(source.quaternion_), scale_(source.scale_),
00056         euler_(source.euler_), translation_(source.translation_),
00057         validEuler_(source.validEuler_),
00058         validQuaternion_(source.validQuaternion_), isChanged_(true){
00059         // isChanged_(true) 初回の計算は強要する
00060     }
00061 
00062     /**
00063      * デストラクタ
00064      */
00065     virtual ~Axis3(){}
00066 
00067     //--------------------------------------------------------------------------
00068     /**
00069      * スケールの設定
00070      * @param scale スケール
00071      */
00072     virtual void setScale(const Vector3& scale){
00073         if(scale_ == scale){ return; }
00074         scale_ = scale;
00075         isChanged_ = true;
00076     }
00077 
00078     /**
00079      * スケールの取得
00080      * @return スケール
00081      */
00082     virtual const Vector3& getScale() const{ return scale_; }
00083 
00084     /**
00085      * スケールを使用しているか
00086      * @return スケールを使用しているならtrue
00087      */
00088     virtual bool isScaled() const{ return (scale_ != Vector3::unitScale); }
00089 
00090     //--------------------------------------------------------------------------
00091     /**
00092      * XYZ回転の設定
00093      * @param rotation XYZ回転
00094      */
00095     virtual void setRotationXYZ(const Vector3& rotation){
00096         if(validEuler_ && (euler_ == rotation)){ return; }
00097         euler_ = rotation;
00098         validEuler_ = true;
00099         validQuaternion_ = false;
00100         isChanged_ = true;
00101     }
00102 
00103     /**
00104      * XYZ回転の取得
00105      * @return XYZ回転
00106      */
00107     virtual const Vector3& getRotationXYZ(){
00108         if(!validEuler_){
00109             quaternion_.getRotationXYZ(&euler_);
00110             validEuler_ = true;
00111         }
00112         return euler_;
00113     }
00114 
00115     //--------------------------------------------------------------------------
00116     /**
00117      * 四元数回転の設定
00118      * @param rotation 四元数回転
00119      */
00120     virtual void setRotationQuaternion(const Quaternion& rotation){
00121         if(validQuaternion_ && (quaternion_ == rotation)){ return; }
00122         quaternion_ = rotation;
00123         validEuler_ = false;
00124         validQuaternion_ = true;
00125         isChanged_ = true;
00126     }
00127 
00128     /**
00129      * 四元数回転の取得
00130      * @return 四元数回転
00131      */
00132     virtual const Quaternion& getRotationQuaternion(){
00133         if(!validQuaternion_){
00134             quaternion_.setRotationXYZ(euler_);
00135             validQuaternion_ = true;
00136         }
00137         return quaternion_;
00138     }
00139 
00140     //--------------------------------------------------------------------------
00141     /**
00142      * 移動の設定
00143      * @param translation 移動
00144      */
00145     virtual void setTranslation(const Vector3& translation){
00146         if(translation_ == translation){ return; }
00147         translation_ = translation;
00148         isChanged_ = true;
00149     }
00150 
00151     /**
00152      * 移動の取得
00153      * @return 移動
00154      */
00155     virtual const Vector3& getTranslation() const{ return translation_; }
00156 
00157     //--------------------------------------------------------------------------
00158     /**
00159      * 行列の構築
00160      * @return 再構築したならばtrue
00161      */
00162     virtual bool buildMatrix(){
00163         if(isChanged_){
00164             if(validQuaternion_){
00165                 matrix_.setTransformationQuaternion(
00166                     scale_, quaternion_, translation_);
00167             }else{
00168                 Assert(validEuler_);
00169                 matrix_.setTransformationXYZ(scale_, euler_, translation_);
00170             }
00171             isChanged_ = false;
00172             return true;
00173         }
00174         return false;
00175     }
00176 
00177     /**
00178      * 行列の取得
00179      * @return 行列
00180      */
00181     virtual const Matrix34& getMatrix() const{
00182         Assert(!isChanged_);
00183         return matrix_;
00184     }
00185 
00186     //--------------------------------------------------------------------------
00187     /**
00188      * 軸が変更されているか
00189      * @return 軸が変更されていればtrue
00190      */
00191     virtual bool isChanged() const{ return isChanged_; }
00192 
00193     //--------------------------------------------------------------------------
00194 protected:
00195     /// 行列
00196     Matrix34 matrix_;
00197     /// 四元数回転
00198     Quaternion quaternion_;
00199     /// スケール
00200     Vector3 scale_;
00201     /// オイラー回転
00202     Vector3 euler_;
00203     /// 移動
00204     Vector3 translation_;
00205     /// オイラー回転が有効か
00206     bool validEuler_;
00207     /// 四元数回転が有効か
00208     bool validQuaternion_;
00209     /// 変更フラグ
00210     bool isChanged_;
00211 
00212 };
00213 
00214 //------------------------------------------------------------------------------
00215 } // End of namespace Lamp
00216 #endif // End of AXIS_3_H_
00217 //------------------------------------------------------------------------------

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