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