SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Member Functions | Public Attributes | List of all members
SDX::Rect Class Reference

矩形を表す図形クラス. More...

#include <Rect.h>

Inherits SDX::IShape.

Public Member Functions

 Rect (double X座標, double Y座標, double 横幅A, double 高さA, double 横幅B=0, double 高さB=0)
 座標と大きさを指定. More...
 
template<class T1 , class T2 , class T3 , class T4 >
 Rect (T1 X座標, T2 Y座標, T3 横幅A, T4 高さA, T3 横幅B=0, T4 高さB=0)
 座標と大きさを指定. More...
 
virtual IShapeClone (double X座標, double Y座標) const override
 同じ形の図形を作る. More...
 
void SetPos (double X座標, double Y座標) override
 指定座標に移動. More...
 
void Move (double X移動量, double Y移動量) override
 相対座標で移動. More...
 
void MultiZoom (double X倍率, double Y倍率) override
 縦横別で拡大率を掛け算する. More...
 
void Rotate (double 回転する角度) override
 回転する. More...
 
void Draw (const Color &描画色) const override
 描画する. More...
 
double GetX () const override
 X座標を取得. More...
 
double GetY () const override
 Y座標を取得. More...
 
double GetW () const override
 幅を取得. More...
 
double GetH () const override
 高さを取得. More...
 
double GetLeft () const
 左端のX座標を取得. More...
 
double GetTop () const
 上端のY座標を取得. More...
 
double GetRight () const
 右端のX座標を取得. More...
 
double GetBottom () const
 下端のY座標を取得. More...
 
bool Hit (const IShape *shape) const override
 衝突判定. More...
 
bool Hit (const Complex *complex) const override
 衝突判定. More...
 
bool Hit (const Point *point) const override
 衝突判定. More...
 
bool Hit (const Line *line) const override
 衝突判定. More...
 
bool Hit (const Rect *rect) const override
 衝突判定. More...
 
bool Hit (const Circle *circle) const override
 衝突判定. More...
 
Point GetPoint () const
 Pointを取得. More...
 
Point GetCenter () const
 
 operator SDL_Rect () const
 SDL_Rectに型変換. More...
 
Rect operator+ (Point &加算値) const
 座標に加算. More...
 
- Public Member Functions inherited from SDX::IPosition
void SetZoom (double X拡大率, double Y拡大率)
 拡大率を設定. More...
 
void MultiZoom (double 倍率)
 拡大率を掛け算する. More...
 
void MoveA (double 距離, double 方向)
 極座標で移動. More...
 
void MoveF (double 距離)
 前方に移動. More...
 
virtual double GetAngle () const
 角度を取得する. More...
 
void SetAngle (double 指定角度)
 角度を指定する. More...
 
double GetDirect (IPosition *比較対象) const
 対象との角度を取得. More...
 
double GetDistance (const IPosition *比較対象) const
 対象との相対座標を取得. More...
 
virtual void SetZoom (double X拡大率, double Y拡大率)
 拡大率を設定. More...
 
void MultiZoom (double 倍率)
 拡大率を掛け算する. More...
 
void MoveA (double 距離, double 方向)
 極座標で移動. More...
 
virtual double GetAngle () const
 角度を取得する. More...
 
virtual void SetAngle (double 指定角度)
 角度を指定する. More...
 
double GetDirect (IPosition *比較対象) const
 対象との角度を取得. More...
 
double GetDistance (IPosition *比較対象) const
 対象との相対座標を取得. More...
 
double CompareAngle (double 角度)
 角度の差を計算する
 

Public Attributes

double x = 0
 起点座標
 
double y = 0
 起点座標
 
double widthLeft = 0
 起点から左側の幅
 
double widthRight = 0
 起点から右側の幅
 
double heightUp = 0
 起点から上側の幅
 
double heightDown = 0
 起点から下側の幅
 

Additional Inherited Members

