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 COLLISION_NODE_H_ 00026 #define COLLISION_NODE_H_ 00027 00028 #include <Collision/System/CollisionObject.h> 00029 #include <Core/Primitive/Axis3.h> 00030 #include <Core/Container/ArrayList.h> 00031 00032 namespace Lamp{ 00033 00034 class CollisionLeaf; 00035 00036 //------------------------------------------------------------------------------ 00037 /** 00038 * コリジョンノード 00039 */ 00040 class CollisionNode : public CollisionObject{ 00041 friend class CollisionScene; 00042 public: 00043 //-------------------------------------------------------------------------- 00044 // スケール 00045 //-------------------------------------------------------------------------- 00046 /** 00047 * スケールの設定 00048 * @param scale スケール 00049 */ 00050 virtual void setScale(const Vector3& scale){ axis_.setScale(scale); } 00051 00052 /** 00053 * スケールの取得 00054 * @return スケール 00055 */ 00056 virtual const Vector3& getScale() const{ return axis_.getScale(); } 00057 00058 /** 00059 * スケールを使用しているか 00060 * @return スケールを使用しているならtrue 00061 */ 00062 virtual bool isScaled() const{ return axis_.isScaled(); } 00063 00064 /** 00065 * グローバルでスケールを使用しているか 00066 * @return グローバルでスケールを使用しているならtrue 00067 */ 00068 virtual bool isGlobalScaled() const{ return globalScaled_; } 00069 00070 //-------------------------------------------------------------------------- 00071 // 回転 00072 //-------------------------------------------------------------------------- 00073 /** 00074 * XYZ回転の設定 00075 * @param rotation XYZ回転 00076 */ 00077 virtual void setRotationXYZ(const Vector3& rotation){ 00078 axis_.setRotationXYZ(rotation); 00079 } 00080 00081 /** 00082 * XYZ回転の取得 00083 * @return XYZ回転 00084 */ 00085 virtual const Vector3& getRotationXYZ(){ return axis_.getRotationXYZ(); } 00086 00087 //-------------------------------------------------------------------------- 00088 /** 00089 * 四元数回転の設定 00090 * @param rotation 四元数回転 00091 */ 00092 virtual void setRotationQuaternion(const Quaternion& rotation){ 00093 axis_.setRotationQuaternion(rotation); 00094 } 00095 00096 /** 00097 * 四元数回転の取得 00098 * @return 四元数回転 00099 */ 00100 virtual const Quaternion& getRotationQuaternion(){ 00101 return axis_.getRotationQuaternion(); 00102 } 00103 00104 //-------------------------------------------------------------------------- 00105 // 移動 00106 //-------------------------------------------------------------------------- 00107 /** 00108 * 移動の設定 00109 * @param translation 移動 00110 */ 00111 virtual void setTranslation(const Vector3& translation){ 00112 axis_.setTranslation(translation); 00113 } 00114 00115 /** 00116 * 移動の取得 00117 * @return 移動 00118 */ 00119 virtual const Vector3& getTranslation() const{ 00120 return axis_.getTranslation(); 00121 } 00122 00123 //-------------------------------------------------------------------------- 00124 // 行列 00125 //-------------------------------------------------------------------------- 00126 /** 00127 * ワールド行列の取得 00128 * @return ワールド行列 00129 */ 00130 const Matrix34& getWorldMatrix() const{ return worldMatrix_; } 00131 00132 /** 00133 * ローカル行列の取得 00134 * @return ローカル行列 00135 */ 00136 const Matrix34& getLocalMatrix() const{ return axis_.getMatrix(); } 00137 00138 //-------------------------------------------------------------------------- 00139 // 子供インターフェース 00140 //-------------------------------------------------------------------------- 00141 /** 00142 * 子供の追加 00143 * @param child 追加する子供 00144 */ 00145 virtual void addChild(CollisionObject* child){ 00146 child->setParent(this); 00147 children_.add(child); 00148 } 00149 00150 /** 00151 * 子供の削除 00152 * @param child 削除する子供 00153 */ 00154 virtual void removeChild(CollisionObject* child){ 00155 child->removeParent(this); 00156 children_.removeByValue(child); 00157 } 00158 00159 /** 00160 * 子供数の取得 00161 * @return 子供数 00162 */ 00163 virtual int getChildCount() const{ return children_.getCount(); } 00164 00165 /** 00166 * 子供の取得 00167 * @param index インデックス 00168 * @return 子供 00169 */ 00170 virtual CollisionObject* getChild(int index) const{ 00171 Assert(index >= 0); 00172 Assert(index < getChildCount()); 00173 return children_.get(index); 00174 } 00175 00176 //-------------------------------------------------------------------------- 00177 // コピー 00178 //-------------------------------------------------------------------------- 00179 /** 00180 * コピー 00181 * @return コピーされたコリジョンオブジェクト 00182 */ 00183 virtual CollisionObject* copy() const{ return copyCollisionNode(); } 00184 00185 /** 00186 * コリジョンノードのコピー 00187 * @return コピーされたコリジョンノード 00188 */ 00189 virtual CollisionNode* copyCollisionNode() const; 00190 00191 //-------------------------------------------------------------------------- 00192 /** 00193 * 再帰的破棄 00194 * @param collisionNode 破棄するコリジョンノード 00195 * @return 破棄したオブジェクト数 00196 */ 00197 static int recursiveDestroy(CollisionNode* collisionNode); 00198 00199 /** 00200 * 子の再帰的破棄 00201 * @param collisionNode 子を破棄するコリジョンノード 00202 * @return 破棄したオブジェクト数 00203 */ 00204 static int recursiveDestroyChildren(CollisionNode* collisionNode); 00205 00206 //-------------------------------------------------------------------------- 00207 // RTTI 00208 //-------------------------------------------------------------------------- 00209 /** 00210 * コリジョンノードかどうか 00211 * @return コリジョンノードならtrue 00212 */ 00213 virtual bool isCollisionNode() const{ return true; } 00214 00215 protected: 00216 //-------------------------------------------------------------------------- 00217 // 生成、破棄 00218 //-------------------------------------------------------------------------- 00219 /** 00220 * コンストラクタ 00221 * @param name 名前 00222 * @param scene シーン 00223 */ 00224 CollisionNode(const String& name, CollisionScene* scene); 00225 00226 /** 00227 * デストラクタ 00228 */ 00229 virtual ~CollisionNode(); 00230 00231 //-------------------------------------------------------------------------- 00232 // 走査 00233 //-------------------------------------------------------------------------- 00234 /** 00235 * 走査 00236 * @param parentMatrix 親行列 00237 * @param parentEnabled 親が有効か 00238 * @param parentScaled 親がスケールを使用しているか 00239 * @param parentChanged 親に変更があったか 00240 */ 00241 virtual void traverseImplement(const Matrix34& parentMatrix, 00242 bool parentEnabled, bool parentScaled, bool parentChanged); 00243 00244 //-------------------------------------------------------------------------- 00245 // 親 00246 //-------------------------------------------------------------------------- 00247 /** 00248 * 親の設定 00249 * @param parent 設定する親 00250 */ 00251 virtual void setParent(CollisionNode* parent){ 00252 CollisionObject::setParent(parent); 00253 setGlobalEnabled(true); 00254 } 00255 00256 /** 00257 * 親の削除 00258 * @param parent 削除する親 00259 */ 00260 virtual void removeParent(CollisionNode* parent){ 00261 CollisionObject::removeParent(parent); 00262 setGlobalEnabled(true); 00263 } 00264 00265 //-------------------------------------------------------------------------- 00266 // 変更フラグ 00267 //-------------------------------------------------------------------------- 00268 /** 00269 * 変更フラグの取得 00270 * @return 変更されていればtrue 00271 */ 00272 virtual bool isChanged() const{ 00273 return (CollisionObject::isChanged() || axis_.isChanged()); 00274 } 00275 00276 //-------------------------------------------------------------------------- 00277 // スケール 00278 //-------------------------------------------------------------------------- 00279 /** 00280 * グローバルでスケールを使用しているかの設定 00281 * @param globalScaled グローバルでスケールを使用しているならtrue 00282 */ 00283 virtual void setGlobalScaled(bool globalScaled){ 00284 globalScaled_ = globalScaled; 00285 } 00286 00287 private: 00288 //-------------------------------------------------------------------------- 00289 // ワールド行列 00290 Matrix34 worldMatrix_; 00291 // 軸 00292 Axis3 axis_; 00293 // 子供配列 00294 ArrayList<CollisionObject*> children_; 00295 // グローバルでのスケールフラグ 00296 bool globalScaled_; 00297 00298 }; 00299 00300 //------------------------------------------------------------------------------ 00301 } // End of namespace Lamp 00302 #endif // End of COLLISION_NODE_H_ 00303 //------------------------------------------------------------------------------