00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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 }
00129