Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

CollisionNode.cpp

Go to the documentation of this file.
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/CollisionNode.h"
00027 #include "Collision/System/CollisionScene.h"
00028 
00029 namespace Lamp{
00030 
00031 //------------------------------------------------------------------------------
00032 // 生成、破棄
00033 //------------------------------------------------------------------------------
00034 // コンストラクタ
00035 CollisionNode::CollisionNode(const String& name, CollisionScene* scene) :
00036     CollisionObject(name, scene), worldMatrix_(Matrix34::unit),
00037     globalScaled_(false){
00038     setGlobalEnabled(true);
00039 }
00040 //------------------------------------------------------------------------------
00041 // デストラクタ
00042 CollisionNode::~CollisionNode(){
00043 }
00044 //------------------------------------------------------------------------------
00045 // コピー
00046 //------------------------------------------------------------------------------
00047 // コリジョンノードのコピー
00048 CollisionNode* CollisionNode::copyCollisionNode() const{
00049     CollisionNode* destination =
00050         getScene()->createCollisionNode(getScene()->renameNode(getName()));
00051     // コリジョンオブジェクトの値をコピー
00052     copyCollisionObjectValue(destination);
00053     // メンバのコピー
00054     destination->axis_ = axis_;
00055     // 子供のコピー
00056     int childCount = getChildCount();
00057     for(int i = 0; i < childCount; i++){
00058         destination->addChild(getChild(i)->copy());
00059     }
00060     return destination;
00061 }
00062 //------------------------------------------------------------------------------
00063 // 再帰的破棄
00064 int CollisionNode::recursiveDestroy(CollisionNode* collisionNode){
00065     CollisionScene* scene = collisionNode->getScene();
00066     Assert(collisionNode != scene->getRootNode());
00067     int result = recursiveDestroyChildren(collisionNode);
00068     // 親から削除
00069     CollisionNode* parent = collisionNode->getParent();
00070     if(parent != NULL){ parent->removeChild(collisionNode); }
00071     // 引数の破棄
00072     scene->destroyNode(collisionNode);
00073     result++;
00074     return result;
00075 }
00076 //------------------------------------------------------------------------------
00077 // 子の再帰的破棄
00078 int CollisionNode::recursiveDestroyChildren(CollisionNode* collisionNode){
00079     Assert(collisionNode != NULL);
00080     int result = 0;
00081     // 子の破棄
00082     int childCount = collisionNode->getChildCount();
00083     for(int i = childCount - 1; i >= 0; i--){
00084         result += CollisionObject::recursiveDestroy(collisionNode->getChild(i));
00085     }
00086     return result;
00087 }
00088 //------------------------------------------------------------------------------
00089 // 走査
00090 //------------------------------------------------------------------------------
00091 // 走査
00092 void CollisionNode::traverseImplement(const Matrix34& parentMatrix,
00093     bool parentEnabled, bool parentScaled, bool parentChanged){
00094     // グローバル有効フラグ設定
00095     bool preGlobalEnabled = isGlobalEnabled();
00096     bool globalEnabled = (parentEnabled && isEnabled());
00097     setGlobalEnabled(globalEnabled);
00098     // 前回がdisabledでdisabledのままならトラバースしない
00099     if((!preGlobalEnabled) && (!globalEnabled)){ return; }
00100 
00101     // 変更フラグ
00102     bool globalChanged = (isChanged() || parentChanged);
00103     setGlobalChanged(globalChanged);
00104     // 変更フラグのリセット
00105     setChanged(false);
00106 
00107     // グローバルスケールフラグ設定
00108     bool globalScaled = (parentScaled || isScaled());
00109     setGlobalScaled(globalScaled);
00110 
00111     // 行列の計算、ここでaxis_のchangedはリセットされる
00112     axis_.buildMatrix();
00113     if(globalChanged){
00114         worldMatrix_ = parentMatrix * getLocalMatrix();
00115     }else{
00116         Assert((parentMatrix * getLocalMatrix()).epsilonEquals(
00117             worldMatrix_, 0.0001f));
00118     }
00119 
00120     // 子供を呼ぶ
00121     int childCount = getChildCount();
00122     for(int i = 0; i < childCount; i++){
00123         getChild(i)->traverseImplement(worldMatrix_,
00124             globalEnabled, globalScaled, globalChanged);
00125     }
00126 }
00127 //------------------------------------------------------------------------------
00128 } // End of namespace Lamp
00129 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:29 2005 for Lamp by doxygen 1.3.2