SDXFrameWork  0.07
SDXFrameWork
 全て クラス ネームスペース 関数 変数 列挙型 列挙型の値 ページ
Shape.h
1 #pragma once//☀SDXFramework
2 #include <Framework/Camera.h>
3 #include <Multimedia/Drawing.h>
4 
5 namespace SDX
6 {
7 class Shape;
8 class Complex;
9 class Point;
10 class Line;
11 class Circle;
12 class Rect;
13 
16 class Shape
17 {
18 protected:
19  double zoomX;
20  double zoomY;
21 
23  static bool RectRect( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
24  {
25  //x座標をラフチェック
26  if ( x1 >= x2)
27  {
28  if ((x1 < x3 && x1 < x4) || (x2 > x3 && x2 > x4))
29  {
30  return false;
31  }
32  }
33  else
34  {
35  if ((x2 < x3 && x2 < x4) || (x1 > x3 && x1 > x4))
36  {
37  return false;
38  }
39  }
40  //y座標をラフチェック
41  if (y1 >= y2)
42  {
43  if ((y1 < y3 && y1 < y4) || (y2 > y3 && y2 > y4))
44  {
45  return false;
46  }
47  }
48  else
49  {
50  if ((y2 < y3 && y2 < y4) || (y1 > y3 && y1 > y4))
51  {
52  return false;
53  }
54  }
55 
56  return true;
57  }
58 
60  static bool LineLine( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
61  {
62  //交差判定
63  if ((double(x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
64  (double(x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0)
65  {
66  return false;
67  }
68 
69  if ((double(x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)) *
70  (double(x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)) > 0)
71  {
72  return false;
73  }
74  return true;
75 
76  }
77 
79  static int PointPoint(double x1 , double y1 , double x2 , double y2)
80  {
81  return int((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
82  }
83 
84 public:
85  Shape():
86  zoomX(1),
87  zoomY(1)
88  {}
89 
91  virtual bool Hit(const Shape *shape) const = 0;
92  virtual bool Hit(const Complex *complex) const = 0;
93  virtual bool Hit(const Point *point) const = 0;
94  virtual bool Hit(const Line *line) const = 0;
95  virtual bool Hit(const Rect *rect) const = 0;
96  virtual bool Hit(const Circle *circle) const = 0;
97 
99  virtual void SetPos(double X座標 , double Y座標) = 0;
100 
102  virtual Shape* Clone(double x , double y) const = 0;
103 
105  void SetZoom(double X拡大率 , double Y拡大率)
106  {
107  MultiZoom( X拡大率 / zoomX , Y拡大率 / zoomY);
108  }
109 
111  void MultiZoom(double 倍率)
112  {
113  MultiZoom(倍率,倍率);
114  }
115 
117  virtual void MultiZoom(double X倍率 , double Y倍率) = 0;
118 
120  virtual void Move(double X移動量 , double Y移動量) = 0;
121 
123  void MoveA(double 距離 , double 方向 )
124  {
125  Move( 距離 * cos(方向) , 距離 * sin(方向) );
126  }
127 
129  virtual void Draw(Color 描画色 , int 透過率 , Camera *座標変換Camera = 0) const = 0;
130 
132  virtual void Rotate(double 回転する角度) = 0;
133 
135  virtual void SetAngle(double 指定角度) = 0;
136 
138  double GetDirect(Shape* 比較対象)
139  {
140  return atan2(比較対象->GetY() - this->GetY(), 比較対象->GetX() - this->GetX());
141  }
142 
144  double GetDistance(Shape* 比較対象)
145  {
146  const double xd = this->GetX() - 比較対象->GetX();
147  const double yd = this->GetY() - 比較対象->GetY();
148 
149  return sqrt( xd * xd + yd * yd );
150  }
151 
153  virtual double GetX() const = 0;
154 
156  virtual double GetY() const = 0;
157 
159  virtual double GetW() const = 0;
160 
162  virtual double GetH() const = 0;
163 };
164 
167 class Complex : public Shape
168 {
169 public:
170  std::vector<Shape*> shapes;
171 
172  Complex(){};
173 
174  Complex(Shape *shape)
175  {
176  shapes.push_back( shape );
177  }
178 
179  Shape* Clone(double x,double y) const
180  {
181  Complex *buf = new Complex();
182 
183  for( auto it: shapes )
184  {
185  buf->shapes.push_back( it );
186  }
187 
188  return buf;
189  }
190 
191  void SetPos(double X座標 , double Y座標)
192  {
193  for( auto it: shapes )
194  {
195  it->SetPos( X座標 , Y座標 );
196  }
197  }
198 
199  void Move(double X移動量 , double Y移動量)
200  {
201  for( auto it: shapes )
202  {
203  it->Move( X移動量 , Y移動量 );
204  }
205  }
206 
207  double GetX() const
208  {
209  return shapes[0]->GetX();
210  }
211 
212  double GetY() const
213  {
214  return shapes[0]->GetY();
215  }
216 
217  double GetW() const
218  {
219  return shapes[0]->GetW();
220  }
221 
222  double GetH() const
223  {
224  return shapes[0]->GetH();
225  }
226 
227  void MultiZoom(double X倍率 , double Y倍率)
228  {
229  for( auto it: shapes )
230  {
231  it->MultiZoom(X倍率, Y倍率);
232  }
233  zoomX *= X倍率;
234  zoomY *= Y倍率;
235  }
236 
237  void Rotate(double 回転する角度)
238  {
239  for( auto it: shapes )
240  {
241  it->Rotate( 回転する角度 );
242  }
243  }
244 
245  void SetAngle(double 指定角度)
246  {
247  for( auto it: shapes )
248  {
249  it->SetAngle( 指定角度 );
250  }
251  }
252 
253  void Draw(Color 描画色, int 透過率, Camera *座標変換Camera = 0) const
254  {
255  for( auto it: shapes )
256  {
257  it->Draw(描画色, 透過率, 座標変換Camera);
258  }
259  }
260 
261  bool Hit(const Shape *shape) const
262  {
263  return shape->Hit( this );
264  }
265  bool Hit(const Complex *complex) const
266  {
267  for( auto itA : this->shapes )
268  {
269  for( auto itB : this->shapes )
270  {
271  if( itA->Hit(itB) ) return true;
272  }
273  }
274  return false;
275  }
276  bool Hit(const Point *point) const;
277  bool Hit(const Line *line) const;
278  bool Hit(const Rect *rect) const;
279  bool Hit(const Circle *circle) const;
280 };
281 
284 class Point : public Shape
285 {
286 public:
287  double x;
288  double y;
289 
290  Point() :
291  x(0),
292  y(0)
293  {};
294 
295  Point(double X座標 , double Y座標):
296  x(X座標),
297  y(Y座標)
298  {}
299 
300  Shape* Clone(double X座標,double Y座標) const
301  {
302  auto shape = new Point( X座標 , Y座標 );
303  shape->zoomX = this->zoomX;
304  shape->zoomY = this->zoomY;
305  return shape;
306  }
307 
308  void SetPos(double X座標 , double Y座標)
309  {
310  this->x = X座標;
311  this->y = Y座標;
312  }
313 
314  void Move(double X移動量 , double Y移動量)
315  {
316  this->x += X移動量;
317  this->y += Y移動量;
318  }
319 
320  double GetX() const
321  {
322  return x;
323  }
324 
325  double GetY() const
326  {
327  return y;
328  }
329 
330  double GetW() const
331  {
332  return 1;
333  }
334 
335  double GetH() const
336  {
337  return 1;
338  }
339 
340  void MultiZoom(double X倍率 , double Y倍率)
341  {
342  zoomX *= X倍率;
343  zoomY *= Y倍率;
344  }
345 
346  void Rotate(double 回転する角度){}
347 
348  void SetAngle(double 指定角度){}
349 
350  void Draw(Color 描画色, int 透過率, Camera *座標変換Camera = 0) const
351  {
352  Screen::SetBlendMode(BlendMode::Alpha, 透過率);
353  if (座標変換Camera)
354  {
355  Drawing::Pixel((int)座標変換Camera->TransX(x), (int)座標変換Camera->TransY(y), 描画色);
356  }
357  else
358  {
359  Drawing::Pixel((int)x, (int)y, 描画色);
360  }
361  Screen::SetBlendMode(BlendMode::NoBlend, 透過率);
362  }
363 
364  bool Hit(const Shape *shape) const
365  {
366  return shape->Hit( this );
367  }
368  bool Hit(const Complex *complex) const
369  {
370  for( auto it : complex->shapes )
371  {
372  if( it->Hit( this ) ) return true;
373  }
374  return false;
375  }
376  bool Hit(const Point *point) const
377  {
378  return ( point->x == this->x && point->y == this->y );
379  }
380  bool Hit(const Line *line) const;
381  bool Hit(const Rect *rect) const;
382  bool Hit(const Circle *circle) const;
383 };
384 
387 class Line : public Shape
388 {
389 private:
390  virtual void CulParam()
391  {
392  CulLine();
393  }
394 
395  void CulLine()
396  {
397  this->xA = x + cos( angle ) * lengthA;
398  this->yA = y + sin( angle ) * lengthA;
399  this->xB = x - cos( angle ) * lengthB;
400  this->yB = y - sin( angle ) * lengthB;
401  this->width = abs(this->xB - this->xA);
402  this->height = abs(this->yB - this->yA);
403  this->thickHarf = this->thick / 2;
404  this->thickPow = this->thick * this->thick / 4;
405  this->minX = std::min( xA , xB );
406  this->maxX = std::max( xA , xB );
407  this->minY = std::min( yA , yB );
408  this->maxY = std::max( yA , yB );
409  }
410 
411  double x;
412  double y;
413  double xA;
414  double yA;
415  double xB;
416  double yB;
417  double thick;//半径
418 
419  double angle;//角度
420 
421  double lengthA;
422  double lengthB;
423 
424  double width;
425  double height;
426  double thickHarf;//半径の二条
427  double thickPow;
428  double minX;
429  double minY;
430  double maxX;
431  double maxY;
432 
433 public:
434 
435  Line( double X中心座標 , double Y中心座標 , double 角度 , double 長さ , double 太さ):
436  x(X中心座標),
437  y(Y中心座標),
438  angle( 角度 ),
439  lengthA( 長さ/2 ),
440  lengthB( 長さ/2 ),
441  thick( 太さ )
442  {
443  this->CulLine();
444  }
445 
446  virtual Shape* Clone(double X座標,double Y座標) const
447  {
448  auto shape = new Line( X座標 , Y座標 , this->angle , this->lengthA , this->thick);
449  shape->zoomX = this->zoomX;
450  shape->zoomY = this->zoomY;
451  return shape;
452  }
453 
454  double GetX() const
455  {
456  return x;
457  }
458 
459  double GetY() const
460  {
461  return y;
462  }
463 
464  double GetW() const
465  {
466  return int(xA - xB);
467  }
468 
469  double GetH() const
470  {
471  return int(yA - yB);
472  }
473 
474  void SetPos(double X座標 , double Y座標 )
475  {
476  this->x = X座標;
477  this->y = Y座標;
478  this->CulParam();
479  }
480 
481  void MultiZoom(double X倍率 , double Y倍率)
482  {
483  this->lengthA *= X倍率;
484  this->lengthB *= Y倍率;
485  this->thick *= X倍率;
486 
487  this->CulParam();
488 
489  zoomX *= X倍率;
490  zoomY *= Y倍率;
491  }
492 
493  void Rotate(double 回転する角度)
494  {
495  this->angle += 回転する角度;
496  this->CulParam();
497  }
498 
499  void SetAngle(double 指定角度)
500  {
501  this->angle = 指定角度;
502  this->CulParam();
503  }
504 
505  void Move(double X移動量 , double Y移動量 )
506  {
507  this->x += X移動量;
508  this->y += Y移動量;
509  this->xA += X移動量;
510  this->yA += Y移動量;
511  this->xB += X移動量;
512  this->yB += Y移動量;
513 
514  this->minX += X移動量;
515  this->minY += Y移動量;
516  this->maxX += X移動量;
517  this->maxY += Y移動量;
518  }
519 
520  void Draw(Color 描画色, int 透過率, Camera *座標変換Camera = 0) const
521  {
522  Screen::SetBlendMode(BlendMode::Alpha, 透過率);
523  if( 座標変換Camera )
524  {
525  Drawing::Line((int)座標変換Camera->TransX(xA), (int)座標変換Camera->TransY(yA), (int)座標変換Camera->TransX(xB), (int)座標変換Camera->TransY(yB), 描画色, (int)(座標変換Camera->GetZoom()));
526  Drawing::Circle((int)座標変換Camera->TransX(xA), (int)座標変換Camera->TransX(yA), (int)(thickHarf*座標変換Camera->GetZoom()), 描画色, true);
527  Drawing::Circle((int)座標変換Camera->TransX(xB), (int)座標変換Camera->TransX(yB), (int)(thickHarf*座標変換Camera->GetZoom()), 描画色, true);
528  }
529  else
530  {
531  Drawing::Line((int)xA, (int)yA, (int)xB, (int)yB, 描画色, (int)thick);
532  Drawing::Circle((int)xA, (int)yA, (int)thickHarf, 描画色, true);
533  Drawing::Circle((int)xB, (int)yB, (int)thickHarf, 描画色, true);
534  }
535  Screen::SetBlendMode(BlendMode::NoBlend, 透過率);
536  }
537 
538  double GetXA() const
539  {
540  return xA;
541  }
542 
543  double GetYA() const
544  {
545  return yA;
546  }
547 
548  double GetXB() const
549  {
550  return xB;
551  }
552 
553  double GetYB() const
554  {
555  return yB;
556  }
557 
558  double GetThick() const
559  {
560  return thick;
561  }
562 
563  void SetThick(double 太さ)
564  {
565  thick = 太さ;
566  thickHarf = int(thick / 2);
567  thickPow = int(thick * thick / 4);
568  }
569 
570  double GetAngle() const
571  {
572  return this->angle;
573  }
574 
575  double GetLength() const
576  {
577  return this->lengthA + this->lengthB;
578  }
579 
580  double GetThickHarf() const
581  {
582  return this->thickHarf;
583  }
584 
585  double GetThickPow() const
586  {
587  return this->thickPow;
588  }
589 
590  double GetMinX() const
591  {
592  return minX;
593  }
594 
595  double GetMinY() const
596  {
597  return minY;
598  }
599 
600  double GetMaxX() const
601  {
602  return maxX;
603  }
604 
605  double GetMaxY() const
606  {
607  return maxY;
608  }
609 
610  bool Hit(const Shape *shape) const
611  {
612  return shape->Hit( this );
613  }
614  bool Hit(const Complex *complex) const
615  {
616  for( auto it : complex->shapes )
617  {
618  if( it->Hit( this ) ) return true;
619  }
620  return false;
621  }
622  bool Hit(const Point *point) const
623  {
624  return LinePoint( point->GetX() , point->GetY() , this->GetThick() );
625  }
626  bool Hit(const Line *line) const
627  {
628  //四角形でラフチェック
629  if( RectRect(this->GetXA() - this->GetThickHarf() ,this->GetYA() - this->GetThickHarf() , this->GetXB() - line->GetThickHarf() , this->GetYB() - line->GetThickHarf() ,
630  line->GetXA() - this->GetThickHarf() ,line->GetYA() - this->GetThickHarf() , line->GetXB() - line->GetThickHarf() , line->GetYB() - line->GetThickHarf() ) )
631  {
632  return true;
633  }
634  //交差チェック
635  if( LineLine(this->GetXA() ,this->GetYA() ,this->GetXB() ,this->GetYB() ,line->GetXA(),line->GetYA(),line->GetXB(),line->GetYB() ) )
636  {
637  return true;
638  }
639  //線と端のチェック
640  //線が点になっているかで分ける
641  if( this->GetLength() != 0)
642  {
643  if( this->LinePoint( line->GetXA() , line->GetYA() , this->GetThickHarf() + line->GetThickHarf() ) ) return true;
644  if( this->LinePoint( line->GetXB() , line->GetYB() , this->GetThickHarf() + line->GetThickHarf() ) ) return true;
645  }
646  if( line->GetLength() != 0 )
647  {
648  if( line->LinePoint( this->GetXA() , this->GetYA() , this->GetThickHarf() + line->GetThickHarf() ) ) return true;
649  if( line->LinePoint( this->GetXB() , this->GetYB() , this->GetThickHarf() + line->GetThickHarf() ) ) return true;
650  }
651 
652  return false;
653  }
654  bool Hit(const Rect *rect) const;
655  bool Hit(const Circle *circle) const;
656 
658  bool LinePoint(double px , double py , double range ) const
659  {
660  //点同士の距離
661  const double dx = GetXB() - GetXA();
662  const double dy = GetYB() - GetYA();
663 
664  const double a = dx * dx + dy * dy;
665  const double b = dx *(GetXA() - px) + dy *(GetYA() - py);
666 
667  //点の場合
668  if (a == 0)
669  {
670  if(
671  ( GetXA() - px ) *( GetXA() - px ) +
672  ( GetYA() - py ) *( GetYA() - py )
673  < range * range ) return true;
674  return false;
675  }
676 
677  const double t = -b / a;
678 
679  const double tx = GetXA() + dx*t;
680  const double ty = GetYA() + dy*t;
681 
682  //線分上の点が範囲内かチェック
683  if ( tx < minX || tx > maxX || ty < minY || ty > maxY)
684  {
685  if (
686  (xA - px) * (xA - px) + (yA - py) * (yA - py) > range * range &&
687  (xB - px) * (xB - px) + (yB - py) * (yB - py) > range * range
688  )
689  {
690  return false;
691  }
692  }
693 
694  const double d = (px - tx)*(px - tx) + (py - ty) * (py - ty);
695 
696  return (d < range * range);
697  }
698 };
699 
702 class Rect : public Shape
703 {
704 public:
705  double x;
706  double y;
707 
708  double widthLeft;
709  double widthRight;
710 
711  double heightUp;
712  double heightDown;
713 
714  Rect(double X座標,double Y座標,double 幅 ,double 高さ):
715  x(X座標),
716  y(Y座標),
717  heightUp( 高さ/2 ),
718  heightDown( 高さ/2 ),
719  widthLeft( 幅/2 ),
720  widthRight( 幅/2 )
721  {}
722 
723  Rect(double X座標,double Y座標,double 幅 ,double 高さ , double X中心 , double Y中心):
724  x(X座標),
725  y(Y座標),
726  heightUp( Y中心 ),
727  heightDown( 高さ-Y中心 ),
728  widthLeft( X中心 ),
729  widthRight( 幅-X中心 )
730  {}
731 
732  virtual Shape* Clone(double X座標,double Y座標) const
733  {
734  auto shape = new Rect( X座標 , Y座標 , GetW() , GetH() , widthLeft , heightUp );
735  shape->zoomX = this->zoomX;
736  shape->zoomY = this->zoomY;
737  return shape;
738  }
739 
740  void SetPos(double X座標 , double Y座標)
741  {
742  this->x = X座標;
743  this->y = Y座標;
744  }
745 
746  void Move(double X移動量 , double Y移動量 )
747  {
748  this->x += X移動量;
749  this->y += Y移動量;
750  }
751 
752  void MultiZoom(double X倍率 , double Y倍率)
753  {
754  widthLeft *= X倍率;
755  widthRight *= X倍率;
756 
757  heightUp *= Y倍率;
758  heightDown *= Y倍率;
759  }
760 
761  void Rotate(double 回転する角度){}
762 
763  void SetAngle(double 指定角度){}
764 
765  void Draw( Color 描画色 , int 透過率 , Camera *座標変換Camera = nullptr) const
766  {
767  Screen::SetBlendMode(BlendMode::Alpha, 透過率);
768  if (座標変換Camera)
769  {
771  (
772  (int)座標変換Camera->TransX(x - widthLeft),
773  (int)座標変換Camera->TransY(y - heightUp),
774  (int)(座標変換Camera->GetZoom() * GetW() ),
775  (int)(座標変換Camera->GetZoom() * GetH() ),
776  描画色 ,
777  true
778  );
779  }
780  else
781  {
783  (
784  (int)( x - widthLeft),
785  (int)( y - heightUp),
786  (int) GetW() ,
787  (int) GetH() ,
788  描画色 ,
789  true
790  );
791  }
792  Screen::SetBlendMode(BlendMode::NoBlend, 透過率);
793  }
794 
795  inline double GetX() const
796  {
797  return x;
798  }
799 
800  inline double GetY() const
801  {
802  return y;
803  }
804 
805  inline double GetW() const
806  {
807  return widthLeft + widthRight;
808  }
809 
810  inline double GetH() const
811  {
812  return heightUp + heightDown;
813  }
814 
815  inline double GetLeft() const
816  {
817  return x - widthLeft;
818  }
819 
820  inline double GetTop() const
821  {
822  return y - heightUp;
823  }
824 
825  inline double GetRight() const
826  {
827  return x + widthRight;
828  }
829 
830  inline double GetBottom() const
831  {
832  return y + heightDown;
833  }
834 
835  bool Hit(const Shape *shape) const
836  {
837  return shape->Hit( this );
838  }
839  bool Hit(const Complex *complex) const
840  {
841  for( auto it : complex->shapes )
842  {
843  if( it->Hit( this ) ) return true;
844  }
845  return false;
846  }
847  bool Hit(const Point *point) const
848  {
849  return (
850  (
851  point->x < this->GetRight()
852  ) && (
853  point->x > this->GetLeft()
854  ) && (
855  point->y < this->GetBottom()
856  ) && (
857  point->y > this->GetTop()
858  )
859  );
860  }
861  bool Hit(const Line *line) const
862  {
863  if (
864  !(
865  line->GetMaxX() + line->GetThickHarf() < this->GetLeft() ||
866  line->GetMinX() - line->GetThickHarf() > this->GetTop() ||
867  line->GetMaxY() + line->GetThickHarf() < this->GetRight() ||
868  line->GetMinY() - line->GetThickHarf() > this->GetBottom()
869  )
870  )
871  {
872  return false;
873  }
874 
875  //√2/2≒0.7
876  if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
877  , 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) ))
878  {
879  return true;
880  }
881 
882  if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
883  , 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) ))
884  {
885  return true;
886  }
887 
888  //端の丸い所以外判定
889  if(
890  line->GetXA() + line->GetThickHarf() > this->GetLeft() && line->GetXA() - line->GetThickHarf() < this->GetRight() &&
891  line->GetYA() + line->GetThickHarf() > this->GetTop() && line->GetYA() - line->GetThickHarf() < this->GetBottom()
892  )
893  {
894  //端の丸い所判定
895  if( line->GetXA() < this->GetLeft() && line->GetYA() < this->GetTop() )
896  {//左上
897 
898  if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
899  (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
900 
901  }
902  else if( line->GetXA() > this->GetRight() && line->GetYA() < this->GetTop() )
903  {//右上
904 
905  if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
906  (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
907 
908  }
909  else if( line->GetXA() < this->GetLeft() && line->GetYA() > this->GetBottom() )
910  {//左下
911 
912  if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
913  (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
914 
915  }
916  else if( line->GetXA() > this->GetRight() && line->GetYA() > this->GetBottom() )
917  {//右下
918 
919  if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
920  (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
921 
922  }
923  else
924  {
925  return true;
926  }
927  }
928 
929  if(
930  line->GetXB() + line->GetThickHarf() > this->GetLeft() && line->GetXB() - line->GetThickHarf() < this->GetRight() &&
931  line->GetYB() + line->GetThickHarf() > this->GetTop() && line->GetYB() - line->GetThickHarf() < this->GetBottom()
932  )
933  {
934  //端の丸い所判定
935  if( line->GetXB() < this->GetLeft() && line->GetYB() < this->GetTop() )
936  {//左上
937  if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
938  (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
939 
940  }
941  else if( line->GetXB() > this->GetRight() && line->GetYB() < this->GetTop() )
942  {//右上
943 
944  if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
945  (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
946 
947  }
948  else if( line->GetXB() < this->GetLeft() && line->GetYB() > this->GetBottom() )
949  {//左下
950 
951  if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
952  (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
953 
954  }
955  else if( line->GetXB() > this->GetRight() && line->GetYB() > this->GetBottom() )
956  {//右下
957  if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
958  (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
959 
960  }
961  else
962  {
963  return true;
964  }
965  }
966 
967  return false;
968  }
969  bool Hit(const Rect *rect) const
970  {
971  return !(GetRight() < rect->GetLeft() || GetLeft() > rect->GetRight() || GetBottom() < rect->GetTop() || GetTop() > rect->GetBottom() );
972  }
973  bool Hit(const Circle *circle) const;
974 };
975 
978 class Circle : public Shape
979 {
980 public:
981  double x;
982  double y;
983  double radius;
984 
985  Circle( double X座標 , double Y座標 , double 半径):
986  x(X座標),
987  y(Y座標),
988  radius(半径)
989  {}
990 
991  Shape* Clone(double X座標,double Y座標) const
992  {
993  auto shape = new Circle( X座標 , Y座標 , this->radius );
994  shape->zoomX = this->zoomX;
995  shape->zoomY = this->zoomY;
996  return shape;
997  }
998 
999  void SetPos(double X座標 , double Y座標 )
1000  {
1001  this->x = X座標;
1002  this->y = Y座標;
1003  }
1004 
1005  void MultiZoom(double 倍率X , double 倍率Y)
1006  {
1007  this->radius *= 倍率X;
1008 
1009  zoomX *= 倍率X;
1010  zoomY *= 倍率Y;
1011  }
1012 
1013  void Rotate(double 回転する角度){}
1014 
1015  void SetAngle(double 指定角度){}
1016 
1017  void Move(double X移動量 , double Y移動量 )
1018  {
1019  this->x += X移動量;
1020  this->y += Y移動量;
1021  }
1022 
1023  double GetX() const
1024  {
1025  return int(x);
1026  }
1027 
1028  double GetY() const
1029  {
1030  return int(y);
1031  }
1032 
1033  double GetW() const
1034  {
1035  return int(radius*2);
1036  }
1037 
1038  double GetH() const
1039  {
1040  return int(radius*2);
1041  }
1042 
1043  void Draw( Color 描画色 , int 透過率 , Camera *座標変換Camera = 0) const
1044  {
1045  Screen::SetBlendMode(BlendMode::Alpha, 透過率);
1046  if( 座標変換Camera )
1047  {
1048  Drawing::Circle( (int)座標変換Camera->TransX(x) , (int)座標変換Camera->TransY(y) , (int)(radius * 座標変換Camera->GetZoom()) , 描画色 , true );
1049  }
1050  else
1051  {
1052  Drawing::Circle( (int)x , (int)y , (int)radius , 描画色 , true );
1053  }
1054  Screen::SetBlendMode(BlendMode::NoBlend, 透過率);
1055 
1056  }
1057 
1058  bool Hit(const Shape *shape) const
1059  {
1060  return shape->Hit( this );
1061  }
1062  bool Hit(const Complex *complex) const
1063  {
1064  for( auto it : complex->shapes )
1065  {
1066  if( it->Hit( this ) ) return true;
1067  }
1068  return false;
1069  }
1070  bool Hit(const Point *point) const
1071  {
1072  return
1073  (
1074  ( point->x - this->x ) * ( point->x - this->x ) +
1075  ( point->y - this->y ) * ( point->y - this->y )
1076  <=
1077  ( this->radius * this->radius )
1078  );
1079  }
1080  bool Hit(const Line *line) const
1081  {
1082  return line->LinePoint( x , y , (line->GetThickHarf() + radius) );
1083  }
1084  bool Hit(const Circle *circle) const
1085  {
1086  return(
1087  (this->x - circle->x) * (this->x - circle->x) +
1088  (this->y - circle->y) * (this->y - circle->y)
1089  <=
1090  (this->radius + circle->radius) * (this->radius + circle->radius)
1091  );
1092  }
1093  bool Hit(const Rect *rect) const
1094  {
1095  return
1096  (
1097  (
1098  (
1099  (
1100  this->x + this->radius >= rect->GetLeft()
1101  )&&(
1102  this->x - this->radius <= rect->GetRight()
1103  )
1104  )&&(
1105  (
1106  this->y >= rect->GetTop()
1107  )&&(
1108  this->y <= rect->GetBottom()
1109  )
1110  )
1111  ) || (
1112  (
1113  (
1114  this->x >= rect->GetLeft()
1115  )&&(
1116  this->x <= rect->GetRight()
1117  )
1118  )&&(
1119  (
1120  this->y + this->radius >= rect->GetTop()
1121  )&&(
1122  this->y - this->radius <= rect->GetBottom()
1123  )
1124  )
1125  ) || (//四角形の四隅と円の判定
1126  (this->x - rect->GetLeft() ) * (this->x - rect->GetLeft() ) +
1127  (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1128  (this->radius * this->radius )
1129  ) || (
1130  (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1131  (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1132  (this->radius * this->radius )
1133  ) || (
1134  (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) +
1135  (this->y - rect->GetBottom()) * (this->y -rect->GetBottom()) <=
1136  (this->radius * this->radius )
1137  ) || (
1138  (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1139  (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <=
1140  (this->radius * this->radius )
1141  )
1142  );
1143  }
1144 };
1145 }
static bool SetBlendMode(BlendMode ブレンドモード, int 設定値)
ブレンド描画のモードを設定.
Definition: Screen.h:136
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:346
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:227
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:340
矩形を表す図形クラス.
Definition: Shape.h:702
virtual void Move(double X移動量, double Y移動量)=0
相対座標で移動.
double GetX() const
X座標を取得.
Definition: Shape.h:795
virtual double GetH() const =0
高さを取得.
double GetW() const
幅を取得.
Definition: Shape.h:805
太さのある線を表す図形クラス.
Definition: Shape.h:387
double GetY() const
Y座標を取得.
Definition: Shape.h:800
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=nullptr) const
描画する.
Definition: Shape.h:765
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:261
double GetW() const
幅を取得.
Definition: Shape.h:330
virtual Shape * Clone(double x, double y) const =0
同じ形の図形を作る.
virtual Shape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:732
double GetY() const
Y座標を取得.
Definition: Shape.h:325
virtual void Rotate(double 回転する角度)=0
回転する.
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:348
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=0) const
描画する.
Definition: Shape.h:520
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=0) const
描画する.
Definition: Shape.h:350
static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円を描画.
Definition: Drawing.h:111
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:740
virtual double GetW() const =0
幅を取得.
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:364
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:763
static int PointPoint(double x1, double y1, double x2, double y2)
二点間の距離を計算.
Definition: Shape.h:79
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:199
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:999
Shape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:300
double GetDirect(Shape *比較対象)
対象との角度を取得.
Definition: Shape.h:138
double GetX() const
X座標を取得.
Definition: Shape.h:207
点を表す図形クラス.
Definition: Shape.h:284
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:314
double GetX() const
X座標を取得.
Definition: Shape.h:320
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:761
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:746
Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:179
Shape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:991
複合図形を表すクラス.
Definition: Shape.h:167
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:237
static bool Rect(int 座標X, int 座標Y, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
左上の座標と大きさを指定して矩形を描画.
Definition: Drawing.h:92
double GetW() const
幅を取得.
Definition: Shape.h:464
void MoveA(double 距離, double 方向)
極座標で移動.
Definition: Shape.h:123
double GetW() const
幅を取得.
Definition: Shape.h:1033
void MultiZoom(double 倍率)
拡大率を掛け算する.
Definition: Shape.h:111
double GetW() const
幅を取得.
Definition: Shape.h:217
double GetX() const
X座標を取得.
Definition: Shape.h:1023
virtual Shape * Clone(double X座標, double Y座標) const
同じ形の図形を作る.
Definition: Shape.h:446
double GetDistance(Shape *比較対象)
対象との相対座標を取得.
Definition: Shape.h:144
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:191
virtual void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=0) const =0
描画する.
色を表すクラス.
Definition: Color.h:7
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:245
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:499
virtual bool Hit(const Shape *shape) const =0
衝突判定.
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=0) const
描画する.
Definition: Shape.h:1043
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:752
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:505
virtual void SetAngle(double 指定角度)=0
角度を指定する.
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:835
static bool Pixel(int 座標X, int 座標Y, Color 色)
指定座標に点を描画.
Definition: Drawing.h:145
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:1058
double GetY() const
Y座標を取得.
Definition: Shape.h:212
double GetY() const
Y座標を取得.
Definition: Shape.h:459
double GetH() const
高さを取得.
Definition: Shape.h:1038
void Draw(Color 描画色, int 透過率, Camera *座標変換Camera=0) const
描画する.
Definition: Shape.h:253
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:308
double GetH() const
高さを取得.
Definition: Shape.h:222
void SetAngle(double 指定角度)
角度を指定する.
Definition: Shape.h:1015
2D用に座標変換を行うカメラを表すクラス.
Definition: Camera.h:16
bool LinePoint(double px, double py, double range) const
線と点の当たり判定.
Definition: Shape.h:658
void Move(double X移動量, double Y移動量)
相対座標で移動.
Definition: Shape.h:1017
double GetH() const
高さを取得.
Definition: Shape.h:335
virtual double GetX() const =0
X座標を取得.
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:1013
double GetX() const
X座標を取得.
Definition: Shape.h:454
virtual void SetPos(double X座標, double Y座標)=0
指定座標に移動.
円を表す図形クラス.
Definition: Shape.h:978
double GetY() const
Y座標を取得.
Definition: Shape.h:1028
位置情報を持つ図形の抽象クラス.
Definition: Shape.h:16
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
線分の交差判定.
Definition: Shape.h:60
void SetPos(double X座標, double Y座標)
指定座標に移動.
Definition: Shape.h:474
virtual double GetY() const =0
Y座標を取得.
void MultiZoom(double X倍率, double Y倍率)
縦横別で拡大率を掛け算する.
Definition: Shape.h:481
void MultiZoom(double 倍率X, double 倍率Y)
縦横別で拡大率を掛け算する.
Definition: Shape.h:1005
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: Shape.h:23
static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
始点と終点を結ぶ直線を描画.
Definition: Drawing.h:85
void Rotate(double 回転する角度)
回転する.
Definition: Shape.h:493
double GetH() const
高さを取得.
Definition: Shape.h:469
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:610
void SetZoom(double X拡大率, double Y拡大率)
拡大率を設定.
Definition: Shape.h:105
double GetH() const
高さを取得.
Definition: Shape.h:810