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

CalculateBoundingSphereFilter.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/SceneFilter/CalculateBoundingSphereFilter/\
00027 CalculateBoundingSphereFilter.h"
00028 #include "Core/Utility/StringTokenizer.h"
00029 #include "Graphics/Mesh/MeshManager.h"
00030 
00031 namespace Lamp{
00032 
00033 //------------------------------------------------------------------------------
00034 // コンストラクタ
00035 CalculateBoundingSphereFilter::CalculateBoundingSphereFilter(Scene* scene) :
00036     SceneFilterInterface(scene), characterScale_(1.f){
00037 }
00038 //------------------------------------------------------------------------------
00039 // デストラクタ
00040 CalculateBoundingSphereFilter::~CalculateBoundingSphereFilter(){
00041 }
00042 //------------------------------------------------------------------------------
00043 // フィルタ
00044 bool CalculateBoundingSphereFilter::filter(const String& command){
00045     StringTokenizer tokenizer_(command);
00046     if(!tokenizer_.hasMoreTokens()){
00047         ErrorOut("CalculateBoundingSphereFilter::filter() "
00048             "Not found filter name");
00049         return false;
00050     }
00051     String filterName = tokenizer_.getNextToken();
00052     if(filterName != "CalculateBoundingSphere"){
00053         ErrorOut("CalculateBoundingSphereFilter::filter() "
00054             "Invalid filter name %s",
00055             filterName.getBytes());
00056         return false;
00057     }
00058     // オプションの解析
00059     while(tokenizer_.hasMoreTokens()){
00060         String token = tokenizer_.getNextToken();
00061         // キャラクタスケールオプション
00062         if(token == "characterScale"){
00063             if(!tokenizer_.hasMoreTokens()){
00064                 ErrorOut("CalculateBoundingBoxFilter::filter() "
00065                     "Not found characterScale value");
00066                 return false;
00067             }
00068             String characterScaleString = tokenizer_.getNextToken();
00069             if(!characterScaleString.parseFloat(&characterScale_)){
00070                 ErrorOut(String("CalculateBoundingBoxFilter::filter() "
00071                     "Invalid characterScale value ") + characterScaleString);
00072                 return false;
00073             }
00074         }else{
00075             ErrorOut(String("CalculateBoundingBoxFilter::filter() "
00076                 "Unknown option ") + token);
00077             return false;
00078         }
00079     }
00080     return filterScene();
00081 }
00082 //------------------------------------------------------------------------------
00083 // シーンのフィルタ
00084 bool CalculateBoundingSphereFilter::filterScene(){
00085     if(!filterMesh()){ return false; }
00086     return true;
00087 }
00088 //------------------------------------------------------------------------------
00089 // メッシュのフィルタ
00090 bool CalculateBoundingSphereFilter::filterMesh(){
00091     int count = meshManager_->getCount();
00092     // 各メッシュのチェック
00093     for(int i = 0; i < count; i++){
00094         if(!filterMesh(meshManager_->get(i))){ return false; }
00095     }
00096     return true;
00097 }
00098 //------------------------------------------------------------------------------
00099 // メッシュのフィルタ
00100 bool CalculateBoundingSphereFilter::filterMesh(Mesh* mesh){
00101     // バウンディングボックスの中心をスフィアの中心とする
00102     Sphere boundingSphere(mesh->getBoundingBox().getCenter(), 0.f);
00103     int vertexCount = mesh->getVertexCount();
00104     for(int i = 0; i < vertexCount; i++){
00105         boundingSphere.append(mesh->getPosition(i));
00106     }
00107     // キャラクタスケールの適用
00108     if((characterScale_ != 1.f) && mesh->isCharacterMesh()){
00109         boundingSphere.setRadius(boundingSphere.getRadius() * characterScale_);
00110     }
00111     mesh->setBoundingSphere(boundingSphere);
00112     return true;
00113 }
00114 //------------------------------------------------------------------------------
00115 } // End of namespace Lamp
00116 //------------------------------------------------------------------------------

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