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

# LODSceneNode.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 "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     // LOD情報のコピー
    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     // 前回がdisabledでdisabledのままならトラバースしない
    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         // LOD処理
    00076         Vector3 worldPosition = worldMatrix.getTranslation();
    00077         worldPosition -= cameraPosition;
    00078         float distance = worldPosition.getLength();
    00079         // LOD処理
    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             // LOD範囲の変更に対してChangedフラグを立てる必要がある
    00088             // 前回使用したLODかどうかを判別できれば効率化可能
    00089             getSceneNode(i)->traverse(
    00090                 worldMatrix, cameraPosition,
    00091 //              childEnable, globalScaled, globalChanged);
    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 } // End of namespace Lamp
    00111 //------------------------------------------------------------------------------