SDXFrameWork 0.09 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
IShape .h
1 #pragma once//©SDXFramework http://sourceforge.jp/projects/dxframework/
2 //#include <Framework/Camera.h>
3 #include <vector>
4 #include <algorithm>
5
6 namespace SDX
7 {
8 class Complex;
9 class Point;
10 class Line;
11 class Circle;
12 class Rect;
13
14 class Camera;
15 class Color;
18 class IShape
19 {
20 protected:
21 double zoomX;
22 double zoomY;
23
25 static bool RectRect( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
26 {
27 //x座標をラフチェック
28 if ( x1 >= x2)
29 {
30 if ((x1 < x3 && x1 < x4) || (x2 > x3 && x2 > x4))
31 {
32 return false;
33 }
34 }
35 else
36 {
37 if ((x2 < x3 && x2 < x4) || (x1 > x3 && x1 > x4))
38 {
39 return false;
40 }
41 }
42 //y座標をラフチェック
43 if (y1 >= y2)
44 {
45 if ((y1 < y3 && y1 < y4) || (y2 > y3 && y2 > y4))
46 {
47 return false;
48 }
49 }
50 else
51 {
52 if ((y2 < y3 && y2 < y4) || (y1 > y3 && y1 > y4))
53 {
54 return false;
55 }
56 }
57
58 return true;
59 }
60
62 static bool LineLine( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
63 {
64 //交差判定
65 if ((double(x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
66 (double(x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0)
67 {
68 return false;
69 }
70
71 if ((double(x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)) *
72 (double(x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)) > 0)
73 {
74 return false;
75 }
76 return true;
77
78 }
79
81 static int PointPoint(double x1 , double y1 , double x2 , double y2)
82 {
83 return int((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
84 }
85
86 public:
87 IShape():
88 zoomX(1),
89 zoomY(1)
90 {}
91
93 virtual bool Hit(const IShape *IShape) const = 0;
94 virtual bool Hit(const Complex *complex) const = 0;
95 virtual bool Hit(const Point *point) const = 0;
96 virtual bool Hit(const Line *line) const = 0;
97 virtual bool Hit(const Rect *rect) const = 0;
98 virtual bool Hit(const Circle *circle) const = 0;
99
101 virtual void SetPos(double X座標 , double Y座標) = 0;
102
104 virtual IShape* Clone(double x , double y) const = 0;
105
107 void SetZoom(double X拡大率 , double Y拡大率)
108 {
109 MultiZoom( X拡大率 / zoomX , Y拡大率 / zoomY);
110 }
111
113 void MultiZoom(double 倍率)
114 {
115 MultiZoom(倍率,倍率);
116 }
117
119 virtual void MultiZoom(double X倍率 , double Y倍率) = 0;
120
122 virtual void Move(double X移動量 , double Y移動量) = 0;
123
125 void MoveA(double 距離 , double 方向 )
126 {
127 Move( 距離 * cos(方向) , 距離 * sin(方向) );
128 }
129
131 virtual void Draw(Color 描画色 , int 透過率 , Camera *座標変換Camera = nullptr) const = 0;
132
134 virtual void Rotate(double 回転する角度) = 0;
135
137 virtual void SetAngle(double 指定角度) = 0;
138
140 double GetDirect(IShape* 比較対象)
141 {
142 return atan2(比較対象->GetY() - this->GetY(), 比較対象->GetX() - this->GetX());
143 }
144
146 double GetDistance(IShape* 比較対象)
147 {
148 const double xd = this->GetX() - 比較対象->GetX();
149 const double yd = this->GetY() - 比較対象->GetY();
150
151 return sqrt( xd * xd + yd * yd );
152 }
153
155 virtual double GetX() const = 0;
156
158 virtual double GetY() const = 0;
159
161 virtual double GetW() const = 0;
162
164 virtual double GetH() const = 0;
165 };
166 }
SDX::IShape::Draw
virtual void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const =0
描画する.
SDX::IShape::Clone
virtual IShape * Clone(double x, double y) const =0
同じ形の図形を作る.
SDX::IShape::GetY
virtual double GetY() const =0
Y座標を取得.
SDX::IShape::PointPoint
static int PointPoint(double x1, double y1, double x2, double y2)
二点間の距離を計算.
Definition: IShape .h:81
SDX::IShape
位置情報を持つ図形の抽象クラス.
Definition: IShape .h:18
SDX::IShape::MoveA
void MoveA(double 距離, double 方向)
極座標で移動.
Definition: IShape .h:125
SDX::IShape::GetW
virtual double GetW() const =0
幅を取得.
SDX::IShape::GetDirect
double GetDirect(IShape *比較対象)
対象との角度を取得.
Definition: IShape .h:140
SDX::Color
色を表すクラス.
Definition: Color.h:7
SDX::IShape::GetDistance
double GetDistance(IShape *比較対象)
対象との相対座標を取得.
Definition: IShape .h:146
SDX::IShape::Rotate
virtual void Rotate(double 回転する角度)=0
回転する.
SDX::IShape::Hit
virtual bool Hit(const IShape *IShape) const =0
衝突判定.
SDX::IShape::LineLine
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
線分の交差判定.
Definition: IShape .h:62
SDX::IShape::SetZoom
void SetZoom(double X拡大率, double Y拡大率)
拡大率を設定.
Definition: IShape .h:107
SDX::IShape::GetX
virtual double GetX() const =0
X座標を取得.
SDX::IShape::SetAngle
virtual void SetAngle(double 指定角度)=0
角度を指定する.
SDX::Camera
2D用に座標変換を行うカメラを表すクラス.
Definition: Camera.h:16
SDX::IShape::SetPos
virtual void SetPos(double X座標, double Y座標)=0
指定座標に移動.
SDX::IShape::GetH
virtual double GetH() const =0
高さを取得.
SDX::IShape::RectRect
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: IShape .h:25
SDX::IShape::Move
virtual void Move(double X移動量, double Y移動量)=0
相対座標で移動.
SDX::IShape::MultiZoom
void MultiZoom(double 倍率)
拡大率を掛け算する.
Definition: IShape .h:113