1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_Light.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_GFX_LIGHT_H_
19 #define NW_GFX_LIGHT_H_
20 
21 #include <nw/gfx/gfx_TransformNode.h>
22 #include <nw/gfx/res/gfx_ResLight.h>
23 
24 namespace nw
25 {
26 namespace gfx
27 {
28 
29 //---------------------------------------------------------------------------
30 //! @brief        ライトを表すクラスです。
31 //---------------------------------------------------------------------------
32 class Light : public TransformNode
33 {
34 private:
35     NW_DISALLOW_COPY_AND_ASSIGN(Light);
36 
37 public:
38     NW_UT_RUNTIME_TYPEINFO;
39 
40     //! @brief 設定内容です。
41     struct Description : public TransformNode::Description
42     {
43         //! @brief コンストラクタです。
DescriptionDescription44         Description(){}
45     };
46 
47 
48     //----------------------------------------
49     //! @name シーンツリー
50     //@{
51 
52     //! @brief        ビジターを受け付けます。
53     //!
54     //! @param[in]    visitor ビジターです。
55     //!
56     virtual void Accept(ISceneVisitor* visitor);
57 
58     //@}
59 
60     //----------------------------------------
61     //! @name アニメーション
62     //@{
63 
64     //! @brief アニメーショングループを取得します。
65     //!
66     //! ライトを DynamicBuilder で生成した場合は NULL を返します。
67     //! その場合、アニメーションは設定できません。
GetAnimGroup()68     AnimGroup* GetAnimGroup() { return m_AnimGroup; }
69 
70     //! @brief アニメーショングループを取得します。
71     //!
72     //! ライトを DynamicBuilder で生成した場合は NULL を返します。
73     //! その場合、アニメーションは設定できません。
GetAnimGroup()74     const AnimGroup* GetAnimGroup() const { return m_AnimGroup; }
75 
76     //! @brief アニメーションオブジェクトを取得します。
GetAnimObject()77     AnimObject* GetAnimObject()
78     {
79         NW_NULL_ASSERT(m_AnimBinding);
80         return m_AnimBinding->GetAnimObject(0);
81     }
82 
83     //! @brief アニメーションオブジェクトを取得します。
GetAnimObject()84     const AnimObject* GetAnimObject() const
85     {
86         NW_NULL_ASSERT(m_AnimBinding);
87         return m_AnimBinding->GetAnimObject(0);
88     }
89 
90     //! @brief アニメーションオブジェクトを設定します。
91     //!
92     //! @param[in] animObject 設定するアニメーションオブジェクトです。NULL を指定するとアニメーションを解除します。
SetAnimObject(AnimObject * animObject)93     void SetAnimObject(AnimObject* animObject)
94     {
95         NW_NULL_ASSERT(m_AnimBinding);
96         NW_FAILSAFE_IF(!ValidateLightAnimType(animObject))
97         {
98             NW_LOG("type mismatch between Light and Animation. Animation did not set.\n");
99             return;
100         }
101         m_AnimBinding->SetAnimObject(0, animObject);
102     }
103 
104     //@}
105 
106 protected:
107     //----------------------------------------
108     //! @name コンストラクタ/デストラクタ
109     //@{
110 
111     //! コンストラクタです。
Light(os::IAllocator * allocator,ResTransformNode resObj,const Light::Description & description)112     Light(
113         os::IAllocator* allocator,
114         ResTransformNode resObj,
115         const Light::Description& description)
116     : TransformNode(
117         allocator,
118         resObj,
119         description),
120       m_OriginalValue(NULL),
121       m_AnimGroup(NULL)
122     {}
123 
124     //! デストラクタです。
~Light()125     virtual ~Light()
126     {
127         ut::SafeDestroy(m_AnimGroup);
128     }
129 
130     //@}
131 
132     //! @brief アニメーショングループを作成します。
133     Result CreateAnimGroup(os::IAllocator* allocator);
134 
135     //! @brief アニメーションに登録するモデルデータのポインタを取得します。
136     void* GetAnimTargetObject(const anim::ResAnimGroupMember& anim);
137 
138     //! @brief OriginalValueを破棄します。
139     void DestroyOriginalValue();
140 
141     // ValidateLightAnimTypeで使用します。
142     virtual u32 GetLightType() const = 0; //!< :private
143     virtual u32 GetLightKind() const = 0; //!< :private
144 
145     ResLight m_OriginalValue;
146     math::Transform3 m_OriginalTransform;
147 
148 private:
149     //! バインドするアニメーションのライト種類と、
150     //! インスタンスのライト種類が等しいかチェックします。
151     //! :private
152     bool ValidateLightAnimType(AnimObject* animObject);
153 
154     AnimGroup* m_AnimGroup;
155 };
156 
157 } // namespace gfx
158 } // namespace nw
159 
160 #endif // NW_GFX_LIGHT_H_
161