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 BONE_H_ 00026 #define BONE_H_ 00027 00028 #include <Core/Primitive/Axis3.h> 00029 #include <Core/Container/ArrayList.h> 00030 00031 namespace Lamp{ 00032 00033 //------------------------------------------------------------------------------ 00034 /** 00035 * ボーン 00036 */ 00037 class Bone{ 00038 friend class CharacterModel; 00039 public: 00040 //-------------------------------------------------------------------------- 00041 /** 00042 * ローカル行列の取得 00043 * @return ローカル行列 00044 */ 00045 virtual const Matrix34& getLocalMatrix(){ return axis_.getMatrix(); } 00046 00047 /** 00048 * モデル行列の取得 00049 * @return モデル行列 00050 */ 00051 virtual const Matrix34& getModelMatrix(){ return modelMatrix_; } 00052 00053 /** 00054 * 変形行列の取得 00055 * @return 変形行列 00056 */ 00057 virtual const Matrix34& getDeformMatrix(){ return deformMatrix_; } 00058 00059 //-------------------------------------------------------------------------- 00060 /** 00061 * ポーズ逆行列の設定 00062 * @param inversePoseMatrix ポーズ逆行列 00063 */ 00064 virtual void setInversePoseMatrix(const Matrix34& inversePoseMatrix){ 00065 inversePoseMatrix_ = inversePoseMatrix; 00066 } 00067 00068 /** 00069 * ポーズ逆行列の取得 00070 * @return ポーズ逆行列 00071 */ 00072 virtual const Matrix34& getInversePoseMatrix() const{ 00073 return inversePoseMatrix_; 00074 } 00075 00076 //-------------------------------------------------------------------------- 00077 /** 00078 * スケールの設定 00079 * @param scale スケール 00080 */ 00081 virtual void setScale(const Vector3& scale){ axis_.setScale(scale); } 00082 00083 /** 00084 * スケールの取得 00085 * @return スケール 00086 */ 00087 virtual const Vector3& getScale() const{ return axis_.getScale(); } 00088 00089 /** 00090 * スケールを使用しているか 00091 * @return スケールを使用しているならtrue 00092 */ 00093 virtual bool isScaled() const{ return axis_.isScaled(); } 00094 00095 //-------------------------------------------------------------------------- 00096 /** 00097 * XYZ回転の設定 00098 * @param rotation XYZ回転 00099 */ 00100 virtual void setRotationXYZ(const Vector3& rotation){ 00101 axis_.setRotationXYZ(rotation); 00102 } 00103 00104 /** 00105 * XYZ回転の取得 00106 * @return XYZ回転 00107 */ 00108 virtual const Vector3& getRotationXYZ(){ 00109 return axis_.getRotationXYZ(); 00110 } 00111 00112 //-------------------------------------------------------------------------- 00113 /** 00114 * 四元数回転の設定 00115 * @param rotation 四元数回転 00116 */ 00117 virtual void setRotationQuaternion(const Quaternion& rotation){ 00118 axis_.setRotationQuaternion(rotation); 00119 } 00120 00121 /** 00122 * 四元数回転の取得 00123 * @return 四元数回転 00124 */ 00125 virtual const Quaternion& getRotationQuaternion(){ 00126 return axis_.getRotationQuaternion(); 00127 } 00128 00129 //-------------------------------------------------------------------------- 00130 /** 00131 * 移動の設定 00132 * @param translation 移動 00133 */ 00134 virtual void setTranslation(const Vector3& translation){ 00135 axis_.setTranslation(translation); 00136 } 00137 00138 /** 00139 * 移動の取得 00140 * @return 移動 00141 */ 00142 virtual const Vector3& getTranslation() const{ 00143 return axis_.getTranslation(); 00144 } 00145 00146 //-------------------------------------------------------------------------- 00147 // ボーンインターフェース 00148 //-------------------------------------------------------------------------- 00149 /** 00150 * ボーンの追加 00151 * @param bone 追加するボーン 00152 */ 00153 virtual void addBone(Bone* bone){ 00154 bones_.add(bone); 00155 } 00156 00157 /** 00158 * ボーンの削除 00159 * @param bone 削除するボーン 00160 */ 00161 virtual void removeBone(Bone* bone){ 00162 bones_.removeByValue(bone); 00163 } 00164 00165 /** 00166 * ボーン数の取得 00167 * @return ボーン数 00168 */ 00169 virtual int getBoneCount() const{ return bones_.getCount(); } 00170 00171 /** 00172 * ボーンの取得 00173 * @param index インデックス 00174 * @return ボーン 00175 */ 00176 virtual Bone* getBone(int index) const{ 00177 Assert(index >= 0); 00178 Assert(index < getBoneCount()); 00179 return bones_.get(index); 00180 } 00181 00182 //-------------------------------------------------------------------------- 00183 /** 00184 * 名前の取得 00185 * @return 名前 00186 */ 00187 virtual const String& getName() const{ return name_; } 00188 00189 /** 00190 * ボーンの値コピー 00191 * @param destination コピー先ボーン 00192 */ 00193 virtual void copyBoneValue(Bone* destination) const; 00194 00195 //-------------------------------------------------------------------------- 00196 protected: 00197 /** 00198 * コンストラクタ 00199 * @param name 名前 00200 */ 00201 Bone(const String& name); 00202 00203 /** 00204 * デストラクタ 00205 */ 00206 virtual ~Bone(); 00207 00208 //-------------------------------------------------------------------------- 00209 /** 00210 * ボーン行列の構築 00211 * @param parentModelMatrix 親のモデル行列 00212 * @return スケールが含まれていればtrue 00213 */ 00214 virtual bool buildBoneMatrix(const Matrix34& parentModelMatrix); 00215 00216 //-------------------------------------------------------------------------- 00217 /// 軸 00218 Axis3 axis_; 00219 /// ポーズ逆行列 00220 Matrix34 inversePoseMatrix_; 00221 /// モデル行列 00222 Matrix34 modelMatrix_; 00223 /// 変形行列 00224 Matrix34 deformMatrix_; 00225 /// ボーン配列 00226 ArrayList<Bone*> bones_; 00227 /// 名前 00228 String name_; 00229 00230 private: 00231 // コピーコンストラクタの隠蔽 00232 Bone(const Bone& copy); 00233 00234 // 代入コピーの隠蔽 00235 void operator =(const Bone& copy); 00236 00237 }; 00238 00239 //------------------------------------------------------------------------------ 00240 } // End of namespace Lamp 00241 #endif // End of BONE_H_ 00242 //------------------------------------------------------------------------------