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_LEAF_H_ 00026 #define COLLISION_LEAF_H_ 00027 00028 #include <Collision/System/CollisionObject.h> 00029 00030 namespace Lamp{ 00031 00032 class IntersectionResult; 00033 00034 //------------------------------------------------------------------------------ 00035 /** 00036 * コリジョンリーフ 00037 */ 00038 class CollisionLeaf : public CollisionObject{ 00039 friend class CollisionScene; 00040 public: 00041 //-------------------------------------------------------------------------- 00042 // 交差 00043 //-------------------------------------------------------------------------- 00044 /** 00045 * 球交差 00046 * @param result 交差結果 00047 * @param sphere 球 00048 * @param collisionMask コリジョンマスク 00049 */ 00050 virtual void intersection(IntersectionResult* result, const Sphere& sphere, 00051 u_int collisionMask = 0xffffffff){ Assert(false); } 00052 00053 /** 00054 * 球コリジョン交差 00055 * @param result 交差結果 00056 * @param sphere 球コリジョン 00057 * @param collisionMask コリジョンマスク 00058 */ 00059 virtual void intersection(IntersectionResult* result, 00060 StaticSphereCollision* sphere, u_int collisionMask = 0xffffffff){ 00061 Assert(false); 00062 } 00063 00064 //-------------------------------------------------------------------------- 00065 // 衝突 00066 //-------------------------------------------------------------------------- 00067 // インターフェースをきる 00068 00069 //-------------------------------------------------------------------------- 00070 // コリジョンマスク 00071 //-------------------------------------------------------------------------- 00072 /** 00073 * コリジョンマスクの設定 00074 * @param collisionMask コリジョンマスク 00075 */ 00076 virtual void setCollisionMask(u_int collisionMask){ 00077 collisionMask_ = collisionMask; 00078 } 00079 00080 /** 00081 * コリジョンマスクの取得 00082 * @return コリジョンマスク 00083 */ 00084 virtual u_int getCollisionMask() const{ return collisionMask_; } 00085 00086 //-------------------------------------------------------------------------- 00087 // スケール 00088 //-------------------------------------------------------------------------- 00089 /** 00090 * スケールの設定 00091 * @param scale 親のスケール 00092 */ 00093 virtual void setScale(const Vector3& scale); 00094 00095 /** 00096 * スケールの取得 00097 * @return 親のスケール 00098 */ 00099 virtual const Vector3& getScale() const; 00100 00101 /** 00102 * スケールを使用しているか 00103 * @return 親がスケールを使用しているならtrue 00104 */ 00105 virtual bool isScaled() const; 00106 00107 /** 00108 * グローバルでスケールを使用しているか 00109 * @return 親がグローバルでスケールを使用しているならtrue 00110 */ 00111 virtual bool isGlobalScaled() const; 00112 00113 //-------------------------------------------------------------------------- 00114 // 回転 00115 //-------------------------------------------------------------------------- 00116 /** 00117 * XYZ回転の設定 00118 * @param rotation 親のXYZ回転 00119 */ 00120 virtual void setRotationXYZ(const Vector3& rotation); 00121 00122 /** 00123 * XYZ回転の取得 00124 * @return 親のXYZ回転 00125 */ 00126 virtual const Vector3& getRotationXYZ(); 00127 00128 //-------------------------------------------------------------------------- 00129 /** 00130 * 四元数回転の設定 00131 * @param rotation 親の四元数回転 00132 */ 00133 virtual void setRotationQuaternion(const Quaternion& rotation); 00134 00135 /** 00136 * 四元数回転の取得 00137 * @return 親の四元数回転 00138 */ 00139 virtual const Quaternion& getRotationQuaternion(); 00140 00141 //-------------------------------------------------------------------------- 00142 // 移動 00143 //-------------------------------------------------------------------------- 00144 /** 00145 * 移動の設定 00146 * @param translation 親の移動 00147 */ 00148 virtual void setTranslation(const Vector3& translation); 00149 00150 /** 00151 * 移動の取得 00152 * @return 親の移動 00153 */ 00154 virtual const Vector3& getTranslation() const; 00155 00156 //-------------------------------------------------------------------------- 00157 // 行列 00158 //-------------------------------------------------------------------------- 00159 /** 00160 * ワールド行列の取得 00161 * @return 親のワールド行列 00162 */ 00163 const Matrix34& getWorldMatrix() const; 00164 00165 /** 00166 * ローカル行列の取得 00167 * @return 親のローカル行列 00168 */ 00169 const Matrix34& getLocalMatrix() const; 00170 00171 //-------------------------------------------------------------------------- 00172 // コピー 00173 //-------------------------------------------------------------------------- 00174 /** 00175 * コリジョンリーフのコピー 00176 * @return コピーされたコリジョンリーフ 00177 */ 00178 virtual CollisionLeaf* copyCollisionLeaf() const = 0; 00179 00180 //-------------------------------------------------------------------------- 00181 /** 00182 * 破棄 00183 * @param collisionLeaf 破棄するコリジョンリーフ 00184 * @return 破棄したオブジェクト数 00185 */ 00186 static int destroy(CollisionLeaf* collisionLeaf); 00187 00188 //-------------------------------------------------------------------------- 00189 // RTTI 00190 //-------------------------------------------------------------------------- 00191 /** 00192 * コリジョンリーフかどうか 00193 * @return コリジョンリーフならtrue 00194 */ 00195 virtual bool isCollisionLeaf() const{ return true; } 00196 00197 protected: 00198 //-------------------------------------------------------------------------- 00199 // 生成、破棄 00200 //-------------------------------------------------------------------------- 00201 /** 00202 * コンストラクタ 00203 * @param name 名前 00204 * @param scene シーン 00205 */ 00206 CollisionLeaf(const String& name, CollisionScene* scene); 00207 00208 /** 00209 * デストラクタ 00210 */ 00211 virtual ~CollisionLeaf(); 00212 00213 //-------------------------------------------------------------------------- 00214 // コピー 00215 //-------------------------------------------------------------------------- 00216 /** 00217 * コリジョンリーフの値コピー 00218 * @param destination コピー先コリジョンリーフ 00219 */ 00220 virtual void copyCollisionLeafValue(CollisionLeaf* destination) const{ 00221 // コリジョンオブジェクトの値コピー 00222 copyCollisionObjectValue(destination); 00223 // メンバコピー 00224 destination->collisionMask_ = collisionMask_; 00225 } 00226 00227 //-------------------------------------------------------------------------- 00228 // 走査 00229 //-------------------------------------------------------------------------- 00230 /** 00231 * 走査のセットアップ 00232 * @param parentEnabled 親が有効か 00233 * @param parentChanged 親に変更があったか 00234 * @return 処理の続行が必要であればtrue 00235 */ 00236 virtual bool traverseSetup(bool parentEnabled, bool parentChanged); 00237 00238 //-------------------------------------------------------------------------- 00239 // 親 00240 //-------------------------------------------------------------------------- 00241 /** 00242 * 親の設定 00243 * @param parent 設定する親 00244 */ 00245 virtual void setParent(CollisionNode* parent){ 00246 CollisionObject::setParent(parent); 00247 setGlobalEnabled(false); 00248 } 00249 00250 /** 00251 * 親の削除 00252 * @param parent 削除する親 00253 */ 00254 virtual void removeParent(CollisionNode* parent){ 00255 CollisionObject::removeParent(parent); 00256 setGlobalEnabled(false); 00257 } 00258 00259 private: 00260 //-------------------------------------------------------------------------- 00261 // コリジョンマスク 00262 u_int collisionMask_; 00263 00264 }; 00265 00266 //------------------------------------------------------------------------------ 00267 } // End of namespace Lamp 00268 #endif // End of COLLISION_LEAF_H_ 00269 //------------------------------------------------------------------------------