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 "Graphics/SceneNode/LODSceneNode.h"
00027 #include "Graphics/SceneNode/SceneNodeManager.h"
00028 #include "Graphics/Model/Model.h"
00029
00030 namespace Lamp{
00031
00032
00033
00034 LODSceneNode::LODSceneNode(const String& name, Scene* scene) :
00035 SceneNode(name, scene), lodThresholdCount_(0), lodThreshold_(NULL){
00036 }
00037
00038
00039 LODSceneNode::~LODSceneNode(){
00040 SafeArrayDelete(lodThreshold_);
00041 }
00042
00043
00044 LODSceneNode* LODSceneNode::copyLODSceneNode(u_int copyMask) const{
00045 SceneNodeManager* manager = scene_->getSceneNodeManager();
00046 LODSceneNode* destination =
00047 manager->createLODSceneNode(manager->rename(name_));
00048 copySceneNodeValue(destination, copyMask);
00049
00050 destination->setLODThresholdCount(lodThresholdCount_);
00051 for(int i = 0; i < lodThresholdCount_; i++){
00052 destination->setLODThreshold(i, lodThreshold_[i]);
00053 }
00054 return destination;
00055 }
00056
00057
00058 void LODSceneNode::traverse(const Matrix34& parentMatrix,
00059 const Vector3& cameraPosition, bool parentEnabled, bool parentScaled,
00060 bool parentChanged){
00061 bool preGlobalEnabled = isGlobalEnabled();
00062 bool globalEnabled = (parentEnabled && isEnabled());
00063 setGlobalEnabled(globalEnabled);
00064
00065 if((!preGlobalEnabled) && (!globalEnabled)){ return; }
00066
00067
00068 bool globalChanged = calcMatrix(parentMatrix, parentChanged);
00069 setGlobalChanged(globalChanged);
00070
00071 bool globalScaled = (parentScaled || isScaled());
00072 setGlobalScaled(globalScaled);
00073 const Matrix34& worldMatrix = getWorldMatrix();
00074 if(globalEnabled){
00075
00076 Vector3 worldPosition = worldMatrix.getTranslation();
00077 worldPosition -= cameraPosition;
00078 float distance = worldPosition.getLength();
00079
00080 int sceneNodeCount = getSceneNodeCount();
00081 Assert((lodThresholdCount_ - 1) == sceneNodeCount);
00082 for(int i = 0; i < sceneNodeCount; i++){
00083 Assert(lodThreshold_[i] < lodThreshold_[i + 1]);
00084
00085 bool childEnable = ((distance >= lodThreshold_[i]) &&
00086 (distance < lodThreshold_[i + 1]));
00087
00088
00089 getSceneNode(i)->traverse(
00090 worldMatrix, cameraPosition,
00091
00092 childEnable, globalScaled, (childEnable || globalChanged));
00093 }
00094 }else{
00095
00096 int sceneNodeCount = getSceneNodeCount();
00097 for(int i = 0; i < sceneNodeCount; i++){
00098 getSceneNode(i)->traverse(worldMatrix, cameraPosition,
00099 globalEnabled, globalScaled, globalChanged);
00100 }
00101 }
00102
00103 int sceneLeafCount = getSceneLeafCount();
00104 for(int i = 0; i < sceneLeafCount; i++){
00105 getSceneLeaf(i)->traverse(worldMatrix,
00106 globalEnabled, globalScaled, globalChanged);
00107 }
00108 }
00109
00110 }
00111