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

SceneNode.h

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 #ifndef SCENE_NODE_H_
00026 #define SCENE_NODE_H_
00027 
00028 #include <Graphics/Scene/SceneObject.h>
00029 #include <Core/Primitive/Axis3.h>
00030 #include <Core/Container/ArrayList.h>
00031 #include <Graphics/Primitive/Visibility.h>
00032 
00033 namespace Lamp{
00034 
00035 class LODSceneNode;
00036 
00037 //------------------------------------------------------------------------------
00038 /**
00039  * シーンノード
00040  */
00041 class SceneNode : public SceneObject{
00042 friend class SceneObjectManagerTemplate<SceneNode>;
00043 friend class SceneNodeManager;
00044 friend class LODSceneNode;
00045 public:
00046     /**
00047      * リファレンスカウントの取得
00048      * @return リファレンスカウント
00049      */
00050     virtual int getReferenceCount() const{
00051         if(parent_ != NULL){ return 1; }
00052         return 0;
00053     }
00054 
00055     //--------------------------------------------------------------------------
00056     /**
00057      * コピー
00058      * @param copyMask コピーマスク
00059      * @return コピーされたシーンノード
00060      */
00061     virtual SceneNode* copy(u_int copyMask = 0) const;
00062 
00063     /**
00064      * 再帰的破棄
00065      * @param sceneNode 破棄するシーンノード
00066      * @return 破棄したオブジェクト数
00067      */
00068     static int recursiveDestroy(SceneNode* sceneNode);
00069 
00070     /**
00071      * 子の再帰的破棄
00072      * @param sceneNode 子を破棄するシーンノード
00073      * @return 破棄したオブジェクト数
00074      */
00075     static int recursiveDestroyChildren(SceneNode* sceneNode);
00076 
00077     //--------------------------------------------------------------------------
00078     /**
00079      * 親の取得
00080      * @return 親
00081      */
00082     virtual SceneNode* getParent() const{ return parent_; }
00083 
00084     //--------------------------------------------------------------------------
00085     /**
00086      * 走査
00087      */
00088     virtual void traverse();
00089 
00090     //--------------------------------------------------------------------------
00091     /**
00092      * ワールド行列の取得
00093      * @return ワールド行列
00094      */
00095     const Matrix34& getWorldMatrix() const{ return worldMatrix_; }
00096 
00097     /**
00098      * ローカル行列の取得
00099      * @return ローカル行列
00100      */
00101     const Matrix34& getLocalMatrix() const{ return axis_.getMatrix(); }
00102 
00103     //--------------------------------------------------------------------------
00104     /**
00105      * スケールの設定
00106      * @param scale スケール
00107      */
00108     virtual void setScale(const Vector3& scale){ axis_.setScale(scale); }
00109 
00110     /**
00111      * スケールの取得
00112      * @return スケール
00113      */
00114     virtual const Vector3& getScale() const{ return axis_.getScale(); }
00115 
00116     /**
00117      * スケールを使用しているか
00118      * @return スケールを使用しているならtrue
00119      */
00120     virtual bool isScaled() const{ return axis_.isScaled(); }
00121 
00122     /**
00123      * グローバルでスケールを使用しているか
00124      * @return グローバルでスケールを使用しているならtrue
00125      */
00126     virtual bool isGlobalScaled() const{ return globalScaled_; }
00127 
00128     //--------------------------------------------------------------------------
00129     /**
00130      * XYZ回転の設定
00131      * @param rotation XYZ回転
00132      */
00133     virtual void setRotationXYZ(const Vector3& rotation){
00134         axis_.setRotationXYZ(rotation);
00135     }
00136 
00137     /**
00138      * XYZ回転の取得
00139      * @return XYZ回転
00140      */
00141     virtual const Vector3& getRotationXYZ(){
00142         return axis_.getRotationXYZ();
00143     }
00144 
00145     //--------------------------------------------------------------------------
00146     /**
00147      * 四元数回転の設定
00148      * @param rotation 四元数回転
00149      */
00150     virtual void setRotationQuaternion(const Quaternion& rotation){
00151         axis_.setRotationQuaternion(rotation);
00152     }
00153 
00154     /**
00155      * 四元数回転の取得
00156      * @return 四元数回転
00157      */
00158     virtual const Quaternion& getRotationQuaternion(){
00159         return axis_.getRotationQuaternion();
00160     }
00161 
00162     //--------------------------------------------------------------------------
00163     /**
00164      * 移動の設定
00165      * @param translation 移動
00166      */
00167     virtual void setTranslation(const Vector3& translation){
00168         axis_.setTranslation(translation);
00169     }
00170 
00171     /**
00172      * 移動の取得
00173      * @return 移動
00174      */
00175     virtual const Vector3& getTranslation() const{
00176         return axis_.getTranslation();
00177     }
00178 
00179     //--------------------------------------------------------------------------
00180     /**
00181      * 変更フラグの取得
00182      * @return 変更されていればtrue
00183      */
00184     virtual bool isChanged() const{ return axis_.isChanged(); }
00185 
00186     /**
00187      * グローバルでの変更フラグの取得
00188      * @return グローバルで変更されていればtrue
00189      */
00190     virtual bool isGlobalChanged() const{ return globalChanged_; }
00191 
00192     //--------------------------------------------------------------------------
00193     /**
00194      * 有効、無効の設定
00195      * @param enabled trueなら有効、falseなら無効
00196      */
00197     virtual void setEnabled(bool enabled){ enabled_ = enabled; }
00198 
00199     /**
00200      * 有効、無効の取得
00201      * @return trueなら有効、falseなら無効
00202      */
00203     virtual bool isEnabled() const{ return enabled_; }
00204 
00205     /**
00206      * グローバルでの有効、無効の取得
00207      * @return trueなら有効、falseなら無効
00208      */
00209     virtual bool isGlobalEnabled() const{ return globalEnabled_; }
00210 
00211     //--------------------------------------------------------------------------
00212     // シーンノードインターフェース
00213     //--------------------------------------------------------------------------
00214     /**
00215      * シーンノードの追加
00216      * @param sceneNode 追加するシーンノード
00217      */
00218     virtual void addSceneNode(SceneNode* sceneNode){
00219         sceneNode->setParent(this);
00220         sceneNodes_.add(sceneNode);
00221     }
00222 
00223     /**
00224      * シーンノードの削除
00225      * @param sceneNode 削除するシーンノード
00226      */
00227     virtual void removeSceneNode(SceneNode* sceneNode){
00228         sceneNode->removeParent(this);
00229         sceneNodes_.removeByValue(sceneNode);
00230     }
00231 
00232     /**
00233      * シーンノード数の取得
00234      * @return シーンノード数
00235      */
00236     virtual int getSceneNodeCount() const{ return sceneNodes_.getCount(); }
00237 
00238     /**
00239      * シーンノードの取得
00240      * @param index インデックス
00241      * @return シーンノード
00242      */
00243     virtual SceneNode* getSceneNode(int index) const{
00244         Assert(index >= 0);
00245         Assert(index < getSceneNodeCount());
00246         return sceneNodes_.get(index);
00247     }
00248 
00249     //--------------------------------------------------------------------------
00250     // シーンリーフインターフェース
00251     //--------------------------------------------------------------------------
00252     /**
00253      * シーンリーフの追加
00254      * @param sceneLeaf 追加するシーンリーフ
00255      */
00256     virtual void addSceneLeaf(SceneLeaf* sceneLeaf);
00257 
00258     /**
00259      * シーンリーフの削除
00260      * @param sceneLeaf 削除するシーンリーフ
00261      */
00262     virtual void removeSceneLeaf(SceneLeaf* sceneLeaf);
00263 
00264     /**
00265      * シーンリーフ数の取得
00266      * @return シーンリーフ数
00267      */
00268     virtual int getSceneLeafCount() const{ return sceneLeafs_.getCount(); }
00269 
00270     /**
00271      * シーンリーフの取得
00272      * @param index インデックス
00273      * @return シーンリーフ
00274      */
00275     virtual SceneLeaf* getSceneLeaf(int index) const{
00276         Assert(index >= 0);
00277         Assert(index < getSceneLeafCount());
00278         return sceneLeafs_.get(index);
00279     }
00280 
00281     //--------------------------------------------------------------------------
00282     // RTTI
00283     //--------------------------------------------------------------------------
00284     /**
00285      * シーンノードかどうか
00286      * @return シーンノードならtrue
00287      */
00288     virtual bool isSceneNode() const{ return true; }
00289 
00290     //--------------------------------------------------------------------------
00291     /**
00292      * レベルオブディティールシーンノードかどうか
00293      * @return レベルオブディティールシーンノードならtrue
00294      */
00295     virtual bool isLODSceneNode() const{ return false; }
00296 
00297     /**
00298      * レベルオブディティールシーンノードへのキャスト
00299      * @return レベルオブディティールシーンノード。型が違えばNULLを返す。
00300      */
00301     virtual LODSceneNode* castLODSceneNode() const{
00302         if(isLODSceneNode()){ return (LODSceneNode*)this; }
00303         return NULL;
00304     }
00305 
00306 protected:
00307     //--------------------------------------------------------------------------
00308     /**
00309      * コンストラクタ
00310      * @param name 名前
00311      * @param scene シーン
00312      */
00313     SceneNode(const String& name, Scene* scene);
00314 
00315     /**
00316      * デストラクタ
00317      */
00318     virtual ~SceneNode();
00319 
00320     /**
00321      * シーンノードの値コピー
00322      * @param destination コピー先シーンノード
00323      * @param copyMask コピーマスク
00324      */
00325     virtual void copySceneNodeValue(
00326         SceneNode* destination, u_int copyMask) const;
00327 
00328     //--------------------------------------------------------------------------
00329     /**
00330      * 走査
00331      * @param parentMatrix 親行列
00332      * @param cameraPosition カメラ位置
00333      * @param parentEnabled 親が有効か
00334      * @param parentScaled 親がスケールを使用しているか
00335      * @param parentChanged 親に変更があったか
00336      */
00337     virtual void traverse(const Matrix34& parentMatrix,
00338         const Vector3& cameraPosition, bool parentEnabled, bool parentScaled,
00339         bool parentChanged);
00340 
00341     /**
00342      * 行列の計算
00343      * @param parentMatrix 親行列
00344      * @param parentChanged 親に変更があったか
00345      * @return 変更があればtrue
00346      */
00347     virtual bool calcMatrix(const Matrix34& parentMatrix, bool parentChanged);
00348 
00349     /**
00350      * グローバルでの有効、無効の設定
00351      * @param globalEnabled trueなら有効、falseなら無効
00352      */
00353     virtual void setGlobalEnabled(bool globalEnabled){
00354         globalEnabled_ = globalEnabled;
00355     }
00356 
00357     /**
00358      * グローバルでスケールを使用しているかの設定
00359      * @param globalScaled グローバルでスケールを使用しているならtrue
00360      */
00361     virtual void setGlobalScaled(bool globalScaled){
00362         globalScaled_ = globalScaled;
00363     }
00364 
00365     /**
00366      * グローバルでの変更フラグの設定
00367      * @param globalChanged trueなら有効、falseなら無効
00368      */
00369     virtual void setGlobalChanged(bool globalChanged){
00370         globalChanged_ = globalChanged;
00371     }
00372 
00373     //--------------------------------------------------------------------------
00374     /**
00375      * 親の設定
00376      * @param parent 設定する親
00377      */
00378     virtual void setParent(SceneNode* parent){
00379         Assert(parent != NULL);
00380         Assert(parent_ == NULL);
00381         parent_ = parent;
00382         setGlobalEnabled(true);
00383     }
00384 
00385     /**
00386      * 親の削除
00387      * @param parent 削除する親
00388      */
00389     virtual void removeParent(SceneNode* parent){
00390         Assert(parent_ != NULL);
00391         Assert(parent_ == parent);
00392         parent_ = NULL;
00393         setGlobalEnabled(true);
00394     }
00395 
00396 private:
00397     //--------------------------------------------------------------------------
00398     // 軸
00399     Axis3 axis_;
00400     // ワールド行列
00401     Matrix34 worldMatrix_;
00402     // シーンノード配列
00403     ArrayList<SceneNode*> sceneNodes_;
00404     // シーンリーフ配列
00405     ArrayList<SceneLeaf*> sceneLeafs_;
00406     // 親
00407     SceneNode* parent_;
00408     // 有効、無効フラグ
00409     bool enabled_;
00410     // グローバルでの有効無効フラグ
00411     bool globalEnabled_;
00412     // グローバルでのスケールフラグ
00413     bool globalScaled_;
00414     // グローバルでの変更フラグ
00415     bool globalChanged_;
00416 
00417 };
00418 
00419 //------------------------------------------------------------------------------
00420 } // End of namespace Lamp
00421 #endif // End of SCENE_NODE_H_
00422 //------------------------------------------------------------------------------

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