6 #include <Framework/IShape.h>
47 this->xA = x + cos(angle) * lengthA;
48 this->yA = y + sin(angle) * lengthA;
49 this->xB = x - cos(angle) * lengthB;
50 this->yB = y - sin(angle) * lengthB;
51 this->width = abs(this->xB - this->xA);
52 this->height = abs(this->yB - this->yA);
53 this->thickHarf = this->thick / 2;
54 this->thickPow = this->thick * this->thick / 4;
55 this->minX = std::min(xA, xB);
56 this->maxX = std::max(xA, xB);
57 this->minY = std::min(yA, yB);
58 this->maxY = std::max(yA, yB);
64 Line(
double X中心座標,
double Y中心座標,
double 角度,
double 長さ,
double 太さ) :
76 Line(
double X中心座標,
double Y中心座標,
double 角度,
double 前方長さ,
double 後方長さ,
double 太さ) :
89 auto shape =
new Line(X座標, Y座標, this->angle, this->lengthA, this->thick);
90 shape->zoomX = this->
zoomX;
91 shape->zoomY = this->
zoomY;
95 double GetX()
const override
115 void SetPos(
double X座標,
double Y座標)
override
124 this->lengthA *= X倍率;
125 this->lengthB *= Y倍率;
136 this->angle += 回転する角度;
140 void Move(
double X移動量,
double Y移動量)
override
155 void Draw(
const Color &描画色)
const override;
191 thickHarf = int(thick / 2);
192 thickPow = int(thick * thick / 4);
204 return this->lengthA + this->lengthB;
210 return this->thickHarf;
216 return this->thickPow;
245 return shape->
Hit(
this);
249 for (
auto it : complex->
shapes)
251 if (it->Hit(
this))
return true;
287 bool Hit(
const Rect *rect)
const override;
288 bool Hit(
const Circle *circle)
const override;
291 bool LinePoint(
double px,
double py,
double range)
const
297 const double a = dx * dx + dy * dy;
298 const double b = dx *(
GetXA() - px) + dy *(
GetYA() - py);
306 < range * range)
return true;
310 const double t = -b / a;
312 const double tx =
GetXA() + dx*t;
313 const double ty =
GetYA() + dy*t;
316 if (tx < minX || tx > maxX || ty < minY || ty > maxY)
319 (xA - px) * (xA - px) + (yA - py) * (yA - py) > range * range &&
320 (xB - px) * (xB - px) + (yB - py) * (yB - py) > range * range
327 const double d = (px - tx)*(px - tx) + (py - ty) * (py - ty);
329 return (d < range * range);
double GetAngle() const override
角度を取得.
Definition: Line.h:196
double GetThickHarf() const
太さの半分を取得.
Definition: Line.h:208
double GetYB() const
頂点BのY座標を取得.
Definition: Line.h:176
矩形を表す図形クラス.
Definition: Rect.h:22
太さのある線を表す図形クラス.
Definition: Line.h:20
double GetThick() const
太さを取得.
Definition: Line.h:182
bool Hit(const Line *line) const override
衝突判定.
Definition: Line.h:259
void SetThick(double 太さ)
太さを設定.
Definition: Line.h:188
Line(double X中心座標, double Y中心座標, double 角度, double 前方長さ, double 後方長さ, double 太さ)
コンストラクタ.
Definition: Line.h:76
double GetMaxY() const
頂点AとBのY座標の大きい値を取得.
Definition: Line.h:238
std::vector< IShape * > shapes
保持するShape
Definition: Complex.h:23
double GetY() const override
Y座標を取得.
Definition: Point.h:68
double GetLength() const
長さを取得.
Definition: Line.h:202
点を表す図形クラス.
Definition: Point.h:22
void Rotate(double 回転する角度) override
回転する.
Definition: Line.h:134
衝突判定可能な図形の抽象クラス.
Definition: IShape.h:21
virtual bool Hit(const IShape *iShape) const =0
衝突判定.
複合図形を表すクラス.
Definition: Complex.h:20
void Draw(const Color &描画色) const override
描画する.
Definition: ShapeDraw.h:23
void SetPos(double X座標, double Y座標) override
指定座標に移動.
Definition: Line.h:115
double GetMinX() const
頂点AとBのX座標の小さい値を取得.
Definition: Line.h:220
色を表すクラス.
Definition: Color.h:11
double GetX() const override
X座標を取得.
Definition: Line.h:95
double GetH() const override
高さを取得.
Definition: Line.h:110
bool Hit(const Complex *complex) const override
衝突判定.
Definition: Line.h:247
bool Hit(const Point *point) const override
衝突判定.
Definition: Line.h:255
double GetMinY() const
頂点AとBのY座標の小さい値を取得.
Definition: Line.h:226
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
線分の交差判定.
Definition: IShape.h:62
double GetW() const override
幅を取得.
Definition: Line.h:105
Line(double X中心座標, double Y中心座標, double 角度, double 長さ, double 太さ)
コンストラクタ.
Definition: Line.h:64
double GetXB() const
頂点BのX座標を取得.
Definition: Line.h:170
double zoomX
図形の拡大率
Definition: IPosition.h:14
void MultiZoom(double X倍率, double Y倍率) override
縦横別で拡大率を掛け算する.
Definition: Line.h:122
bool LinePoint(double px, double py, double range) const
線と点の当たり判定.
Definition: Line.h:291
virtual IShape * Clone(double X座標, double Y座標) const override
同じ形の図形を作る.
Definition: Line.h:87
double GetYA() const
頂点AのY座標を取得.
Definition: Line.h:164
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: IShape.h:25
double GetXA() const
頂点AのX座標を取得.
Definition: Line.h:158
double GetMaxX() const
頂点AとBのX座標の大きい値を取得.
Definition: Line.h:232
円を表す図形クラス.
Definition: Circle.h:20
double zoomY
図形の拡大率
Definition: IPosition.h:15
double GetX() const override
X座標を取得.
Definition: Point.h:63
double GetThickPow() const
太さの二乗を取得.
Definition: Line.h:214
double GetY() const override
Y座標を取得.
Definition: Line.h:100
bool Hit(const IShape *shape) const override
衝突判定.
Definition: Line.h:243
void Move(double X移動量, double Y移動量) override
相対座標で移動.
Definition: Line.h:140