1 #pragma once//©SDXFramework http://sourceforge.jp/projects/dxframework/
3 #include <Framework/IShape .h>
21 std::vector<IShape*> shapes;
27 shapes.push_back( shape );
34 for(
auto it: shapes )
36 buf->shapes.push_back( it );
44 for(
auto it: shapes )
46 it->SetPos( X座標 , Y座標 );
50 void Move(
double X移動量 ,
double Y移動量)
52 for(
auto it: shapes )
54 it->Move( X移動量 , Y移動量 );
60 return shapes[0]->GetX();
65 return shapes[0]->GetY();
70 return shapes[0]->GetW();
75 return shapes[0]->GetH();
80 for(
auto it: shapes )
82 it->MultiZoom(X倍率, Y倍率);
90 for(
auto it: shapes )
98 for(
auto it: shapes )
100 it->SetAngle( 指定角度 );
108 return shape->
Hit(
this );
112 for(
auto itA : this->shapes )
114 for(
auto itB : this->shapes )
116 if( itA->Hit(itB) )
return true;
121 bool Hit(
const Point *point)
const;
122 bool Hit(
const Line *line)
const;
123 bool Hit(
const Rect *rect)
const;
124 bool Hit(
const Circle *circle)
const;
140 Point(
double X座標 ,
double Y座標):
145 template<
class TA,
class TB>
146 Point(TA X座標, TB Y座標) :
153 auto shape =
new Point( X座標 , Y座標 );
154 shape->zoomX = this->zoomX;
155 shape->zoomY = this->zoomY;
165 void Move(
double X移動量 ,
double Y移動量)
205 return shape->
Hit(
this );
209 for(
auto it : complex->shapes )
211 if( it->Hit(
this ) )
return true;
215 bool Hit(
const Point *point)
const
217 return ( point->x == this->x && point->y == this->y );
219 bool Hit(
const Line *line)
const;
220 bool Hit(
const Rect *rect)
const;
221 bool Hit(
const Circle *circle)
const;
229 virtual void CulParam()
236 this->xA = x + cos( angle ) * lengthA;
237 this->yA = y + sin( angle ) * lengthA;
238 this->xB = x - cos( angle ) * lengthB;
239 this->yB = y - sin( angle ) * lengthB;
240 this->width = abs(this->xB - this->xA);
241 this->height = abs(this->yB - this->yA);
242 this->thickHarf = this->thick / 2;
243 this->thickPow = this->thick * this->thick / 4;
244 this->minX = std::min( xA , xB );
245 this->maxX = std::max( xA , xB );
246 this->minY = std::min( yA , yB );
247 this->maxY = std::max( yA , yB );
274 Line(
double X中心座標 ,
double Y中心座標 ,
double 角度 ,
double 長さ ,
double 太さ):
285 Line(
double X中心座標,
double Y中心座標,
double 角度,
double 前方長さ ,
double 後方長さ ,
double 太さ) :
298 auto shape =
new Line( X座標 , Y座標 , this->angle , this->lengthA , this->thick);
299 shape->zoomX = this->zoomX;
300 shape->zoomY = this->zoomY;
333 this->lengthA *= X倍率;
334 this->lengthB *= Y倍率;
345 this->angle += 回転する角度;
355 void Move(
double X移動量 ,
double Y移動量 )
392 double GetThick()
const
397 void SetThick(
double 太さ)
400 thickHarf = int(thick / 2);
401 thickPow = int(thick * thick / 4);
404 double GetAngle()
const
409 double GetLength()
const
411 return this->lengthA + this->lengthB;
414 double GetThickHarf()
const
416 return this->thickHarf;
419 double GetThickPow()
const
421 return this->thickPow;
424 double GetMinX()
const
429 double GetMinY()
const
434 double GetMaxX()
const
439 double GetMaxY()
const
446 return shape->
Hit(
this );
450 for(
auto it : complex->shapes )
452 if( it->Hit(
this ) )
return true;
456 bool Hit(
const Point *point)
const
458 return LinePoint( point->GetX() , point->GetY() , this->GetThick() );
460 bool Hit(
const Line *line)
const
463 if(
RectRect(this->GetXA() - this->GetThickHarf() ,this->GetYA() - this->GetThickHarf() , this->GetXB() - line->GetThickHarf() , this->GetYB() - line->GetThickHarf() ,
464 line->GetXA() - this->GetThickHarf() ,line->GetYA() - this->GetThickHarf() , line->GetXB() - line->GetThickHarf() , line->GetYB() - line->GetThickHarf() ) )
469 if(
LineLine(this->GetXA() ,this->GetYA() ,this->GetXB() ,this->GetYB() ,line->GetXA(),line->GetYA(),line->GetXB(),line->GetYB() ) )
475 if( this->GetLength() != 0)
477 if( this->
LinePoint( line->GetXA() , line->GetYA() , this->GetThickHarf() + line->GetThickHarf() ) )
return true;
478 if( this->
LinePoint( line->GetXB() , line->GetYB() , this->GetThickHarf() + line->GetThickHarf() ) )
return true;
480 if( line->GetLength() != 0 )
482 if( line->LinePoint( this->GetXA() , this->GetYA() , this->GetThickHarf() + line->GetThickHarf() ) )
return true;
483 if( line->LinePoint( this->GetXB() , this->GetYB() , this->GetThickHarf() + line->GetThickHarf() ) )
return true;
488 bool Hit(
const Rect *rect)
const;
489 bool Hit(
const Circle *circle)
const;
492 bool LinePoint(
double px ,
double py ,
double range )
const
495 const double dx = GetXB() - GetXA();
496 const double dy = GetYB() - GetYA();
498 const double a = dx * dx + dy * dy;
499 const double b = dx *(GetXA() - px) + dy *(GetYA() - py);
505 ( GetXA() - px ) *( GetXA() - px ) +
506 ( GetYA() - py ) *( GetYA() - py )
507 < range * range )
return true;
511 const double t = -b / a;
513 const double tx = GetXA() + dx*t;
514 const double ty = GetYA() + dy*t;
517 if ( tx < minX || tx > maxX || ty < minY || ty > maxY)
520 (xA - px) * (xA - px) + (yA - py) * (yA - py) > range * range &&
521 (xB - px) * (xB - px) + (yB - py) * (yB - py) > range * range
528 const double d = (px - tx)*(px - tx) + (py - ty) * (py - ty);
530 return (d < range * range);
551 Rect(
double X座標,
double Y座標,
double 横幅A ,
double 高さA,
double 横幅B = 0 ,
double 高さB = 0):
561 Rect(T X座標, T Y座標, T 横幅A, T 高さA, T 横幅B = 0, T 高さB = 0) :
564 heightUp((
double)高さB),
565 heightDown((
double)高さA),
566 widthLeft((
double)横幅B),
567 widthRight((
double)横幅A)
573 auto shape =
new Rect( X座標 , Y座標 , widthRight , heightDown , widthLeft , heightUp );
574 shape->zoomX = this->zoomX;
575 shape->zoomY = this->zoomY;
585 void Move(
double X移動量 ,
double Y移動量 )
618 return widthLeft + widthRight;
623 return heightUp + heightDown;
626 inline double GetLeft()
const
628 return x - widthLeft;
631 inline double GetTop()
const
636 inline double GetRight()
const
638 return x + widthRight;
641 inline double GetBottom()
const
643 return y + heightDown;
648 return shape->
Hit(
this );
652 for(
auto it : complex->shapes )
654 if( it->Hit(
this ) )
return true;
658 bool Hit(
const Point *point)
const
662 point->x < this->GetRight()
664 point->x > this->GetLeft()
666 point->y < this->GetBottom()
668 point->y > this->GetTop()
672 bool Hit(
const Line *line)
const
676 line->GetMaxX() + line->GetThickHarf() < this->GetLeft() ||
677 line->GetMinX() - line->GetThickHarf() > this->GetTop() ||
678 line->GetMaxY() + line->GetThickHarf() < this->GetRight() ||
679 line->GetMinY() - line->GetThickHarf() > this->GetBottom()
687 if(
LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
688 , this->GetLeft() - int(line->GetThickHarf() * 0.7) , this->GetTop() - int(line->GetThickHarf() * 0.7) , this->GetRight() + int(line->GetThickHarf() * 0.7) , this->GetBottom() + int(line->GetThickHarf() * 0.7) ))
693 if(
LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
694 , this->GetRight() + int(line->GetThickHarf() * 0.7) , this->GetTop() - int(line->GetThickHarf() * 0.7) , this->GetLeft() - int(line->GetThickHarf() * 0.7) , this->GetBottom() + int(line->GetThickHarf() * 0.7) ))
701 line->GetXA() + line->GetThickHarf() > this->GetLeft() && line->GetXA() - line->GetThickHarf() < this->GetRight() &&
702 line->GetYA() + line->GetThickHarf() > this->GetTop() && line->GetYA() - line->GetThickHarf() < this->GetBottom()
706 if( line->GetXA() < this->GetLeft() && line->GetYA() < this->GetTop() )
709 if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
710 (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() )
return true;
713 else if( line->GetXA() > this->GetRight() && line->GetYA() < this->GetTop() )
716 if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
717 (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() )
return true;
720 else if( line->GetXA() < this->GetLeft() && line->GetYA() > this->GetBottom() )
723 if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
724 (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() )
return true;
727 else if( line->GetXA() > this->GetRight() && line->GetYA() > this->GetBottom() )
730 if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
731 (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() )
return true;
741 line->GetXB() + line->GetThickHarf() > this->GetLeft() && line->GetXB() - line->GetThickHarf() < this->GetRight() &&
742 line->GetYB() + line->GetThickHarf() > this->GetTop() && line->GetYB() - line->GetThickHarf() < this->GetBottom()
746 if( line->GetXB() < this->GetLeft() && line->GetYB() < this->GetTop() )
748 if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
749 (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() )
return true;
752 else if( line->GetXB() > this->GetRight() && line->GetYB() < this->GetTop() )
755 if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
756 (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() )
return true;
759 else if( line->GetXB() < this->GetLeft() && line->GetYB() > this->GetBottom() )
762 if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
763 (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() )
return true;
766 else if( line->GetXB() > this->GetRight() && line->GetYB() > this->GetBottom() )
768 if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
769 (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() )
return true;
780 bool Hit(
const Rect *rect)
const
782 return !(GetRight() < rect->GetLeft() || GetLeft() > rect->GetRight() || GetBottom() < rect->GetTop() || GetTop() > rect->GetBottom() );
784 bool Hit(
const Circle *circle)
const;
796 Circle(
double X座標 ,
double Y座標 ,
double 半径):
804 auto shape =
new Circle( X座標 , Y座標 , this->radius );
805 shape->zoomX = this->zoomX;
806 shape->zoomY = this->zoomY;
828 void Move(
double X移動量 ,
double Y移動量 )
846 return int(radius*2);
851 return int(radius*2);
858 return shape->
Hit(
this );
862 for(
auto it : complex->shapes )
864 if( it->Hit(
this ) )
return true;
868 bool Hit(
const Point *point)
const
872 ( point->x - this->x ) * ( point->x - this->x ) +
873 ( point->y - this->y ) * ( point->y - this->y )
875 ( this->radius * this->radius )
878 bool Hit(
const Line *line)
const
880 return line->LinePoint( x , y , (line->GetThickHarf() + radius) );
882 bool Hit(
const Circle *circle)
const
885 (this->x - circle->x) * (this->x - circle->x) +
886 (this->y - circle->y) * (this->y - circle->y)
888 (this->radius + circle->radius) * (this->radius + circle->radius)
891 bool Hit(
const Rect *rect)
const
898 this->x + this->radius >= rect->GetLeft()
900 this->x - this->radius <= rect->GetRight()
904 this->y >= rect->GetTop()
906 this->y <= rect->GetBottom()
912 this->x >= rect->GetLeft()
914 this->x <= rect->GetRight()
918 this->y + this->radius >= rect->GetTop()
920 this->y - this->radius <= rect->GetBottom()
924 (this->x - rect->GetLeft() ) * (this->x - rect->GetLeft() ) +
925 (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
926 (this->radius * this->radius )
928 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
929 (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
930 (this->radius * this->radius )
932 (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) +
933 (this->y - rect->GetBottom()) * (this->y -rect->GetBottom()) <=
934 (this->radius * this->radius )
936 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
937 (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <=
938 (this->radius * this->radius )
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:197
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:78
bool Hit(const IShape *shape) const
衝突判定.
Definition: Shape.h:856
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:191
IShape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:151
矩形を表す図形クラス.
Definition: Shape.h:536
bool Hit(const IShape *shape) const
衝突判定.
Definition: Shape.h:203
double GetX() const
X座標を取得.
Definition: Shape.h:606
double GetW() const
幅を取得.
Definition: Shape.h:616
太さのある線を表す図形クラス.
Definition: Shape.h:226
double GetY() const
Y座標を取得.
Definition: Shape.h:611
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: ShapeDraw.h:46
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: ShapeDraw.h:6
double GetW() const
幅を取得.
Definition: Shape.h:181
double GetY() const
Y座標を取得.
Definition: Shape.h:176
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:199
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:579
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:602
virtual IShape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:296
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:50
IShape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:30
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:810
double GetX() const
X座標を取得.
Definition: Shape.h:58
点を表す図形クラス.
Definition: Shape.h:129
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:165
double GetX() const
X座標を取得.
Definition: Shape.h:171
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: ShapeDraw.h:28
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:600
位置情報を持つ図形の抽象クラス.
Definition: IShape .h:18
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:585
複合図形を表すクラス.
Definition: Shape.h:18
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:88
double GetW() const
幅を取得.
Definition: Shape.h:314
double GetW() const
幅を取得.
Definition: Shape.h:844
double GetW() const
幅を取得.
Definition: Shape.h:68
double GetX() const
X座標を取得.
Definition: Shape.h:834
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:42
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: ShapeDraw.h:14
bool Hit(const IShape *shape) const
衝突判定.
Definition: Shape.h:444
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: ShapeDraw.h:80
色を表すクラス.
Definition: Color.h:7
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:96
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:349
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:591
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:355
virtual bool Hit(const IShape *IShape) const =0
衝突判定.
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
線分の交差判定.
Definition: IShape .h:62
double GetY() const
Y座標を取得.
Definition: Shape.h:63
double GetY() const
Y座標を取得.
Definition: Shape.h:309
double GetH() const
高さを取得.
Definition: Shape.h:849
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:159
double GetH() const
高さを取得.
Definition: Shape.h:73
IShape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:802
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:826
2D用に座標変換を行うカメラを表すクラス.
Definition: Camera.h:16
bool LinePoint(double px, double py, double range) const
線と点の当たり判定.
Definition: Shape.h:492
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:828
double GetH() const
高さを取得.
Definition: Shape.h:186
virtual IShape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:571
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: IShape .h:25
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:824
double GetX() const
X座標を取得.
Definition: Shape.h:304
円を表す図形クラス.
Definition: Shape.h:789
double GetY() const
Y座標を取得.
Definition: Shape.h:839
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:324
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:331
void MultiZoom(double 倍率X, double 倍率Y)
縦横別で拡大率を掛け算する.
Definition: Shape.h:816
bool Hit(const IShape *shape) const
衝突判定.
Definition: Shape.h:646
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:343
bool Hit(const IShape *shape) const
衝突判定.
Definition: Shape.h:106
double GetH() const
高さを取得.
Definition: Shape.h:319
double GetH() const
高さを取得.
Definition: Shape.h:621