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

# TranslationSceneNodeInstance.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/Instance/TranslationSceneNodeInstance.h"
    00027 #include "Graphics/SceneNode/SceneNodeManager.h"
    00028
    00029 namespace LampForMaya{
    00030
    00031 //------------------------------------------------------------------------------
    00032 // コンストラクタ
    00033 TranslationSceneNodeInstance::TranslationSceneNodeInstance(
    00034     const MDagPath& initializePath, const String& initializeName) :
    00035     TranslationInstance(initializePath, initializeName),
    00036     source_(NULL), destination_(NULL){
    00037 }
    00038 //------------------------------------------------------------------------------
    00039 // デストラクタ
    00040 TranslationSceneNodeInstance::~TranslationSceneNodeInstance(){
    00041 }
    00042 //------------------------------------------------------------------------------
    00043 // 分析
    00044 bool TranslationSceneNodeInstance::analyze(){
    00045     if(!analyzeInstance()){ return false; }
    00046
    00047     MStatus result;
    00048     String errorString;
    00049     // トランスフォーム初期化
    00050     MFnTransform transform(dagPath_, &result);
    00051     MayaStatusCheck(result);
    00052
    00053     // スケールピボット移動値が0であるかチェック
    00054     MPoint scalePivotTrans =
    00055         transform.scalePivotTranslation(MSpace::kTransform, &result);
    00056     MayaStatusCheck(result);
    00057     if(!zeroCheck(scalePivotTrans)){
    00058         errorString.format("TranslationSceneNodeInstance::analyze() "
    00059             "scalePivotTranslationが0でない ( %8f, %8f, %8f ) %s",
    00060             scalePivotTrans.x, scalePivotTrans.y, scalePivotTrans.z,
    00061             name_.getBytes());
    00062         MayaErrorOut(errorString);
    00063         return false;
    00064     }
    00065
    00066     // 回転ピボット移動値が0であるかチェック
    00067     MPoint rotationPivotTrans =
    00068         transform.rotatePivotTranslation(MSpace::kTransform, &result);
    00069     MayaStatusCheck(result);
    00070     if(!zeroCheck(rotationPivotTrans)){
    00071         errorString.format("TranslationSceneNodeInstance::analyze() "
    00072             "rotationPivotTransが0でない ( %8f, %8f, %8f ) %s",
    00073             rotationPivotTrans.x, rotationPivotTrans.y,
    00074             rotationPivotTrans.z, name_.getBytes());
    00075         MayaErrorOut(errorString);
    00076         return false;
    00077     }
    00078
    00079     // シアーが0であるかチェック
    00080     double shearArray[3];
    00081     result = transform.getShear(shearArray);
    00082     MPoint shear(shearArray);
    00083     if(!zeroCheck(shear)){
    00084         errorString.format("TranslationSceneNodeInstance::analyze() "
    00085             "shearが0でない ( %8f, %8f, %8f ) %s",
    00086             shear.x, shear.y, shear.z, name_.getBytes());
    00087         MayaErrorOut(errorString);
    00088         return false;
    00089     }
    00090
    00091     // ピボット
    00092     MPoint scalePivot = transform.scalePivot(MSpace::kTransform, &result);
    00093     MayaStatusCheck(result);
    00094     MPoint rotationPivot =
    00095         transform.rotatePivot(MSpace::kTransform, &result);
    00096     MayaStatusCheck(result);
    00097     MPoint pivotDifference = scalePivot - rotationPivot;
    00098     if(!zeroCheck(pivotDifference)){
    00099         errorString.format("TranslationSceneNodeInstance::analyze() "
    00100             "scalePivotとrotationPivotが同じでない "
    00101             "scale ( %8f, %8f, %8f ) rotation ( %8f, %8f, %8f ) %s",
    00102             scalePivot.x, scalePivot.y, scalePivot.z,
    00103             rotationPivot.x, rotationPivot.y, rotationPivot.z,
    00104             name_.getBytes());
    00105         MayaErrorOut(errorString);
    00106         return false;
    00107     }
    00108     pivot_.set((float)rotationPivot.x,
    00109         (float)rotationPivot.y, (float)rotationPivot.z);
    00110
    00111     // スケール
    00112     double scale[3];
    00113     result = transform.getScale(scale);
    00114     MayaStatusCheck(result);
    00115     scale_.set((float)scale[0], (float)scale[1], (float)scale[2]);
    00116
    00117     // 回転
    00118     MEulerRotation rotation;
    00119     result = transform.getRotation(rotation);
    00120     MayaStatusCheck(result);
    00121     if(rotation.order != MEulerRotation::kXYZ){
    00122         errorString.format("TranslationSceneNodeInstance::analyze() "
    00123             "回転順序はXYZしかサポートしていません %s", name_.getBytes());
    00124         MayaErrorOut(errorString);
    00125         return false;
    00126     }
    00127     rotation_.set((float)rotation.x, (float)rotation.y, (float)rotation.z);
    00128
    00129     // 移動
    00130     MVector translation =
    00131         transform.translation(MSpace::kTransform, &result);
    00132     MayaStatusCheck(result);
    00133     translation_.set(
    00134         (float)translation.x, (float)translation.y, (float)translation.z);
    00135
    00136     // ピボットのコンパイル
    00137     translation_ += pivot_;
    00138     pivot_.set(0.f, 0.f, 0.f);
    00139     return true;
    00140 }
    00141 //------------------------------------------------------------------------------
    00142 // Lampへの変換
    00143 bool TranslationSceneNodeInstance::convertToLamp(Scene* scene){
    00144     // 親シーンノードの検索
    00145     SceneNodeManager* sceneNodeManager = scene->getSceneNodeManager();
    00146     SceneNode* target = sceneNodeManager->search(parentSceneNodeName_);
    00147     if(target == NULL){
    00148         MayaErrorOut(String("TranslationSceneNodeInstance::convertToLamp() "
    00149             "インスタンス先のシーンノードが見つかりません ") +
    00150             parentSceneNodeName_);
    00151         return false;
    00152     }
    00153
    00154     // シーンノードインスタンス
    00155     SceneNode* sceneNode = sceneNodeManager->search(name_);
    00156     if(sceneNode == NULL){
    00157         MayaErrorOut(String("TranslationSceneNodeInstance::convertToLamp() "
    00158             "インスタンス元のシーンノード" + name_ + "が見つかりません ") +
    00159             parentSceneNodeName_);
    00160         return false;
    00161     }
    00162     source_ = sceneNode;
    00163     SceneNode* copySceneNode = sceneNode->copy(0);
    00164     destination_ = copySceneNode;
    00165
    00166     // 値のコピー
    00167     copySceneNode->setScale(scale_);
    00168     copySceneNode->setRotationXYZ(rotation_);
    00169     copySceneNode->setTranslation(translation_);
    00170     copySceneNode->setEnabled(visibility_);
    00171     target->addSceneNode(copySceneNode);
    00172     return true;
    00173 }
    00174 //------------------------------------------------------------------------------
    00175 } // End of namespace LampForMaya
    00176 //------------------------------------------------------------------------------