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