/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_CameraController.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:$ *---------------------------------------------------------------------------*/ #ifndef NW_DEMO_CAMERA_H_ #define NW_DEMO_CAMERA_H_ #include #include #include // NW4Rのデモカメラ(demos\g3d\demolib内のcamera.cpp/h)を参考に実装しています。 namespace nw { namespace os { class IAllocator; } // namespace os namespace demo { //! @brief パッドでカメラを操作するための制御クラスです。 // アナログスティックのみで回転を、 // アナログスティック+Aボタンで前後に、Bボタンで上下左右に移動をさせることができます。 // Xボタンを押すとカメラ位置が初期状態に戻ります。 class CameraController { private: NW_DISALLOW_COPY_AND_ASSIGN(CameraController); public: //! @brief 制御クラスの設定内容です。 struct Description { size_t maxCameraCount; //!< 登録できるカメラの最大数です //! @brief コンストラクタです。 Description() : maxCameraCount(MAX_CAMERA_COUNT) {} }; //! @brief 制御クラスを構築するためのクラスです。 class Builder { public: //! @brief 構築する制御クラスを設定します。 Builder& CameraDescription(const Description& description) { m_Description = description; return *this; } //! @brief 登録できるカメラの最大数を設定します。 Builder& MaxCameraCount(size_t count) { m_Description.maxCameraCount = count; return *this; } //--------------------------------------------------------------------------- //! @brief 制御クラスを生成します。 //! //! 先にnw::demo::PadFactory::Initialize()を実行しておく必要があります。 //! //! @param[in] allocator 制御クラスで使用するアロケータです。 //--------------------------------------------------------------------------- CameraController* Create(os::IAllocator* allocator); private: Description m_Description; }; //! @brief 制御クラスを削除します。 void Destroy(); //--------------------------------------------------------------------------- //! @brief UpdateCamera を反映させる対象のカメラを登録します。 //! //! 登録時のカメラの位置と姿勢は保存され、コントローラのXボタンを押すことで //! 元に戻すことができます。 //! //! @param[in] camera UpdateCamera の反映先となるカメラへのポインタです。 //! @param[in] cameraIndex カメラの登録番号です。 0以上maxCameraCount未満でなければなりません。 //--------------------------------------------------------------------------- void Register(nw::gfx::Camera* camera, unsigned int cameraIndex = 0); //--------------------------------------------------------------------------- //! @brief パッド入力に応じて指定したカメラの状態を更新します。 //! //! @param[in] cameraIndex RegisterCameraで指定したカメラの登録番号です。 //--------------------------------------------------------------------------- void Update(unsigned int cameraIndex = 0); private: //! @brief 登録できるカメラ最大数のデフォルト値です。 static const size_t MAX_CAMERA_COUNT = 10; //! @brief コンストラクタです。 CameraController( os::IAllocator* allocator, const Description& description); ~CameraController(); //! @brief カメラのViewUpdaterとTransformを実際に更新するクラスです。 class CameraEntry { public: CameraEntry(nw::gfx::Camera* camera); ~CameraEntry() {}; //! @brief コントローラの状態からカメラの位置と姿勢を更新します void Update(); private: //! @brief 登録されたカメラのViewUpdaterとTransformを更新します。 void UpdateCamera(); nw::math::VEC3 m_Rotate; nw::math::VEC3 m_TargetPos; f32 m_TargetDistance; nw::gfx::Camera* m_Camera; nw::math::VEC3 m_InitialRotate; nw::math::VEC3 m_InitialTargetPos; f32 m_InitialTargetDistance; //! @brief 距離の変更速度です。 static const f32 DOLLY_SPEED_BASE; //! @brief 回転速度です。 static const f32 TUMBLE_SPEED; //! @brief カメラの平行移動速度です。 static const f32 MOVE_SPEED_BASE; //! @brief X軸回転速度の制限です。 static const f32 ROTATE_X_LIMIT; //! @brief 距離の初期値です。 //! 登録されたカメラがRotateViewUpdaterを使用していた場合に適用されます。 static const f32 DEFAULT_DISTANCE; }; nw::os::IAllocator* m_Allocator; Description m_Description; nw::ut::MoveArray m_CameraEntries; bool m_UsagePrinted; }; } // namespace nw::demo } // namespace nw #endif /* NW_DEMO_CAMERA_H_ */