1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_TransformAnimOverrider.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_TRANSFORMANIMOVERRIDER_H_
19 #define NW_GFX_TRANSFORMANIMOVERRIDER_H_
20 
21 #include <nw/gfx/gfx_AnimOverrider.h>
22 
23 namespace nw {
24 namespace gfx {
25 
26 //---------------------------------------------------------------------------
27 //! @brief トランスフォームアニメーション評価結果を上書きブレンドするクラスです。
28 //!
29 //! ブレンドは各メンバの移動・回転・スケール成分ごとに行われます。
30 //!
31 //! 動作の詳細は、 AnimOverrider をご覧ください。
32 //---------------------------------------------------------------------------
33 class TransformAnimOverrider : public AnimOverrider
34 {
35 public:
36     NW_UT_RUNTIME_TYPEINFO;
37 
38     //----------------------------------------
39     //! @name 作成
40     //@{
41 
42     //! トランスフォームアニメーション上書きを構築するクラスです。
43     class Builder
44     {
45     public:
46         //! コンストラクタです。
Builder()47         Builder()
48         : m_MaxAnimObjects(2) {}
49 
50         //! 最大アニメーションオブジェクト数を設定します。
MaxAnimObjects(int maxAnimObjects)51         Builder& MaxAnimObjects(int maxAnimObjects)
52         {
53             NW_ASSERT(maxAnimObjects > 0);
54             m_MaxAnimObjects = maxAnimObjects;
55             return *this;
56         }
57 
58         //! @brief 生成時に必要なメモリサイズを取得します。
59         //!
60         //! メモリサイズは Builder の設定によって変化します。
61         //! すべての設定が終わった後にこの関数を呼び出してください。
62         //!
63         //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。
64         size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const
65         {
66             os::MemorySizeCalculator size(alignment);
67 
68             GetMemorySizeInternal(&size);
69 
70             return size.GetSizeWithPadding(alignment);
71         }
72 
73         //! @details :private
GetMemorySizeInternal(os::MemorySizeCalculator * pSize)74         void GetMemorySizeInternal(os::MemorySizeCalculator* pSize) const
75         {
76             os::MemorySizeCalculator& size = *pSize;
77 
78             size += sizeof(TransformAnimOverrider);
79             TransformAnimOverrider::GetMemorySizeForInitialize(pSize, m_MaxAnimObjects);
80         }
81 
82         //! @brief トランスフォームアニメーション上書きを生成します。
83         //!
84         //! @param[in] allocator アロケータです。
85         //!
86         //! @return 生成されたトランスフォームアニメーション上書きです。
87         //!
Create(os::IAllocator * allocator)88         TransformAnimOverrider* Create(os::IAllocator* allocator)
89         {
90             void* buf = allocator->Alloc(sizeof(TransformAnimOverrider));
91 
92             if (buf == NULL)
93             {
94                 return NULL;
95             }
96 
97             TransformAnimOverrider* overrider = new(buf) TransformAnimOverrider(allocator);
98 
99             Result result = overrider->Initialize(m_MaxAnimObjects);
100             NW_ASSERT(result.IsSuccess());
101 
102             return overrider;
103         }
104 
105     private:
106         int m_MaxAnimObjects;
107     };
108 
109     //@}
110 
111     //----------------------------------------
112     //! @name 評価
113     //@{
114 
115     //! @brief メンバ単位でアニメーション結果を取得します。
116     //!
117     //! @param[out] target アニメーション結果を書き込む対象です。
118     //! @param[in] memberIdx メンバインデックスです。
119     //!
120     //! @return アニメーション結果を適用した場合は NULL でない値を返します。
121     //!
122     virtual const anim::AnimResult* GetResult(
123         void* target,
124         int memberIdx) const;
125 
126     //@}
127 
128 protected:
129     //----------------------------------------
130     //! @name コンストラクタ/デストラクタ
131     //@{
132 
133     //! コンストラクタです。
134     //!
135     //! :private
TransformAnimOverrider(os::IAllocator * allocator)136     TransformAnimOverrider(
137         os::IAllocator* allocator)
138     : AnimOverrider(allocator)
139     {}
140 
141     //! デストラクタです。
142     //!
143     //! :private
~TransformAnimOverrider()144     virtual ~TransformAnimOverrider() {}
145 
146     //@}
147 };
148 
149 } // namespace gfx
150 } // namespace nw
151 
152 #endif // NW_GFX_TRANSFORMANIMOVERRIDER_H_
153