/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_VertexLight.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 24209 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_VERTEXLIGHT_H_ #define NW_GFX_VERTEXLIGHT_H_ #include #include #include #include #if defined(NW_GFX_VERTEX_LIGHT_ENABLED) namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief 頂点ライトを表すクラスです。 //--------------------------------------------------------------------------- class VertexLight : public Light { private: NW_DISALLOW_COPY_AND_ASSIGN(VertexLight); public: NW_UT_RUNTIME_TYPEINFO; //---------------------------------------- //! @name 取得/設定 //@{ //! @brief ライト方向を取得します。 //! //! SceneUpdater で ResLight の m_Direction から親ノードの回転を継承フラグに応じて計算もしくはコピーされます。 //! Direction を変更する場合は、SceneUpdater::UpdateTransformNode の実行前ならば ResLight::SetDirection を用い、 //! SceneUpdater の実行後ではこちらの Direction を直接編集してください。 //! //! @return ライト方向です。 //! const math::VEC3& Direction() const { return this->m_Direction; } //! @brief ライト方向を取得します。 //! //! SceneUpdater で ResLight の m_Direction から親ノードの回転を継承フラグに応じて計算もしくはコピーされます。 //! Direction を変更する場合は、SceneUpdater::UpdateTransformNode の実行前ならば ResLight::SetDirection を用い、 //! SceneUpdater の実行後ではこちらの Direction を直接編集してください。 //! //! @return ライト方向です。 //! math::VEC3& Direction() { return this->m_Direction; } //@} //! @brief 設定内容です。 struct Description : public Light::Description { //! @brief コンストラクタです。 Description(){} }; //---------------------------------------- //! @name 作成/破棄 //@{ //! @brief 頂点ライトを動的に構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class DynamicBuilder { public: //! コンストラクタです。 DynamicBuilder() {} //! デストラクタです。 ~DynamicBuilder() {} //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_Description.isFixedSizeMemory = isFixedSizeMemory; return *this; } //! 子の最大数を設定します。 DynamicBuilder& MaxChildren(int maxChildren) { m_Description.maxChildren = maxChildren; return *this; } //! 管理できるコールバックの最大数を設定します。 DynamicBuilder& MaxCallbacks(int maxCallbacks) { m_Description.maxCallbacks = maxCallbacks; return *this; } //! @brief 頂点ライトを生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成した頂点ライトを返します。 //! VertexLight* Create(os::IAllocator* allocator); private: VertexLight::Description m_Description; }; //! @brief 頂点ライトを生成します。 //! //! @param[in] parent 親のノードです。 //! @param[in] resource リソースです。 //! @param[in] description 設定内容です。 //! @param[in] allocator アロケータです。 //! //! @return 生成された頂点ライトです。 //! static VertexLight* Create( SceneNode* parent, ResSceneObject resource, const VertexLight::Description& description, os::IAllocator* allocator); //@} //---------------------------------------- //! @name トランスフォーム //@{ //! @brief 方向情報を更新します。 virtual void UpdateDirection(); //@} //---------------------------------------- //! @name シーンツリー //@{ //! @brief ビジターを受け付けます。 //! //! @param[in] visitor ビジターです。 //! virtual void Accept(ISceneVisitor* visitor); //@} //---------------------------------------- //! @name リソース //@{ //! 頂点ライトのリソースを取得します。 ResVertexLight GetResVertexLight() { return ResStaticCast(this->GetResSceneObject()); } //! 頂点ライトのリソースを取得します。 const ResVertexLight GetResVertexLight() const { return ResStaticCast(this->GetResSceneObject()); } //@} protected: struct ResVertexLightDataDestroyer : public std::unary_function { ResVertexLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator) {} result_type operator()(argument_type data) { DestroyResVertexLight(m_Allocator, data); } os::IAllocator* m_Allocator; }; //! 動的生成したライトリソースを破棄するための MovePtr の定義です。 typedef ut::MovePtr ResPtr; //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 VertexLight( os::IAllocator* allocator, ResVertexLight resObj, const VertexLight::Description& description) : Light( allocator, resObj, description), m_Direction(resObj.GetDirection()) {} //! コンストラクタです。 VertexLight( os::IAllocator* allocator, ResPtr resource, const VertexLight::Description& description) : Light( allocator, ResVertexLight(resource.Get()), description), m_Resource(resource) { m_Direction = this->GetResVertexLight().GetDirection(); } //! デストラクタです。 virtual ~VertexLight() { DestroyOriginalValue(); } //@} private: virtual Result Initialize(os::IAllocator* allocator); //--------------------------------------------------------------------------- //! @brief ResVertexLightData のリソースを生成します。 //! //! @param[in] allocator リソース用のメモリを確保するアロケータです。 //! @param[in] name リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。 //! //! @return ResVertexLightData へのポインタです。 //--------------------------------------------------------------------------- static ResVertexLightData* CreateResVertexLight(os::IAllocator* allocator, const char* name = NULL); //--------------------------------------------------------------------------- //! @brief ResVertexLightData のリソースを破棄します。 //! //! @param[in] resVertexLight ResVertexLightData へのポインタです。 //! @param[in] allocator リソース用のメモリを開放するアロケータです。 //--------------------------------------------------------------------------- static void DestroyResVertexLight(os::IAllocator* allocator, ResVertexLightData* resVertexLight); //! アニメーションを初期状態に戻すため、初期化時の状態を保存します。 Result CreateOriginalValue(os::IAllocator* allocator); ResPtr m_Resource; math::VEC3 m_Direction; }; } // namespace gfx } // namespace nw #endif #endif // NW_GFX_VERTEXLIGHT_H_