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

TranslationCameraManager.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 "System/stdafx.h"
00026 #include "Translator/Camera/TranslationCameraManager.h"
00027 
00028 namespace LampForMaya{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 TranslationCameraManager::TranslationCameraManager() :
00033     database_(256, 0.75f), array_(256){
00034 }
00035 //------------------------------------------------------------------------------
00036 // デストラクタ
00037 TranslationCameraManager::~TranslationCameraManager(){
00038     Assert(database_.getCount() == 0);
00039     Assert(array_.getCount() == 0);
00040     if(getCount() != 0){ clear(); }
00041 }
00042 //------------------------------------------------------------------------------
00043 // カメラの収集
00044 bool TranslationCameraManager::collectCameras(){
00045     MStatus result;
00046     MItDag dagIterator(MItDag::kBreadthFirst, MFn::kCamera, &result);
00047     MayaStatusCheck(result);
00048     MDagPath dagPath;
00049     for( ; !dagIterator.isDone(); dagIterator.next()){
00050         result = dagIterator.getPath(dagPath);
00051         MayaStatusCheck(result);
00052         MFnDagNode dagNode(dagPath, &result);
00053         MayaStatusCheck(result);
00054         // インスタンス化されていればキャンセル
00055         u_int instanceNumber = dagPath.instanceNumber(&result);
00056         MayaStatusCheck(result);
00057         if(instanceNumber > 0){ continue; }
00058         // 名前の取得
00059         MString dagName = dagNode.name(&result);
00060         MayaStatusCheck(result);
00061         // デフォルトカメラをはじく
00062         if((dagName == "perspShape") ||
00063             (dagName == "topShape") ||
00064             (dagName == "frontShape") ||
00065             (dagName == "sideShape")){ continue; }
00066         // カメラの解析
00067         if(!analysisCamera(dagPath)){ return false; }
00068     }
00069     return true;
00070 }
00071 //------------------------------------------------------------------------------
00072 // カメラの解析
00073 bool TranslationCameraManager::analysisCamera(MDagPath dagPath){
00074     MStatus result;
00075     MFnDagNode dagNode(dagPath, &result);
00076     MayaStatusCheck(result);
00077     // 名前の重複が無いかチェック
00078     String cameraName = dagNode.name(&result).asChar();
00079     MayaStatusCheck(result);
00080     TranslationCamera* exist = database_.get(cameraName);
00081     if(exist != NULL){
00082         MayaErrorOut(String("TranslationCameraManager::analysisCamera() "
00083             "名前が重複しています ") + cameraName);
00084         return false;
00085     }
00086     TranslationCamera* camera =
00087         new TranslationCamera(dagPath, cameraName);
00088     if(!camera->analyze()){
00089         delete camera;
00090         return false;
00091     }
00092     database_.put(cameraName, camera);
00093     array_.add(camera);
00094     return true;
00095 }
00096 //------------------------------------------------------------------------------
00097 // アニメーションの収集
00098 bool TranslationCameraManager::collectAnimations(){
00099     for(int i = 0; i < getCount(); i++){
00100         if(!get(i)->analyzeAnimation()){ return false; }
00101     }
00102     return true;
00103 }
00104 //------------------------------------------------------------------------------
00105 // Lampへの変換
00106 bool TranslationCameraManager::convertToLamp(Scene* scene) const{
00107     // カメラのコンバート
00108     for(int i = 0; i < getCount(); i++){
00109         if(!get(i)->convertToLamp(scene)){ return false; }
00110     }
00111     return true;
00112 }
00113 //------------------------------------------------------------------------------
00114 // アニメーションの変換
00115 bool TranslationCameraManager::convertAnimation(
00116     AnimationManager* animationManager, AnimationSet* animationSet){
00117     for(int i = 0; i < getCount(); i++){
00118         if(!get(i)->convertAnimation(animationManager, animationSet)){
00119             return false;
00120         }
00121     }
00122     return true;
00123 }
00124 //------------------------------------------------------------------------------
00125 // クリア
00126 int TranslationCameraManager::clear(){
00127     int result = getCount();
00128     // 要素の削除
00129     for(int i = 0; i < result; i++){ delete array_.get(i); }
00130     array_.clear();
00131     database_.clear();
00132     return result;
00133 }
00134 //------------------------------------------------------------------------------
00135 } // End of namespace LampForMaya
00136 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:55 2005 for LampForMaya by doxygen 1.3.2