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

InformationRenderer.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/Renderer/InformationRenderer.h"
00027 #include "Graphics/PrimitiveRenderer/PrimitiveRenderer.h"
00028 #include "Graphics/PrimitiveRenderer/PrimitiveDrawRequestBuilder.h"
00029 #include "Graphics/Scene/Scene.h"
00030 #include "Graphics/SceneNode/SceneNodeManager.h"
00031 #include "Graphics/Model/CharacterModel.h"
00032 #include "Graphics/Mesh/Mesh.h"
00033 
00034 namespace Lamp{
00035 
00036 /// メッシュバウンディングカラー
00037 const Color4c InformationRenderer::meshBoundingColor_ = Color4c(0, 255, 0, 64);
00038 /// ボーンカラー
00039 const Color4c InformationRenderer::boneColor_ = Color4c(0, 255, 255, 255);
00040 
00041 //------------------------------------------------------------------------------
00042 // 生成、破棄
00043 //------------------------------------------------------------------------------
00044 // コンストラクタ
00045 InformationRenderer::InformationRenderer() : scene_(NULL), camera_(NULL),
00046     isDrawnGrid_(false), isDrawnAxis_(false), isDrawnMeshBounding_(false),
00047     isDrawnBone_(false){
00048     renderer_ = new PrimitiveRenderer;
00049 }
00050 //------------------------------------------------------------------------------
00051 // デストラクタ
00052 InformationRenderer::~InformationRenderer(){
00053     SafeDelete(renderer_);
00054 }
00055 //------------------------------------------------------------------------------
00056 // レンダリング
00057 //------------------------------------------------------------------------------
00058 // レンダリング準備を行う
00059 void InformationRenderer::renderingSetup(Scene* scene){
00060     Assert(scene != NULL);
00061     scene_ = scene;
00062     camera_ = scene_->getCurrentCamera();
00063     Assert(camera_ != NULL);
00064     // メッシュリストの取得
00065     if(isDrawnMeshBounding() || isDrawnBone()){
00066         scene_->getMeshList(&meshList_, camera_);
00067     }
00068     // グリッドの描画
00069     if(isDrawnGrid()){ setupGrid(); }
00070     // 軸の描画
00071     if(isDrawnAxis()){ setupAxis(); }
00072     // メッシュバウンディングの描画
00073     if(isDrawnMeshBounding()){ setupMeshBounding(); }
00074     // ボーンの描画
00075     if(isDrawnBone()){ setupBone(); }
00076     // メッシュリストのクリア
00077     meshList_.clear();
00078 }
00079 //------------------------------------------------------------------------------
00080 // グリッドのセットアップ
00081 void InformationRenderer::setupGrid(){
00082     renderer_->requestGrid(Vector3(100.f, 100.f, 100.f),
00083         Vector3::zero, Vector3::zero, Color4c::white, true);
00084 }
00085 //------------------------------------------------------------------------------
00086 // 軸のセットアップ
00087 void InformationRenderer::setupAxis(){
00088     SceneNodeManager* sceneNodeManager = scene_->getSceneNodeManager();
00089     int sceneNodeCount = sceneNodeManager->getCount();
00090     for(int i = 0; i < sceneNodeCount; i++){
00091         SceneNode* sceneNode = sceneNodeManager->get(i);
00092         if(!sceneNode->isGlobalEnabled()){ continue; }
00093         renderer_->requestAxis(sceneNode->getWorldMatrix(),
00094             Color4c::white, false);
00095     }
00096 }
00097 //------------------------------------------------------------------------------
00098 // メッシュバウンディングのセットアップ
00099 void InformationRenderer::setupMeshBounding(){
00100     int meshCount = meshList_.getCount();
00101     for(int i = 0; i < meshCount; i++){
00102         Mesh* mesh = meshList_[i];
00103         const Sphere& boundingSphere = mesh->getWorldBoundingSphere();
00104         float radius = boundingSphere.getRadius();
00105         renderer_->requestSphere(Vector3(radius, radius, radius),
00106             Vector3::zero, boundingSphere.getCenter(), meshBoundingColor_);
00107     }
00108 }
00109 //------------------------------------------------------------------------------
00110 // ボーンのセットアップ
00111 void InformationRenderer::setupBone(){
00112     /// キャラクタモデルリスト
00113     ArrayList<CharacterModel*> modelList_;
00114     int meshCount = meshList_.getCount();
00115     for(int i = 0; i < meshCount; i++){
00116         // キャラクタモデルかどうか
00117         CharacterModel* model = meshList_[i]->getParent()->castCharacterModel();
00118         if(model == NULL){ continue; }
00119         // すでにそのモデルを描画していないかチェック
00120         int modelCount = modelList_.getCount();
00121         for(int j = 0; j < modelCount; j++){
00122             if(modelList_[j] == model){
00123                 model = NULL;
00124                 break;
00125             }
00126         }
00127         if(model == NULL){ continue; }
00128         modelList_.add(model);
00129         PrimitiveDrawRequest primitive;
00130         PrimitiveDrawRequestBuilder::buildBone(&primitive, model);
00131         renderer_->request(primitive, model->getParent()->getWorldMatrix(),
00132             boneColor_, false);
00133     }
00134 }
00135 //------------------------------------------------------------------------------
00136 // レンダリングを行う
00137 void InformationRenderer::rendering(){
00138     Assert(scene_ != NULL);
00139     Assert(camera_ != NULL);
00140     renderer_->render(camera_);
00141 }
00142 //------------------------------------------------------------------------------
00143 } // End of namespace Lamp
00144 //------------------------------------------------------------------------------

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