1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: demo_CameraController.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision:$ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_DEMO_CAMERA_H_ 17 #define NW_DEMO_CAMERA_H_ 18 19 #include <nw/gfx.h> 20 21 #include <nw/ut/ut_MoveArray.h> 22 #include <nw/ut/ut_Preprocessor.h> 23 24 // NW4Rのデモカメラ(demos\g3d\demolib内のcamera.cpp/h)を参考に実装しています。 25 26 namespace nw { 27 namespace os 28 { 29 class IAllocator; 30 } // namespace os 31 32 namespace demo { 33 34 //! @brief パッドでカメラを操作するための制御クラスです。 35 // アナログスティックのみで回転を、 36 // アナログスティック+Aボタンで前後に、Bボタンで上下左右に移動をさせることができます。 37 // Xボタンを押すとカメラ位置が初期状態に戻ります。 38 39 class CameraController 40 { 41 private: 42 NW_DISALLOW_COPY_AND_ASSIGN(CameraController); 43 44 public: 45 //! @brief 制御クラスの設定内容です。 46 struct Description 47 { 48 size_t maxCameraCount; //!< 登録できるカメラの最大数です 49 50 //! @brief コンストラクタです。 DescriptionDescription51 Description() 52 : maxCameraCount(MAX_CAMERA_COUNT) 53 {} 54 }; 55 56 //! @brief 制御クラスを構築するためのクラスです。 57 class Builder 58 { 59 public: 60 //! @brief 構築する制御クラスを設定します。 CameraDescription(const Description & description)61 Builder& CameraDescription(const Description& description) 62 { 63 m_Description = description; 64 return *this; 65 } 66 67 //! @brief 登録できるカメラの最大数を設定します。 MaxCameraCount(size_t count)68 Builder& MaxCameraCount(size_t count) 69 { 70 m_Description.maxCameraCount = count; 71 return *this; 72 } 73 74 //--------------------------------------------------------------------------- 75 //! @brief 制御クラスを生成します。 76 //! 77 //! 先にnw::demo::PadFactory::Initialize()を実行しておく必要があります。 78 //! 79 //! @param[in] allocator 制御クラスで使用するアロケータです。 80 //--------------------------------------------------------------------------- 81 CameraController* Create(os::IAllocator* allocator); 82 83 private: 84 Description m_Description; 85 }; 86 87 //! @brief 制御クラスを削除します。 88 void Destroy(); 89 90 //--------------------------------------------------------------------------- 91 //! @brief UpdateCamera を反映させる対象のカメラを登録します。 92 //! 93 //! 登録時のカメラの位置と姿勢は保存され、コントローラのXボタンを押すことで 94 //! 元に戻すことができます。 95 //! 96 //! @param[in] camera UpdateCamera の反映先となるカメラへのポインタです。 97 //! @param[in] cameraIndex カメラの登録番号です。 0以上maxCameraCount未満でなければなりません。 98 //--------------------------------------------------------------------------- 99 void Register(nw::gfx::Camera* camera, unsigned int cameraIndex = 0); 100 101 //--------------------------------------------------------------------------- 102 //! @brief パッド入力に応じて指定したカメラの状態を更新します。 103 //! 104 //! @param[in] cameraIndex RegisterCameraで指定したカメラの登録番号です。 105 //--------------------------------------------------------------------------- 106 void Update(unsigned int cameraIndex = 0); 107 108 private: 109 //! @brief 登録できるカメラ最大数のデフォルト値です。 110 static const size_t MAX_CAMERA_COUNT = 10; 111 112 //! @brief コンストラクタです。 113 CameraController( 114 os::IAllocator* allocator, 115 const Description& description); 116 117 ~CameraController(); 118 119 //! @brief カメラのViewUpdaterとTransformを実際に更新するクラスです。 120 class CameraEntry 121 { 122 public: 123 CameraEntry(nw::gfx::Camera* camera); 124 ~CameraEntry()125 ~CameraEntry() {}; 126 127 //! @brief コントローラの状態からカメラの位置と姿勢を更新します 128 void Update(); 129 130 private: 131 //! @brief 登録されたカメラのViewUpdaterとTransformを更新します。 132 void UpdateCamera(); 133 134 nw::math::VEC3 m_Rotate; 135 nw::math::VEC3 m_TargetPos; 136 f32 m_TargetDistance; 137 nw::gfx::Camera* m_Camera; 138 139 nw::math::VEC3 m_InitialRotate; 140 nw::math::VEC3 m_InitialTargetPos; 141 f32 m_InitialTargetDistance; 142 143 //! @brief 距離の変更速度です。 144 static const f32 DOLLY_SPEED_BASE; 145 //! @brief 回転速度です。 146 static const f32 TUMBLE_SPEED; 147 //! @brief カメラの平行移動速度です。 148 static const f32 MOVE_SPEED_BASE; 149 //! @brief X軸回転速度の制限です。 150 static const f32 ROTATE_X_LIMIT; 151 152 //! @brief 距離の初期値です。 153 //! 登録されたカメラがRotateViewUpdaterを使用していた場合に適用されます。 154 static const f32 DEFAULT_DISTANCE; 155 }; 156 157 nw::os::IAllocator* m_Allocator; 158 Description m_Description; 159 160 nw::ut::MoveArray<CameraEntry*> m_CameraEntries; 161 162 bool m_UsagePrinted; 163 }; 164 165 } // namespace nw::demo 166 } // namespace nw 167 168 #endif /* NW_DEMO_CAMERA_H_ */ 169 170