/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AnimObject.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_ANIMOBJECT_H_ #define NW_GFX_ANIMOBJECT_H_ #include #include #include #include namespace nw { namespace gfx { class AnimGroup; //--------------------------------------------------------------------------- //! @brief アニメーションの重みを比較します。 //! //! @param[in] weight 重み //! @param[in] value 比較する値 //! //! @return 重みと比較する値の誤差が許容値以下なら true を返します。 //--------------------------------------------------------------------------- NW_INLINE bool AnimWeightNearlyEqual(const float weight, const float value) { // 0.1%未満は無視することとします。 const float Epsilon = 0.001f; return math::FAbs(weight - value) <= Epsilon; } //--------------------------------------------------------------------------- //! @brief アニメーションの重みが 0 にほぼ等しいか比較します。 //! //! @param[in] weight 重み //! //! @return 重みと 0 との誤差が許容値以下なら true を返します。 //--------------------------------------------------------------------------- NW_INLINE bool AnimWeightNearlyEqualZero(const float weight) { return AnimWeightNearlyEqual(weight, 0.0f); } //--------------------------------------------------------------------------- //! @brief アニメーションの重みが 1 にほぼ等しいか比較します。 //! //! @param[in] weight 重み //! //! @return 重みと 1 との誤差が許容値以下なら true を返します。 //--------------------------------------------------------------------------- NW_INLINE bool AnimWeightNearlyEqualOne(const float weight) { return AnimWeightNearlyEqual(weight, 1.0f); } //--------------------------------------------------------------------------- //! @brief アニメーションブレンドの重みを正規化するスケールを取得します。 //! //! @param[in] weightSum 重みの合計です。 //! //! @return 重みを正規化するスケールです。 //--------------------------------------------------------------------------- NW_INLINE float GetAnimWeightNormalizeScale(float weightSum) { return AnimWeightNearlyEqualOne(weightSum) || AnimWeightNearlyEqualZero(weightSum) ? 1.0f : 1.0f / weightSum; } //--------------------------------------------------------------------------- //! @brief アニメーション評価を抽象化するクラスです。 //! 抽象クラスですのでインスタンス化して使用することはできません。 //! //! フレームを進める、各フレームの値を取得する、などの動作を抽象化しています。 //! 単一のアニメーションを評価する AnimEvaluator, 複数のアニメーションをブレンドする AnimBlender などの派生クラスがあります。 //--------------------------------------------------------------------------- class AnimObject : public GfxObject { public: //! @details :private NW_UT_RUNTIME_TYPEINFO; //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 AnimObject(os::IAllocator* allocator, u32 animType) : GfxObject(allocator), m_AnimGroup(NULL), m_AnimType(animType) {} //! デストラクタです。 virtual ~AnimObject() {} //@} //---------------------------------------- //! @name 基本操作 //@{ //! @brief アニメーションを関連付けます。 //! //! @param[in] animGroup アニメーショングループです。 //! //! @return バインドに成功したら true を返します。 //! //! @sa TryBind bool Bind(AnimGroup* animGroup) { return TryBind(animGroup).IsSuccess(); } //! @brief アニメーションを関連付けます。 //! //! Bind() よりも詳細なバインド結果を得ることができます。 //! //! @param[in] animGroup アニメーショングループです。 //! //! @return バインドの結果を返します。 //! //! @sa Bind //! @sa BindResult virtual Result TryBind(AnimGroup* animGroup) = 0; //! アニメーションの関連付けを解除します。 virtual void Release() = 0; //! フレームを更新します。 virtual void UpdateFrame() = 0; //@} //---------------------------------------- //! @name 評価 //@{ //! @brief メンバ単位でアニメーション結果を取得します。 //! //! @param[out] target アニメーション結果を書き込む対象です。 //! @param[in] memberIdx メンバインデックスです。 //! //! @return アニメーション結果を返します。 //! ブレンドオペレーションを使用する場合は、返り値のアニメーション結果を使用してください。 //! virtual const anim::AnimResult* GetResult( void* target, int memberIdx) const = 0; //@} //---------------------------------------- //! @name 取得/設定 //@{ //! アニメーショングループを取得します。 const AnimGroup* GetAnimGroup() const { return m_AnimGroup; } //! アニメーショングループを取得します。 AnimGroup* GetAnimGroup() { return m_AnimGroup; } //! アニメーショングループを設定します。 void SetAnimGroup(AnimGroup* group) { m_AnimGroup = group; } //! @brief メンバに関連付けられたアニメーションが存在するかどうかを取得します。 //! //! @param[in] memberIdx メンバインデックスです。 //! //! @return アニメーションが存在すれば true を返します。 //! virtual bool HasMemberAnim(int memberIdx) const = 0; //@} //---------------------------------------- //! @name キャッシュ //@{ //! アニメーション評価結果の内部キャッシュが古ければ更新します。 virtual void UpdateCache() = 0; //! @details :private enum { ANIMTYPE_SIMPLE, ANIMTYPE_TRANSFORM_SIMPLE, ANIMTYPE_BLENDER }; //! @details :private u32 GetAnimType() const { return m_AnimType; } //@} protected: //! @details :private AnimGroup* m_AnimGroup; //! @details :private u32 m_AnimType; }; } // namespace gfx } // namespace nw #endif // NW_GFX_ANIMOBJECT_H_