/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ResCamera.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: 18106 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_RESCAMERA_H_ #define NW_GFX_RESCAMERA_H_ #include #include #include #include #include #include namespace nw { namespace gfx { namespace res { // TODO: Updaterクラス構造の最適化をおこなう。 //! @details :private struct ResCameraData : public ResTransformNodeData { nw::ut::ResS32 m_ViewType; nw::ut::ResS32 m_ProjectionType; nw::ut::Offset toViewUpdater; nw::ut::Offset toProjectionUpdater; nw::ut::ResF32 m_WScale; }; //! @details :private struct ResCameraViewUpdaterData { nw::ut::ResTypeInfo typeInfo; }; //! @details :private struct ResCameraProjectionUpdaterData { nw::ut::ResTypeInfo typeInfo; nw::ut::ResF32 m_Near; nw::ut::ResF32 m_Far; }; //! @details :private struct ResAimTargetViewUpdaterData : public ResCameraViewUpdaterData { enum Flag { FLAG_INHERITING_TARGET_ROTATE = 0x1 << 0, FLAG_INHERITING_TARGET_TRANSLATE = 0x1 << 1 }; nw::ut::ResU32 m_Flags; nw::ut::ResVec3 m_TargetPosition; nw::ut::ResF32 m_Twist; }; //! @details :private struct ResLookAtTargetViewUpdaterData : public ResCameraViewUpdaterData { enum Flag { FLAG_INHERITING_UP_ROTATE = 0x1 << 0, FLAG_INHERITING_TARGET_ROTATE = 0x1 << 1, FLAG_INHERITING_TARGET_TRANSLATE = 0x1 << 2 }; nw::ut::ResU32 m_Flags; nw::ut::ResVec3 m_TargetPosition; nw::ut::ResVec3 m_UpwardVector; }; //! @details :private struct ResRotateViewUpdaterData : public ResCameraViewUpdaterData { enum Flag { FLAG_INHERITING_ROTATE = 0x1 << 0 }; nw::ut::ResU32 m_Flags; nw::ut::ResVec3 m_ViewRotate; }; struct ResProjectionRect { nw::ut::ResF32 m_AspectRatio; nw::ut::ResF32 m_Height; nw::ut::ResVec2 m_Center; //---------------------------------------- //! @name 取得/設定 //@{ //! @brief nw::ut::Rect 形式の矩形情報に変換するキャスト演算子です。 operator nw::ut::Rect() const { f32 width = m_Height * m_AspectRatio; return nw::ut::Rect( m_Center.x - width / 2, m_Center.y - m_Height / 2, m_Center.x + width / 2, m_Center.y + m_Height / 2 ); } //! @brief 高さを取得します。 //! //! @return 矩形の高さを返します。 f32 GetHeight() const { return m_Height; } //! @brief 幅を取得します。 //! //! @return 矩形の幅を返します。 f32 GetWidth() const { return m_Height * m_AspectRatio; } //! @brief アスペクト比を取得します。 //! //! @return 矩形のアスペクト比を返します。 f32 GetAspectRatio() const { return m_AspectRatio; } //! @brief 中心座標を取得します。 //! //! @return 矩形の中心座標を返します。 nw::math::VEC2 GetCenter() const { return m_Center; } //! @brief 廃止予定となります。 //! SetWithYFlip() が以前と同等の挙動となります。 //! //! @sa SetWithoutFlip //! @sa SetWithYFlip NW_DEPRECATED_FUNCTION(void Set( f32 l, f32 r, f32 b, f32 t )) { SetWithYFlip(l, r, b, t); } //! @brief 左上、右下の座標で矩形を設定します。 //! //! @param[in] l 矩形の左座標 //! @param[in] r 矩形の右座標 //! @param[in] b 矩形の下座標 //! @param[in] t 矩形の上座標 void SetWithoutFlip( f32 l, f32 r, f32 b, f32 t ) { m_Height = t - b; m_AspectRatio = (r - l) / m_Height; m_Center = nw::math::VEC2( (r + l) / 2, (t + b) / 2 ); } //! @brief 左上、右下の座標で矩形を設定します。 //! この関数はバイナリから設定する場合と比較して b, t が反転しています。 //! バイナリと同様の設定を行うためには SetWithoutFlip() を用いてください。 //! //! @param[in] l 矩形の左座標 //! @param[in] r 矩形の右座標 //! @param[in] b 矩形の下座標 //! @param[in] t 矩形の上座標 void SetWithYFlip( f32 l, f32 r, f32 b, f32 t ) { m_Height = b - t; m_AspectRatio = (r - l) / m_Height; m_Center = nw::math::VEC2( (r + l) / 2, (b + t) / 2 ); } //! @brief 高さとアスペクト比で矩形を設定します。 //! //! @param[in] aspect アスペクト比です。 //! @param[in] height 高さです。 //! @param[in] center 中心座標です。 void Set( f32 aspect, f32 height, const nw::math::VEC2& center ) { m_Height = height; m_AspectRatio = aspect; m_Center = center; } //@} }; //! @details :private struct ResFrustumProjectionUpdaterData : public ResCameraProjectionUpdaterData { ResProjectionRect m_Rect; }; //! @details :private struct ResOrthoProjectionUpdaterData : public ResCameraProjectionUpdaterData { ResProjectionRect m_Rect; }; //! @details :private struct ResPerspectiveProjectionUpdaterData : public ResCameraProjectionUpdaterData { nw::ut::ResF32 m_AspectRatio; nw::ut::ResF32 m_Fovy; }; //-------------------------------------------------------------------------- //! @brief カメラビューアップデータリソースの基底クラスです。 //--------------------------------------------------------------------------- class ResCameraViewUpdater : public nw::ut::ResCommon< ResCameraViewUpdaterData > { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResCameraViewUpdater) }; NW_RES_CTOR( ResCameraViewUpdater ) //--------------------------------------------------------------------------- //! @brief インスタンスの型情報を取得します。 //! //! @return 型情報です。 //--------------------------------------------------------------------------- nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; } }; //-------------------------------------------------------------------------- //! @brief カメラプロジェクションアップデータリソースの基底クラスです。 //--------------------------------------------------------------------------- class ResCameraProjectionUpdater : public nw::ut::ResCommon< ResCameraProjectionUpdaterData > { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResCameraProjectionUpdater) }; NW_RES_CTOR( ResCameraProjectionUpdater ) //--------------------------------------------------------------------------- //! @fn void SetNear(f32 value) //! @brief ニアクリップの値を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetNear() const //! @brief ニアクリップの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( f32, Near ) // GetNear(), SetNear() //--------------------------------------------------------------------------- //! @fn void SetFar(f32 value) //! @brief ファークリップの値を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetFar() const //! @brief ファークリップの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( f32, Far ) // GetFar(), SetFar() //--------------------------------------------------------------------------- //! @brief インスタンスの型情報を取得します。 //! //! @return 型情報です。 //--------------------------------------------------------------------------- nw::ut::ResTypeInfo GetTypeInfo() const { return ref().typeInfo; } }; //-------------------------------------------------------------------------- //! @brief Aim カメラ用ビューアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResAimTargetViewUpdater : public ResCameraViewUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResAimTargetViewUpdater) }; NW_RES_CTOR_INHERIT( ResAimTargetViewUpdater, ResCameraViewUpdater ) //--------------------------------------------------------------------------- //! @fn void SetTwist(f32 value) //! @brief カメラの視線方向に対する回転角度を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetTargetPosition(f32 x, f32 y, f32 z) //! @brief 注視点の位置を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFlags(u32 value) //! @brief フラグの値を設定します。 //! 設定されなかったフラグは無効になります。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void EnaleFlags(u32 value) //! @brief 指定された Flag の値を有効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void DisableFlags(u32 value) //! @brief 指定された Flag の値を無効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetTwist() const //! @brief カメラの視線方向に対する回転角度を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const nw::math::VEC3 & GetTargetPosition() const //! @brief 注視点の位置を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFlags() const //! @brief フラグの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, TargetPosition ) // VEC3& GetTargetPosition() NW_RES_FIELD_PRIMITIVE_DECL( f32, Twist ) // GetTwist(), SetTwist() NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() }; //-------------------------------------------------------------------------- //! @brief LookAt カメラ用ビューアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResLookAtTargetViewUpdater : public ResCameraViewUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResLookAtTargetViewUpdater) }; NW_RES_CTOR_INHERIT( ResLookAtTargetViewUpdater, ResCameraViewUpdater ) //--------------------------------------------------------------------------- //! @fn void SetUpwardVector(f32 x, f32 y, f32 z) //! @brief カメラの上方向ベクトルを設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetTargetPosition(f32 x, f32 y, f32 z) //! @brief カメラの注視点の座標を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFlags(u32 value) //! @brief フラグの値を設定します。 //! 設定されなかったフラグは無効になります。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void EnaleFlags(u32 value) //! @brief 指定された Flag の値を有効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void DisableFlags(u32 value) //! @brief 指定された Flag の値を無効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const nw::math::VEC3 & GetUpwardVector() const //! @brief カメラの上方向ベクトルを取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const nw::math::VEC3 & GetTargetPosition() const //! @brief カメラの注視点の座標を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFlags() const //! @brief フラグの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, TargetPosition ) // VEC3& GetTargetPosition() NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, UpwardVector ) // VEC3& GetUpwardVector() NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() }; //-------------------------------------------------------------------------- //! @brief Rotate カメラ用ビューアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResRotateViewUpdater : public ResCameraViewUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResRotateViewUpdater) }; NW_RES_CTOR_INHERIT( ResRotateViewUpdater, ResCameraViewUpdater ) //--------------------------------------------------------------------------- //! @fn void SetViewRotate(f32 x, f32 y, f32 z) //! @brief カメラの回転量を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetFlags(u32 value) //! @brief フラグの値を設定します。 //! 設定されなかったフラグは無効になります。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void EnaleFlags(u32 value) //! @brief 指定された Flag の値を有効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void DisableFlags(u32 value) //! @brief 指定された Flag の値を無効にします。 //! 設定されなかったフラグは変更されません。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const nw::math::VEC3 & GetViewRotate() const //! @brief カメラの回転量を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn u32 GetFlags() const //! @brief フラグの値を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_VECTOR3_DECL( nw::math::VEC3, ViewRotate ) // VEC3& GetViewRotate() NW_RES_FIELD_FLAGS_DECL( u32, Flags ) // GetFlags(), SetFlags(), EnableFlags(), DisableFlags() }; //-------------------------------------------------------------------------- //! @brief Frustum 用プロジェクションアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResFrustumProjectionUpdater : public ResCameraProjectionUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResFrustumProjectionUpdater) }; NW_RES_CTOR_INHERIT( ResFrustumProjectionUpdater, ResCameraProjectionUpdater ) //--------------------------------------------------------------------------- //! @fn void SetRect(f32 l, f32 r, f32 b, f32 t) //! @brief 廃止予定となります。 //! SetRectWithYFlip() が以前と同等の挙動となります。 //! //! @sa SetRectWithoutFlip //! @sa SetRectWithYFlip //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetRectWithoutFlip(f32 l, f32 r, f32 b, f32 t) //! @brief 透視射影の近平面の矩形情報を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetRectWithYFlip(f32 l, f32 r, f32 b, f32 t) //! @brief 透視射影の近平面の矩形情報を設定します。 //! この関数はバイナリから設定する場合と比較して b, t が反転しています。 //! バイナリと同様の設定を行うためには SetRectWithoutFlip() を用いてください。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const ResProjectionRect & GetRect() const //! @brief 透視射影の近平面の矩形情報を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_RECT_DECL( ResProjectionRect, Rect ) // ResProjectionRect& GetRect() }; //-------------------------------------------------------------------------- //! @brief Ortho 用プロジェクションアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResOrthoProjectionUpdater : public ResCameraProjectionUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResOrthoProjectionUpdater) }; NW_RES_CTOR_INHERIT( ResOrthoProjectionUpdater, ResCameraProjectionUpdater ) //--------------------------------------------------------------------------- //! @fn void SetRect(f32 l, f32 r, f32 b, f32 t) //! @brief 廃止予定となります。 //! SetRectWithYFlip() が以前と同等の挙動となります。 //! //! @sa SetRectWithoutFlip //! @sa SetRectWithYFlip //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetRectWithoutFlip(f32 l, f32 r, f32 b, f32 t) //! @brief 透視射影の近平面の矩形情報を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetRectWithYFlip(f32 l, f32 r, f32 b, f32 t) //! @brief 透視射影の近平面の矩形情報を設定します。 //! この関数はバイナリから設定する場合と比較して b, t が反転しています。 //! バイナリと同様の設定を行うためには SetRectWithoutFlip() を用いてください。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn const ResProjectionRect & GetRect() const //! @brief 正射影の矩形情報を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_RECT_DECL( ResProjectionRect, Rect ) // ResProjectionRect& GetRect() }; //-------------------------------------------------------------------------- //! @brief Perspective 用プロジェクションアップデータのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResPerspectiveProjectionUpdater : public ResCameraProjectionUpdater { public: enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResPerspectiveProjectionUpdater) }; NW_RES_CTOR_INHERIT( ResPerspectiveProjectionUpdater, ResCameraProjectionUpdater ) //--------------------------------------------------------------------------- //! @fn void SetFovy(f32 value) //! @brief カメラの画角を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn void SetAspectRatio(f32 value) //! @brief アスペクト比を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetFovy() const //! @brief カメラの画角を取得します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetAspectRatio() const //! @brief アスペクト比を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( f32, AspectRatio ) // GetAspectRatio(), SetAspectRatio() NW_RES_FIELD_PRIMITIVE_DECL( f32, Fovy ) // GetFovy(), SetFovy() }; //-------------------------------------------------------------------------- //! @brief カメラのバイナリリソースクラスです。 //--------------------------------------------------------------------------- class ResCamera : public ResTransformNode { public: enum { BINARY_REVISION = REVISION_RES_CAMERA }; enum { TYPE_INFO = NW_GFX_RES_TYPE_INFO(ResCamera) }; //! @brief ビューアップデータの種類です。 enum ViewType { VIEWTYPE_AIM, //!< Aim ビューアップデータです。 VIEWTYPE_LOOKAT, //!< LookAt ビューアップデータです。 VIEWTYPE_ROTATE, //!< Rotate ビューアップデータです。 VIEWTYPE_COUNT //!< enum の最大値です。 }; //! @brief プロジェクションアップデータの種類です。 enum ProjType { PROJTYPE_PERSPECTIVE, //!< Perspective プロジェクションアップデータです。 PROJTYPE_FRUSTUM, //!< Frustum プロジェクションアップデータです。 PROJTYPE_ORTHO, //!< Ortho プロジェクションアップデータです。 PROJTYPE_COUNT //!< enum の最大値です。 }; NW_RES_CTOR_INHERIT( ResCamera, ResTransformNode ) //--------------------------------------------------------------------------- //! @fn void SetViewType(ViewType value) //! @brief ビューカメラアップデータのタイプを設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ViewType GetViewType() const //! @brief ビューカメラアップデータのタイプを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( ViewType, ViewType ) // GetViewType() //--------------------------------------------------------------------------- //! @fn void SetProjectionType(ProjType value) //! @brief プロジェクションカメラアップデータのタイプを設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn ProjType GetProjectionType() const //! @brief プロジェクションカメラアップデータのタイプを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( ProjType, ProjectionType ) // GetProjectionType() //--------------------------------------------------------------------------- //! @fn ResCameraViewUpdater GetViewUpdater() //! @brief ビュー行列のアップデータを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_CLASS_DECL( ResCameraViewUpdater, ViewUpdater ) // GetViewUpdater() //--------------------------------------------------------------------------- //! @fn ResCameraProjectionUpdater GetProjectionUpdater() //! @brief 射影行列のアップデータを取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_CLASS_DECL( ResCameraProjectionUpdater, ProjectionUpdater ) // GetProjectionUpdater() //--------------------------------------------------------------------------- //! @fn void SetWScale(f32 value) //! @brief Wバッファのスケール因子を設定します。 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //! @fn f32 GetWScale() const //! @brief Wバッファのスケール因子を取得します。 //--------------------------------------------------------------------------- NW_RES_FIELD_PRIMITIVE_DECL( f32, WScale ) // GetWScale() //--------------------------------------------------------------------------- //! @brief リビジョンを取得します。 //! //! @return リソースのリビジョン情報です。 //--------------------------------------------------------------------------- u32 GetRevision() const { return this->GetHeader().revision; } }; typedef nw::ut::ResArrayPatricia::type ResCameraArray; } // namespace res } // namespace gfx } // namespace nw #endif // NW_GFX_RESCAMERA_H_