- Static Protected Member Functions inherited from SDX::IShape
static bool RectRect (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 矩形の交差判定. More...
 
static bool LineLine (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
 線分の交差判定. More...
 
static int PointPoint (double x1, double y1, double x2, double y2)
 二点間の距離を計算. More...
 
- Protected Attributes inherited from SDX::IPosition
double zoomX = 1
 図形の拡大率
 
double zoomY = 1
 図形の拡大率
 

Detailed Description

矩形を表す図形クラス.

//Copyright © 2014 SDXFramework
//[License]GNU Affero General Public License, version 3
//[Contact]http://sourceforge.jp/projects/dxframework/
//図形の当たり判定をする
#include <SDXFramework.h>
bool SampleShape()
{
using namespace SDX;
System::Initialise("sample", 640, 480);
//図形を宣言する
Circle circle(10, 10, 100);
Rect rect(60, 60, 100, 100);
Line line(200, 100, PAI / 4, 600, 5);
//共通のインターフェースを持っている
IShape* shapes[3];
shapes[0] = &circle;
shapes[1] = &rect;
shapes[2] = &line;
while (System::Update())
{
//Lineは回転可能
line.Rotate(0.01);
//ダブルディスパッチによる当たり判定
for (int a = 0; a < 3; ++a)
{
int hit = 0;
for (int b = 0; b < 3; ++b)
{
if (a == b){ continue; }
hit += shapes[a]->Hit(shapes[b]);
}
if ( hit == 0)
{
shapes[a]->Draw(Color::White);
}
else if (hit == 1)
{
shapes[a]->Draw(Color::Red);
}
else
{
shapes[a]->Draw(Color::Blue);
}
}
if (Input::key.Return.on){ break;}//Enterで終了
}
return true;
}

Constructor & Destructor Documentation

SDX::Rect::Rect ( double  X座標,
double  Y座標,
double  横幅A,
double  高さA,
double  横幅B = 0,
double  高さB = 0 
)
inline

座標と大きさを指定.

デフォルト引数だと左上座標と大きさを指定 横幅A=横幅B,高さA=高さBとすると中心座標指定になる

template<class T1 , class T2 , class T3 , class T4 >
SDX::Rect::Rect ( T1  X座標,
T2  Y座標,
T3  横幅A,
T4  高さA,
T3  横幅B = 0,
T4  高さB = 0 
)
inline

座標と大きさを指定.

デフォルト引数だと左上座標と大きさを指定 横幅A=横幅B,高さA=高さBとすると中心座標指定になる

Member Function Documentation

virtual IShape* SDX::Rect::Clone ( double  x,
double  y 
) const
inlineoverridevirtual

同じ形の図形を作る.

Implements SDX::IShape.

void SDX::Rect::SetPos ( double  X座標,
double  Y座標 
)
inlineoverridevirtual

指定座標に移動.

Implements SDX::IPosition.

void SDX::Rect::Move ( double  X移動量,
double  Y移動量 
)
inlineoverridevirtual

相対座標で移動.

Implements SDX::IPosition.

void SDX::Rect::MultiZoom ( double  X倍率,
double  Y倍率 
)
inlineoverridevirtual

縦横別で拡大率を掛け算する.

Implements SDX::IPosition.

void SDX::Rect::Rotate ( double  回転する角度)
inlineoverridevirtual

回転する.

Implements SDX::IPosition.

void SDX::Rect::Draw ( const Color 描画色) const
overridevirtual

描画する.

Implements SDX::IShape.

double SDX::Rect::GetX ( ) const
inlineoverridevirtual

X座標を取得.

Implements SDX::IPosition.

double SDX::Rect::GetY ( ) const
inlineoverridevirtual

Y座標を取得.

Implements SDX::IPosition.

double SDX::Rect::GetW ( ) const
inlineoverridevirtual

幅を取得.

Implements SDX::IPosition.

double SDX::Rect::GetH ( ) const
inlineoverridevirtual

高さを取得.

Implements SDX::IPosition.

double SDX::Rect::GetLeft ( ) const
inline

左端のX座標を取得.

double SDX::Rect::GetTop ( ) const
inline

上端のY座標を取得.

double SDX::Rect::GetRight ( ) const
inline

右端のX座標を取得.

double SDX::Rect::GetBottom ( ) const
inline

下端のY座標を取得.

bool SDX::Rect::Hit ( const IShape iShape) const
inlineoverridevirtual

衝突判定.

Implements SDX::IShape.

bool SDX::Rect::Hit ( const Complex complex) const
inlineoverridevirtual

衝突判定.

Implements SDX::IShape.

bool SDX::Rect::Hit ( const Point point) const
inlineoverridevirtual

衝突判定.

Implements SDX::IShape.

bool SDX::Rect::Hit ( const Line line) const
inlineoverridevirtual

衝突判定.

Implements SDX::IShape.

bool SDX::Rect::Hit ( const Rect rect) const
inlineoverridevirtual

衝突判定.

Implements SDX::IShape.

bool SDX::Rect::Hit ( const Circle circle) const
overridevirtual

衝突判定.

Implements SDX::IShape.

Point SDX::Rect::GetPoint ( ) const
inline

Pointを取得.

SDX::Rect::operator SDL_Rect ( ) const
inline

SDL_Rectに型変換.

Rect SDX::Rect::operator+ ( Point 加算値) const
inline

座標に加算.