1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmRectCollision.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_RECT_COLLISION_H_ 18 #define SM_RECT_COLLISION_H_ 19 20 #include <nw/ut.h> 21 22 //------------------------------------------------------------------------------ 23 // ��`�R���W���� 24 class SmRectCollision 25 { 26 public: 27 // �R���X�g���N�^ SmRectCollision()28 SmRectCollision() 29 { 30 SetRect( 0.f, 0.f, 0.f, 0.f ); 31 } 32 33 // �f�X�g���N�^ ~SmRectCollision()34 ~SmRectCollision(){} 35 36 // ��`��ݒ� SetRect(f32 x,f32 y,f32 w,f32 h)37 void SetRect( f32 x, f32 y, f32 w, f32 h ) 38 { 39 m_Collision.SetOriginAndSize( x, y, w, h ); 40 } SetRect(nw::ut::Rect & rect)41 void SetRect( nw::ut::Rect& rect ) 42 { 43 m_Collision = rect; 44 } 45 46 // �R���W�����͈͓��`�F�b�N CheckInner(u16 x,u16 y)47 bool CheckInner( u16 x, u16 y ) 48 { 49 f32 posx = static_cast<f32>(x); 50 f32 posy = static_cast<f32>(y); 51 52 f32 colx = m_Collision.GetX(); 53 f32 coly = m_Collision.GetY(); 54 55 f32 colw = m_Collision.GetWidth(); 56 f32 colh = m_Collision.GetHeight(); 57 58 59 if ( colx < posx ) 60 { 61 if ( posx < colx + colw ) 62 { 63 if ( coly < posy ) 64 { 65 if ( posy < coly + colh ) 66 { 67 return true; 68 } 69 } 70 } 71 } 72 return false; 73 } 74 75 // �ʒu��ݒ� SetXY(f32 x,f32 y)76 void SetXY( f32 x, f32 y ) 77 { 78 m_Collision.MoveTo( x, y ); 79 } 80 81 // �ʒu�����Z AddXY(f32 x,f32 y)82 void AddXY( f32 x, f32 y ) 83 { 84 m_Collision.left += x; 85 m_Collision.top += x; 86 m_Collision.right += y; 87 m_Collision.bottom += y; 88 } 89 90 // �ʒu���擾���܂��B GetX()91 f32 GetX() const { return m_Collision.GetX(); } GetY()92 f32 GetY() const { return m_Collision.GetY(); } 93 94 95 // �c/�����擾���܂��B GetWidth()96 f32 GetWidth() const { return m_Collision.GetWidth(); } GetHeight()97 f32 GetHeight() const { return m_Collision.GetHeight(); } 98 99 100 // ���C�A�E�g�̋�`��ݒ� SetLytRect(nw::ut::Rect & rect)101 void SetLytRect( nw::ut::Rect& rect ) 102 { 103 m_Collision.left = rect.left; 104 m_Collision.top = -rect.top; 105 m_Collision.right = rect.right; 106 m_Collision.bottom = -rect.bottom; 107 } 108 109 nw::ut::Rect m_Collision; 110 }; 111 112 #endif // SM_RECT_COLLISION_H_ 113