1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     SmCamera.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 #ifndef SM_CAMERA_H_
18 #define SM_CAMERA_H_
19 
20 #include <nw/gfx.h>
21 #include "../include/SmMessage.h"
22 #include "../include/SmPadStatus.h"
23 #include "../include/SmRectCollision.h"
24 #include "../include/SmTouchPanelStatus.h"
25 
26 //------------------------------------------------------------------------------
27 // �J�������\����
28 // Viewer����q�؂��܂����B
29 struct CameraInfo
30 {
31 /*
32     float           AspectRatio;
33     float           Height;
34     float           Rotate;
35     float           Twist;*/
36 
37     float           Near;
38     float           Far;
39     float           Fovy;
40     nw::math::VEC3  Position;
41     nw::math::VEC3  TargetPos;
42     nw::math::VEC3  UpVector;
43 
44 
45     float           RotationInit;
46     float           RotationStep;
47     float           RotationMax;
48     float           TranslationInit;
49     float           TranslationStep;
50     float           TranslationMax;
51     float           TiltInit;
52     float           DollyInit;
53 
54     bool            TumbleXInverse;
55     bool            TumbleYInverse;
56     bool            TrackXInverse;
57     bool            TrackYInverse;
58     bool            DollyInverse;
59     bool            DollyTargetInverse;
60     bool            TiltXInverse;
61     bool            TiltYInverse;
62     CameraInfo();
63 };
64 
65 
66 
67 //------------------------------------------------------------------------------
68 // �J�����N���X
69 class SmCamera : public SmMessage
70 {
71     friend class GfxCtrl;
72 
73 private:
74     // �R���X�g���N�^
75     SmCamera( nw::gfx::SceneNode* parent, nw::gfx::Camera* camera );
76 
77     // �f�X�g���N�^
78     ~SmCamera();
79 
80 public:
81     // �J�����A�j���[�V�����z��
82     #define ANIM_COUNT (32)
83     typedef nw::ut::FixedSizeArray<nw::gfx::AnimEvaluator*, ANIM_COUNT> CameraAnimEvaluatorArray;
84 
85     // ���_�Z�b�g
SetPosition(nw::math::VEC3 * position)86     void SetPosition( nw::math::VEC3* position )
87     {
88         NW_NULL_ASSERT( position );
89         NW_NULL_ASSERT( m_Camera );
90 
91         // ���_
92         m_Position = *position;
93         m_Camera->Transform().SetTranslate( m_Position );
94     }
95 
SetPadCameraPosition(nw::math::VEC3 * position)96     void SetPadCameraPosition( nw::math::VEC3* position )
97     {
98         NW_NULL_ASSERT( position );
99         NW_NULL_ASSERT( m_PadCamera );
100         m_PadCamera->Transform().SetTranslate( *position );
101     }
102 
103 
104 
105     // ���_�擾
GetPosition(nw::math::VEC3 * position)106     void GetPosition( nw::math::VEC3* position )
107     {
108         NW_NULL_ASSERT( position );
109         *position = m_Position;
110     }
111 
112     // �����_���Z�b�g
SetTarget(nw::math::VEC3 * target)113     void SetTarget( nw::math::VEC3* target )
114     {
115         NW_NULL_ASSERT( target );
116         NW_NULL_ASSERT( m_Camera );
117 
118         m_Target = *target;
119 
120         nw::gfx::ResCameraViewUpdater resViewUpdater = m_Camera->GetViewUpdater()->GetResource();
121         nw::gfx::ResAimTargetViewUpdater resAimTargetViewUpdater =
122             nw::gfx::ResDynamicCast<nw::gfx::ResAimTargetViewUpdater>(resViewUpdater);
123         nw::gfx::ResLookAtTargetViewUpdater resLookAtTargetViewUpdater =
124             nw::gfx::ResDynamicCast<nw::gfx::ResLookAtTargetViewUpdater>(resViewUpdater);
125         nw::gfx::ResRotateViewUpdater resRotateViewUpdater =
126             nw::gfx::ResDynamicCast<nw::gfx::ResRotateViewUpdater>(resViewUpdater);
127 
128         // �����_��ێ�
129         if (resAimTargetViewUpdater.IsValid())
130         {
131             resAimTargetViewUpdater.SetTargetPosition( m_Target );
132         }
133         else if (resLookAtTargetViewUpdater.IsValid())
134         {
135             resLookAtTargetViewUpdater.SetTargetPosition( m_Target );
136         }
137         else if (resRotateViewUpdater.IsValid())
138         {
139             //
140             NW_FATAL_ERROR("Unxxxxx type of resource view updater");
141         }
142         else
143         {
144             NW_FATAL_ERROR("Invalid type of resource view updater");
145         }
146     }
147 
SetPadCameraTarget(nw::math::VEC3 * target)148     void SetPadCameraTarget( nw::math::VEC3* target )
149     {
150         NW_NULL_ASSERT( m_PadCamera );
151 
152         nw::gfx::LookAtTargetViewUpdater* viewUpdater =
153             nw::ut::DynamicCast<nw::gfx::LookAtTargetViewUpdater*>(m_PadCamera->GetViewUpdater());
154         nw::gfx::ResLookAtTargetViewUpdater resViewUpdater =
155             nw::gfx::ResStaticCast<nw::gfx::ResLookAtTargetViewUpdater>(viewUpdater->GetResource());
156 
157        resViewUpdater.SetTargetPosition(*target);
158     }
159 
160     // �����_���擾
GetTarget(nw::math::VEC3 * target)161     void GetTarget( nw::math::VEC3* target )
162     {
163         NW_NULL_ASSERT( target );
164         *target = m_Target;
165     }
166 
167     // �J�����Z�b�g
168     void SetGxCamera( nw::gfx::Camera* camera );
169 
170     // �J�������擾���܂��B
171     nw::gfx::Camera* GetGxCamera();
172 
GetBaseCamera()173     nw::gfx::Camera* GetBaseCamera()
174     {
175         return m_Camera;
176     }
177 
GetPadCamera()178     nw::gfx::Camera* GetPadCamera()
179     {
180         return m_PadCamera;
181     }
182 
IsPadCamera()183     bool IsPadCamera()
184     {
185         return m_PadCameraAttached;
186     }
187 
188     /*
189         �A�j���[�V�����@�\
190     */
191     // �A�j���[�V������lj�����
192     void AddAnimEvaluator( nw::gfx::AnimEvaluator* animEvaluator );
193 
194     // �A�j���[�V���������擾����
195     uint GetAnimEvaluatorNum() const;
196 
197     // �A�j���[�V�����ݒ��������
198     bool DetachAnimEvaluator();
199 
200     // �A�j���[�V������ݒ肷��
201     bool SetAnimEvaluatorNo( uint animEvaluatorNo );
202 
203     // �A�j���[�V�����t���[����ݒ肷��
204     void SetAnimationFrame( f32 setFrame );
205 
206     // �A�j���[�V�����t���[����i�߂�
207     bool AddAnimationFrame( f32 addFrame, bool loop = true );
208 
209     // �A�j���[�V�����t���[�����擾����
210     f32 GetAnimationFrame() const;
211 
212     // ���b�Z�[�W��M
213     virtual bool ReceveMessage( SmMessageType type, void* object, uint targetId );
214 
215     // Viewer�Ɠ��J��������
216     void MoveCamera3D( SmPadStatus* padStaus, SmTouchPanelStatus* panelStatus );
217 
218     // �J�����}�g���N�X���X�V����
219     void UpdateMatrix();
220 
221 private:
222     nw::gfx::SceneNode*         m_Parent;
223     nw::gfx::Camera*            m_Camera;
224     nw::gfx::Camera*            m_PadCamera;
225     bool                        m_PadCameraAttached;
226 
227     nw::math::VEC3              m_Position;
228     nw::math::VEC3              m_Target;
229 
230     bool                        m_IsAnimPlaying;
231     f32                         m_AnimationFrame;
232     s32                         m_CurrentAnimEvNo;
233     CameraAnimEvaluatorArray    m_CameraAnimEvaluatorArray;
234 
235     f32                         mRotation;
236     f32                         mTranslation;
237     CameraInfo                  mCameraInfo;
238     s32                         mTouchPanelX;
239     s32                         mTouchPanelY;
240 
241     bool                        m_IsGrab;
242     SmRectCollision             m_Collision;
243 };
244 
245 
246 #endif  // SM_CAMERA_H_
247