SDXFrameWork 0.10 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Circle.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5
6 #include <Framework/IShape.h>
7 namespace SDX
8 {
9 class Complex;
10 class Point;
11 class Line;
12 class Circle;
13 class Rect;
14
15 class Camera;
16 class Color;
17
20 class Circle : public IShape
21 {
22 public:
23 double x;
24 double y;
25 double radius;
26
28 Circle(double X座標, double Y座標, double 半径) :
29 x(X座標),
30 y(Y座標),
31 radius(半径)
32 {}
33
34 IShape* Clone(double X座標, double Y座標) const override
35 {
36 auto shape = new Circle(X座標, Y座標, this->radius);
37 shape->zoomX = this->zoomX;
38 shape->zoomY = this->zoomY;
39 return shape;
40 }
41
42 void SetPos(double X座標, double Y座標) override
43 {
44 this->x = X座標;
45 this->y = Y座標;
46 }
47
48 void MultiZoom(double 倍率X, double 倍率Y) override
49 {
50 this->radius *= 倍率X;
51
52 zoomX *= 倍率X;
53 zoomY *= 倍率Y;
54 }
55
56 void Rotate(double 回転する角度) override
57 {
58 }
59
60 void Move(double X移動量, double Y移動量) override
61 {
62 this->x += X移動量;
63 this->y += Y移動量;
64 }
65
66 double GetX() const override
67 {
68 return int(x);
69 }
70
71 double GetY() const override
72 {
73 return int(y);
74 }
75
76 double GetW() const override
77 {
78 return int(radius * 2);
79 }
80
81 double GetH() const override
82 {
83 return int(radius * 2);
84 }
85
86 void Draw(const Color &描画色) const override;
87
88 bool Hit(const IShape *shape) const override
89 {
90 return shape->Hit(this);
91 }
92 bool Hit(const Complex *complex) const override
93 {
94 for (auto it : complex->shapes)
95 {
96 if (it->Hit(this)) return true;
97 }
98 return false;
99 }
100 bool Hit(const Point *point) const override
101 {
102 return
103 (
104 (point->x - this->x) * (point->x - this->x) + (point->y - this->y) * (point->y - this->y)
105 <=
106 (this->radius * this->radius)
107 );
108 }
109 bool Hit(const Line *line) const override
110 {
111 return line->LinePoint(x, y, (line->GetThickHarf() + radius));
112 }
113 bool Hit(const Circle *circle) const override
114 {
115 return
116 (
117 (this->x - circle->x) * (this->x - circle->x) + (this->y - circle->y) * (this->y - circle->y)
118 <=
119 (this->radius + circle->radius) * (this->radius + circle->radius)
120 );
121 }
122 bool Hit(const Rect *rect) const override
123 {
124 return
125 (
126 (
127 (
128 (
129 this->x + this->radius >= rect->GetLeft()
130 ) && (
131 this->x - this->radius <= rect->GetRight()
132 )
133 ) && (
134 (
135 this->y >= rect->GetTop()
136 ) && (
137 this->y <= rect->GetBottom()
138 )
139 )
140 ) || (
141 (
142 (
143 this->x >= rect->GetLeft()
144 ) && (
145 this->x <= rect->GetRight()
146 )
147 ) && (
148 (
149 this->y + this->radius >= rect->GetTop()
150 ) && (
151 this->y - this->radius <= rect->GetBottom()
152 )
153 )
154 ) || (//四角形の四隅と円の判定
155 (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) + (this->y - rect->GetTop()) * (this->y - rect->GetTop()) <= (this->radius * this->radius)
156 ) || (
157 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) + (this->y - rect->GetTop()) * (this->y - rect->GetTop()) <= (this->radius * this->radius)
158 ) || (
159 (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) + (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <= (this->radius * this->radius)
160 ) || (
161 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) + (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <= (this->radius * this->radius)
162 )
163 );
164 }
165 };
166 }
SDX::Line::GetThickHarf
double GetThickHarf() const
太さの半分を取得.
Definition: Line.h:206
SDX::Rect
矩形を表す図形クラス.
Definition: Rect.h:22
SDX::Point::y
double y
座標
Definition: Point.h:26
SDX::Circle::Draw
void Draw(const Color &描画色) const override
描画する.
Definition: ShapeDraw.h:38
SDX::Line
太さのある線を表す図形クラス.
Definition: Line.h:20
SDX::Rect::GetBottom
double GetBottom() const
下端のY座標を取得.
Definition: Rect.h:136
SDX::Circle::GetX
double GetX() const override
X座標を取得.
Definition: Circle.h:66
SDX::Circle::Clone
IShape * Clone(double X座標, double Y座標) const override
同じ形の図形を作る.
Definition: Circle.h:34
SDX::Rect::GetTop
double GetTop() const
上端のY座標を取得.
Definition: Rect.h:124
SDX::Rect::GetRight
double GetRight() const
右端のX座標を取得.
Definition: Rect.h:130
SDX::Circle::Hit
bool Hit(const Line *line) const override
衝突判定.
Definition: Circle.h:109
SDX::Rect::GetLeft
double GetLeft() const
左端のX座標を取得.
Definition: Rect.h:118
SDX::Circle::Hit
bool Hit(const Rect *rect) const override
衝突判定.
Definition: Circle.h:122
SDX::Complex::shapes
std::vector< IShape * > shapes
保持するShape
Definition: Complex.h:23
SDX::Circle::x
double x
座標
Definition: Circle.h:23
SDX::Point
点を表す図形クラス.
Definition: Point.h:22
SDX::Circle::Move
void Move(double X移動量, double Y移動量) override
相対座標で移動.
Definition: Circle.h:60
SDX::IShape
衝突判定可能な図形の抽象クラス.
Definition: IShape.h:21
SDX::IShape::Hit
virtual bool Hit(const IShape *iShape) const =0
衝突判定.
SDX::Circle::y
double y
座標
Definition: Circle.h:24
SDX::Complex
複合図形を表すクラス.
Definition: Complex.h:20
SDX::Circle::Hit
bool Hit(const Point *point) const override
衝突判定.
Definition: Circle.h:100
SDX::Circle::GetY
double GetY() const override
Y座標を取得.
Definition: Circle.h:71
SDX::Color
色を表すクラス.
Definition: Color.h:11
SDX::Circle::Hit
bool Hit(const Circle *circle) const override
衝突判定.
Definition: Circle.h:113
SDX::Circle::MultiZoom
void MultiZoom(double 倍率X, double 倍率Y) override
縦横別で拡大率を掛け算する.
Definition: Circle.h:48
SDX::Circle::GetH
double GetH() const override
高さを取得.
Definition: Circle.h:81
SDX::Circle::Hit
bool Hit(const IShape *shape) const override
衝突判定.
Definition: Circle.h:88
SDX::Circle::SetPos
void SetPos(double X座標, double Y座標) override
指定座標に移動.
Definition: Circle.h:42
SDX::IPosition::zoomX
double zoomX
図形の拡大率
Definition: Framework/IPosition.h:14
SDX::Point::x
double x
座標
Definition: Point.h:25
SDX::Circle::GetW
double GetW() const override
幅を取得.
Definition: Circle.h:76
SDX::Line::LinePoint
bool LinePoint(double px, double py, double range) const
線と点の当たり判定.
Definition: Line.h:289
SDX::Circle::Circle
Circle(double X座標, double Y座標, double 半径)
コンストラクタ.
Definition: Circle.h:28
SDX::Circle
円を表す図形クラス.
Definition: Circle.h:20
SDX::IPosition::zoomY
double zoomY
図形の拡大率
Definition: Framework/IPosition.h:15
SDX::Circle::Hit
bool Hit(const Complex *complex) const override
衝突判定.
Definition: Circle.h:92
SDX::Circle::radius
double radius
半径
Definition: Circle.h:25
SDX::Circle::Rotate
void Rotate(double 回転する角度) override
回転する.
Definition: Circle.h:56