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 #include "LampBasic.h" 00026 #include "Collision/System/CollisionLeaf.h" 00027 #include "Collision/System/CollisionScene.h" 00028 #include "Collision/System/CollisionNode.h" 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 // コンストラクタ 00034 CollisionLeaf::CollisionLeaf(const String& name, CollisionScene* scene) : 00035 CollisionObject(name, scene), collisionMask_(1){ 00036 setGlobalEnabled(false); 00037 } 00038 //------------------------------------------------------------------------------ 00039 // デストラクタ 00040 CollisionLeaf::~CollisionLeaf(){ 00041 } 00042 //------------------------------------------------------------------------------ 00043 // 破棄 00044 int CollisionLeaf::destroy(CollisionLeaf* collisionLeaf){ 00045 Assert(collisionLeaf != NULL); 00046 // 親から削除 00047 CollisionNode* parent = collisionLeaf->getParent(); 00048 if(parent != NULL){ parent->removeChild(collisionLeaf); } 00049 // 引数の破棄 00050 collisionLeaf->getScene()->destroyLeaf(collisionLeaf); 00051 return 1; 00052 } 00053 //------------------------------------------------------------------------------ 00054 // 走査 00055 //------------------------------------------------------------------------------ 00056 // 走査のセットアップ 00057 bool CollisionLeaf::traverseSetup(bool parentEnabled, bool parentChanged){ 00058 // グローバル有効フラグ設定 00059 bool globalEnabled = (parentEnabled && isEnabled()); 00060 setGlobalEnabled(globalEnabled); 00061 // グローバルで有効で無いなら処理しない 00062 if(!globalEnabled){ return false; } 00063 00064 // グローバル変更フラグ設定 00065 bool globalChanged = (parentChanged || isChanged()); 00066 setGlobalChanged(globalChanged); 00067 // 変更フラグのリセット 00068 setChanged(false); 00069 // グローバルで変更が無いなら処理しない 00070 if(!globalChanged){ return false; } 00071 00072 return true; 00073 } 00074 //------------------------------------------------------------------------------ 00075 // スケール 00076 //------------------------------------------------------------------------------ 00077 // スケールの設定 00078 void CollisionLeaf::setScale(const Vector3& scale){ 00079 Assert(getParent() != NULL); 00080 getParent()->setScale(scale); 00081 } 00082 //------------------------------------------------------------------------------ 00083 // スケールの取得 00084 const Vector3& CollisionLeaf::getScale() const{ 00085 Assert(getParent() != NULL); 00086 return getParent()->getScale(); 00087 } 00088 //------------------------------------------------------------------------------ 00089 // スケールを使用しているか 00090 bool CollisionLeaf::isScaled() const{ 00091 Assert(getParent() != NULL); 00092 return getParent()->isScaled(); 00093 } 00094 //------------------------------------------------------------------------------ 00095 // グローバルでスケールを使用しているか 00096 bool CollisionLeaf::isGlobalScaled() const{ 00097 Assert(getParent() != NULL); 00098 return getParent()->isGlobalScaled(); 00099 } 00100 //------------------------------------------------------------------------------ 00101 // 回転 00102 //------------------------------------------------------------------------------ 00103 // XYZ回転の設定 00104 void CollisionLeaf::setRotationXYZ(const Vector3& rotation){ 00105 Assert(getParent() != NULL); 00106 getParent()->setRotationXYZ(rotation); 00107 } 00108 //------------------------------------------------------------------------------ 00109 // XYZ回転の取得 00110 const Vector3& CollisionLeaf::getRotationXYZ(){ 00111 Assert(getParent() != NULL); 00112 return getParent()->getRotationXYZ(); 00113 } 00114 //------------------------------------------------------------------------------ 00115 // 四元数回転の設定 00116 void CollisionLeaf::setRotationQuaternion(const Quaternion& rotation){ 00117 Assert(getParent() != NULL); 00118 getParent()->setRotationQuaternion(rotation); 00119 } 00120 //------------------------------------------------------------------------------ 00121 // 四元数回転の取得 00122 const Quaternion& CollisionLeaf::getRotationQuaternion(){ 00123 Assert(getParent() != NULL); 00124 return getParent()->getRotationQuaternion(); 00125 } 00126 //------------------------------------------------------------------------------ 00127 // 移動 00128 //------------------------------------------------------------------------------ 00129 // 移動の設定 00130 void CollisionLeaf::setTranslation(const Vector3& translation){ 00131 Assert(getParent() != NULL); 00132 getParent()->setTranslation(translation); 00133 } 00134 //------------------------------------------------------------------------------ 00135 // 移動の取得 00136 const Vector3& CollisionLeaf::getTranslation() const{ 00137 Assert(getParent() != NULL); 00138 return getParent()->getTranslation(); 00139 } 00140 //------------------------------------------------------------------------------ 00141 // 行列 00142 //------------------------------------------------------------------------------ 00143 // ワールド行列の取得 00144 const Matrix34& CollisionLeaf::getWorldMatrix() const{ 00145 Assert(getParent() != NULL); 00146 return getParent()->getWorldMatrix(); 00147 } 00148 //------------------------------------------------------------------------------ 00149 // ローカル行列の取得 00150 const Matrix34& CollisionLeaf::getLocalMatrix() const{ 00151 Assert(getParent() != NULL); 00152 return getParent()->getLocalMatrix(); 00153 } 00154 //------------------------------------------------------------------------------ 00155 } // End of namespace Lamp 00156 //------------------------------------------------------------------------------