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_OBJECT_H_ 00026 #define COLLISION_OBJECT_H_ 00027 00028 namespace Lamp{ 00029 00030 class CollisionScene; 00031 class CollisionNode; 00032 class CollisionLeaf; 00033 class StaticCollisionLeaf; 00034 class StaticSphereCollision; 00035 class StaticDeformedMeshCollision; 00036 class DynamicCollisionLeaf; 00037 00038 //------------------------------------------------------------------------------ 00039 /** 00040 * コリジョンオブジェクト 00041 */ 00042 class CollisionObject{ 00043 friend class CollisionScene; 00044 friend class CollisionNode; 00045 public: 00046 //-------------------------------------------------------------------------- 00047 // 走査 00048 //-------------------------------------------------------------------------- 00049 /** 00050 * 走査 00051 */ 00052 virtual void traverse(); 00053 00054 //-------------------------------------------------------------------------- 00055 // メンバアクセサ 00056 //-------------------------------------------------------------------------- 00057 /** 00058 * 名前の取得 00059 * @return 名前 00060 */ 00061 virtual const String& getName() const{ return name_; } 00062 00063 //-------------------------------------------------------------------------- 00064 /** 00065 * シーンの取得 00066 * @return シーン 00067 */ 00068 virtual CollisionScene* getScene() const{ return scene_; } 00069 00070 //-------------------------------------------------------------------------- 00071 /** 00072 * 親の取得 00073 * @return 親 00074 */ 00075 virtual CollisionNode* getParent() const{ return parent_; } 00076 00077 //-------------------------------------------------------------------------- 00078 // 有効、無効 00079 //-------------------------------------------------------------------------- 00080 /** 00081 * 有効、無効の設定 00082 * @param enabled trueなら有効、falseなら無効 00083 */ 00084 virtual void setEnabled(bool enabled){ 00085 enabled_ = enabled; 00086 setChanged(true); 00087 } 00088 00089 /** 00090 * 有効、無効の取得 00091 * @return trueなら有効、falseなら無効 00092 */ 00093 virtual bool isEnabled() const{ return enabled_; } 00094 00095 /** 00096 * グローバルでの有効、無効の取得 00097 * @return trueなら有効、falseなら無効 00098 */ 00099 virtual bool isGlobalEnabled() const{ return globalEnabled_; } 00100 00101 //-------------------------------------------------------------------------- 00102 // ユーザデータ 00103 //-------------------------------------------------------------------------- 00104 /** 00105 * ユーザデータの設定 00106 * @param userData ユーザデータ 00107 */ 00108 virtual void setUserData(void* userData){ userData_ = userData; } 00109 00110 /** 00111 * ユーザデータの取得 00112 * @return ユーザデータ 00113 */ 00114 virtual void* getUserData(){ return userData_; } 00115 00116 //-------------------------------------------------------------------------- 00117 // 変更フラグ 00118 //-------------------------------------------------------------------------- 00119 /** 00120 * グローバルでの変更フラグの取得 00121 * @return グローバルで変更されていればtrue 00122 */ 00123 virtual bool isGlobalChanged() const{ return globalChanged_; } 00124 00125 //-------------------------------------------------------------------------- 00126 // コピー 00127 //-------------------------------------------------------------------------- 00128 /** 00129 * コピー 00130 * @return コピーされたコリジョンオブジェクト 00131 */ 00132 virtual CollisionObject* copy() const = 0; 00133 00134 /** 00135 * 再帰的破棄 00136 * @param collisionObject 破棄するコリジョンオブジェクト 00137 * @return 破棄したオブジェクト数 00138 */ 00139 static int recursiveDestroy(CollisionObject* collisionObject); 00140 00141 //-------------------------------------------------------------------------- 00142 // RTTI 00143 //-------------------------------------------------------------------------- 00144 /** 00145 * コリジョンノードかどうか 00146 * @return コリジョンノードならtrue 00147 */ 00148 virtual bool isCollisionNode() const{ return false; } 00149 00150 /** 00151 * コリジョンノードへのキャスト 00152 * @return コリジョンノード。型が違えばNULLを返す。 00153 */ 00154 virtual CollisionNode* castCollisionNode() const{ 00155 if(isCollisionNode()){ return (CollisionNode*)this; } 00156 return NULL; 00157 } 00158 00159 //-------------------------------------------------------------------------- 00160 /** 00161 * コリジョンリーフかどうか 00162 * @return コリジョンリーフならtrue 00163 */ 00164 virtual bool isCollisionLeaf() const{ return false; } 00165 00166 /** 00167 * コリジョンリーフへのキャスト 00168 * @return コリジョンリーフ。型が違えばNULLを返す。 00169 */ 00170 virtual CollisionLeaf* castCollisionLeaf() const{ 00171 if(isCollisionLeaf()){ return (CollisionLeaf*)this; } 00172 return NULL; 00173 } 00174 00175 //-------------------------------------------------------------------------- 00176 // 静的コリジョンリーフRTTI 00177 //-------------------------------------------------------------------------- 00178 /** 00179 * 静的コリジョンリーフかどうか 00180 * @return 静的コリジョンリーフならtrue 00181 */ 00182 virtual bool isStaticCollisionLeaf() const{ return false; } 00183 00184 /** 00185 * 静的コリジョンリーフへのキャスト 00186 * @return 静的コリジョンリーフ。型が違えばNULLを返す。 00187 */ 00188 virtual StaticCollisionLeaf* castStaticCollisionLeaf() const{ 00189 if(isStaticCollisionLeaf()){ return (StaticCollisionLeaf*)this; } 00190 return NULL; 00191 } 00192 00193 //-------------------------------------------------------------------------- 00194 /** 00195 * 静的球コリジョンかどうか 00196 * @return 静的球コリジョンならtrue 00197 */ 00198 virtual bool isStaticSphereCollision() const{ return false; } 00199 00200 /** 00201 * 静的球コリジョンへのキャスト 00202 * @return 静的球コリジョン。型が違えばNULLを返す。 00203 */ 00204 virtual StaticSphereCollision* castStaticSphereCollision() const{ 00205 if(isStaticSphereCollision()){ return (StaticSphereCollision*)this; } 00206 return NULL; 00207 } 00208 00209 //-------------------------------------------------------------------------- 00210 /** 00211 * 静的変形メッシュコリジョンかどうか 00212 * @return 静的変形メッシュコリジョンならtrue 00213 */ 00214 virtual bool isStaticDeformedMeshCollision() const{ return false; } 00215 00216 /** 00217 * 静的変形メッシュコリジョンへのキャスト 00218 * @return 静的変形メッシュコリジョン。型が違えばNULLを返す。 00219 */ 00220 virtual StaticDeformedMeshCollision* 00221 castStaticDeformedMeshCollision() const{ 00222 if(isStaticDeformedMeshCollision()){ 00223 return (StaticDeformedMeshCollision*)this; 00224 } 00225 return NULL; 00226 } 00227 00228 //-------------------------------------------------------------------------- 00229 // 動的コリジョンリーフRTTI 00230 //-------------------------------------------------------------------------- 00231 /** 00232 * 動的コリジョンリーフかどうか 00233 * @return 動的コリジョンリーフならtrue 00234 */ 00235 virtual bool isDynamicCollisionLeaf() const{ return false; } 00236 00237 /** 00238 * 動的コリジョンリーフへのキャスト 00239 * @return 動的コリジョンリーフ。型が違えばNULLを返す。 00240 */ 00241 virtual DynamicCollisionLeaf* castDynamicCollisionLeaf() const{ 00242 if(isDynamicCollisionLeaf()){ return (DynamicCollisionLeaf*)this; } 00243 return NULL; 00244 } 00245 00246 protected: 00247 //-------------------------------------------------------------------------- 00248 // 生成、破棄 00249 //-------------------------------------------------------------------------- 00250 /** 00251 * コンストラクタ 00252 * @param name 名前 00253 * @param scene シーン 00254 */ 00255 CollisionObject(const String& name, CollisionScene* scene) : 00256 name_(name), scene_(scene), parent_(NULL), userData_(NULL), 00257 enabled_(true), changed_(true), globalChanged_(true){ 00258 // globalEnabled_の初期値はNodeかLeafかで違う 00259 } 00260 00261 /** 00262 * デストラクタ 00263 */ 00264 virtual ~CollisionObject(){} 00265 00266 //-------------------------------------------------------------------------- 00267 // コピー 00268 //-------------------------------------------------------------------------- 00269 /** 00270 * コリジョンオブジェクトの値コピー 00271 * @param destination コピー先コリジョンオブジェクト 00272 */ 00273 virtual void copyCollisionObjectValue(CollisionObject* destination) const{ 00274 destination->enabled_ = enabled_; 00275 Assert(destination->changed_); 00276 } 00277 00278 //-------------------------------------------------------------------------- 00279 // 走査 00280 //-------------------------------------------------------------------------- 00281 /** 00282 * 走査 00283 * @param parentMatrix 親行列 00284 * @param parentEnabled 親が有効か 00285 * @param parentScaled 親がスケールを使用しているか 00286 * @param parentChanged 親に変更があったか 00287 */ 00288 // なぜかtraverse()だとオーバーロードされない、publicのtraverseが隠蔽される 00289 virtual void traverseImplement(const Matrix34& parentMatrix, 00290 bool parentEnabled, bool parentScaled, bool parentChanged) = 0; 00291 00292 //-------------------------------------------------------------------------- 00293 // 有効、無効 00294 //-------------------------------------------------------------------------- 00295 /** 00296 * グローバルでの有効、無効の設定 00297 * @param globalEnabled trueなら有効、falseなら無効 00298 */ 00299 virtual void setGlobalEnabled(bool globalEnabled){ 00300 globalEnabled_ = globalEnabled; 00301 } 00302 00303 //-------------------------------------------------------------------------- 00304 // 変更フラグ 00305 //-------------------------------------------------------------------------- 00306 /** 00307 * 変更フラグの取得 00308 * @return 変更されていればtrue 00309 */ 00310 virtual bool isChanged() const{ return changed_; } 00311 00312 /** 00313 * 変更フラグの設定 00314 * @param changed trueなら有効、falseなら無効 00315 */ 00316 virtual void setChanged(bool changed){ changed_ = changed; } 00317 00318 /** 00319 * グローバルでの変更フラグの設定 00320 * @param globalChanged trueなら有効、falseなら無効 00321 */ 00322 virtual void setGlobalChanged(bool globalChanged){ 00323 globalChanged_ = globalChanged; 00324 } 00325 00326 //-------------------------------------------------------------------------- 00327 // 親 00328 //-------------------------------------------------------------------------- 00329 /** 00330 * 親の設定 00331 * @param parent 設定する親 00332 */ 00333 virtual void setParent(CollisionNode* parent){ 00334 Assert(parent != NULL); 00335 Assert(parent_ == NULL); 00336 parent_ = parent; 00337 setChanged(true); 00338 // globalEnabled_をNodeとLeafで設定する 00339 } 00340 00341 /** 00342 * 親の削除 00343 * @param parent 削除する親 00344 */ 00345 virtual void removeParent(CollisionNode* parent){ 00346 Assert(parent_ != NULL); 00347 Assert(parent_ == parent); 00348 parent_ = NULL; 00349 setChanged(true); 00350 // globalEnabled_をNodeとLeafで設定する 00351 } 00352 00353 private: 00354 //-------------------------------------------------------------------------- 00355 // コピーコンストラクタの隠蔽 00356 CollisionObject(const CollisionObject& copy); 00357 00358 // 代入コピーの隠蔽 00359 void operator =(const CollisionObject& copy); 00360 00361 //-------------------------------------------------------------------------- 00362 // 名前 00363 String name_; 00364 // シーン 00365 CollisionScene* scene_; 00366 // 親 00367 CollisionNode* parent_; 00368 // ユーザデータ 00369 void* userData_; 00370 // 有効、無効フラグ 00371 bool enabled_; 00372 // グローバルでの有効無効フラグ 00373 bool globalEnabled_; 00374 // 変更フラグ 00375 bool changed_; 00376 // グローバルでの変更フラグ 00377 bool globalChanged_; 00378 00379 }; 00380 00381 //------------------------------------------------------------------------------ 00382 } // End of namespace Lamp 00383 #endif // End of COLLISION_OBJECT_H_ 00384 //------------------------------------------------------------------------------