/*---------------------------------------------------------------------------* Project: NintendoWare File: SmRectCollision.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #ifndef SM_RECT_COLLISION_H_ #define SM_RECT_COLLISION_H_ #include //------------------------------------------------------------------------------ // 矩形コリジョン class SmRectCollision { public: // コンストラクタ SmRectCollision() { SetRect( 0.f, 0.f, 0.f, 0.f ); } // デストラクタ ~SmRectCollision(){} // 矩形を設定 void SetRect( f32 x, f32 y, f32 w, f32 h ) { m_Collision.SetOriginAndSize( x, y, w, h ); } void SetRect( nw::ut::Rect& rect ) { m_Collision = rect; } // コリジョン範囲内チェック bool CheckInner( u16 x, u16 y ) { f32 posx = static_cast(x); f32 posy = static_cast(y); f32 colx = m_Collision.GetX(); f32 coly = m_Collision.GetY(); f32 colw = m_Collision.GetWidth(); f32 colh = m_Collision.GetHeight(); if ( colx < posx ) { if ( posx < colx + colw ) { if ( coly < posy ) { if ( posy < coly + colh ) { return true; } } } } return false; } // 位置を設定 void SetXY( f32 x, f32 y ) { m_Collision.MoveTo( x, y ); } // 位置を加算 void AddXY( f32 x, f32 y ) { m_Collision.left += x; m_Collision.top += x; m_Collision.right += y; m_Collision.bottom += y; } // 位置を取得します。 f32 GetX() const { return m_Collision.GetX(); } f32 GetY() const { return m_Collision.GetY(); } // 縦/幅を取得します。 f32 GetWidth() const { return m_Collision.GetWidth(); } f32 GetHeight() const { return m_Collision.GetHeight(); } // レイアウトの矩形を設定 void SetLytRect( nw::ut::Rect& rect ) { m_Collision.left = rect.left; m_Collision.top = -rect.top; m_Collision.right = rect.right; m_Collision.bottom = -rect.bottom; } nw::ut::Rect m_Collision; }; #endif // SM_RECT_COLLISION_H_