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