SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Shape.h
1 #pragma once
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 
15 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 rgb , int transRate , Camera *camera = 0) const = 0;
130 
132  virtual void Rotate(double angle) = 0;
133 
135  virtual void SetAngle(double angle) = 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 
166 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 mX , double mY)
200  {
201  for( auto it: shapes )
202  {
203  it->Move( mX , mY );
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 rateX , double rateY)
228  {
229  for( auto it: shapes )
230  {
231  it->MultiZoom( rateX , rateY );
232  }
233  zoomX *= rateX;
234  zoomY *= rateY;
235  }
236 
237  void Rotate(double angle)
238  {
239  for( auto it: shapes )
240  {
241  it->Rotate( angle );
242  }
243  }
244 
245  void SetAngle(double angle)
246  {
247  for( auto it: shapes )
248  {
249  it->SetAngle( angle );
250  }
251  }
252 
253  void Draw( Color rgb , int transRate , Camera *camera = 0) const
254  {
255  for( auto it: shapes )
256  {
257  it->Draw( rgb , transRate , 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 
283 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  return new Point( x , y );
303  }
304 
305  void SetPos(double x , double y)
306  {
307  this->x = x;
308  this->y = y;
309  }
310 
311  void Move(double mX , double mY)
312  {
313  this->x += mX;
314  this->y += mY;
315  }
316 
317  double GetX() const
318  {
319  return x;
320  }
321 
322  double GetY() const
323  {
324  return y;
325  }
326 
327  double GetW() const
328  {
329  return 1;
330  }
331 
332  double GetH() const
333  {
334  return 1;
335  }
336 
337  void MultiZoom(double rateX , double rateY)
338  {
339  zoomX *= rateX;
340  zoomY *= rateY;
341  }
342 
343  void Rotate(double angle){}
344 
345  void SetAngle(double angle){}
346 
347  void Draw( Color rgb , int transRate , Camera *camera = 0) const
348  {
349  Screen::SetBlendMode(BlendMode::Alpha, transRate);
350  if( camera )
351  {
352  Drawing::Pixel((int)camera->TransX(x), (int)camera->TransY(y), rgb);
353  }
354  else
355  {
356  Drawing::Pixel((int)x, (int)y, rgb);
357  }
358  Screen::SetBlendMode(BlendMode::NoBlend, transRate);
359  }
360 
361  bool Hit(const Shape *shape) const
362  {
363  return shape->Hit( this );
364  }
365  bool Hit(const Complex *complex) const
366  {
367  for( auto it : complex->shapes )
368  {
369  if( it->Hit( this ) ) return true;
370  }
371  return false;
372  }
373  bool Hit(const Point *point) const
374  {
375  return ( point->x == this->x && point->y == this->y );
376  }
377  bool Hit(const Line *line) const;
378  bool Hit(const Rect *rect) const;
379  bool Hit(const Circle *circle) const;
380 };
381 
383 class Line : public Shape
385 {
386 private:
387  virtual void CulParam()
388  {
389  CulLine();
390  }
391 
392  void CulLine()
393  {
394  this->xA = x + cos( angle ) * lengthA;
395  this->yA = y + sin( angle ) * lengthA;
396  this->xB = x - cos( angle ) * lengthB;
397  this->yB = y - sin( angle ) * lengthB;
398  this->width = int(abs(this->xB - this->xA));
399  this->height = int(abs(this->yB - this->yA));
400  this->thickHarf = int(this->thick / 2);
401  this->thickPow = int(this->thick * this->thick / 4);
402  this->minX = int( this->xA < this->xB ? this->xA:this->xB );
403  this->maxX = int( this->xA > this->xB ? this->xA:this->xB );
404  this->minY = int( this->yA < this->yB ? this->yA:this->yB );
405  this->maxY = int( this->yA > this->yB ? this->yA:this->yB );
406  }
407 
408  double x;
409  double y;
410  double xA;
411  double yA;
412  double xB;
413  double yB;
414  double thick;//半径
415 
416  double angle;//角度
417 
418  double lengthA;
419  double lengthB;
420 
421  double width;
422  double height;
423  double thickHarf;//半径の二条
424  double thickPow;
425  double minX;
426  double minY;
427  double maxX;
428  double maxY;
429 
430 public:
431 
432  Line( double x , double y , double angle , double length , double thick):
433  x(x),
434  y(y),
435  angle(angle),
436  lengthA( length/2 ),
437  lengthB( length/2 ),
438  thick( thick )
439  {
440  this->CulLine();
441  }
442 
443  virtual Shape* Clone(double x,double y) const
444  {
445  return new Line( x , y , this->angle , this->lengthA , this->thick);
446  }
447 
448  double GetX() const
449  {
450  return x;
451  }
452 
453  double GetY() const
454  {
455  return y;
456  }
457 
458  double GetW() const
459  {
460  return int(xA - xB);
461  }
462 
463  double GetH() const
464  {
465  return int(yA - yB);
466  }
467 
468  void SetPos(double x , double y )
469  {
470  this->x = x;
471  this->y = y;
472  this->CulParam();
473  }
474 
475  void MultiZoom(double rateX , double rateY)
476  {
477  this->lengthA *= rateX;
478  this->lengthB *= rateY;
479  this->thick *= rateX;
480 
481  this->CulParam();
482 
483  zoomX *= rateX;
484  zoomY *= rateY;
485  }
486 
487  void Rotate(double angle)
488  {
489  this->angle += angle;
490  this->CulParam();
491  }
492 
493  void SetAngle(double angle)
494  {
495  this->angle = angle;
496  this->CulParam();
497  }
498 
499  void Move(double mX , double mY )
500  {
501  this->x += mX;
502  this->y += mY;
503  this->xA += mX;
504  this->yA += mY;
505  this->xB += mX;
506  this->yB += mY;
507 
508  this->minX += mX;
509  this->minY += mY;
510  this->maxX += mX;
511  this->maxY += mY;
512  }
513 
514  void Draw( Color rgb , int transRate , Camera *camera = 0 ) const
515  {
516  Screen::SetBlendMode(BlendMode::Alpha, transRate);
517  if( camera )
518  {
519  Drawing::Line((int)camera->TransX(xA), (int)camera->TransY(yA), (int)camera->TransX(xB), (int)camera->TransY(yB), rgb, (int)(camera->GetZoom()));
520  Drawing::Circle((int)camera->TransX(xA), (int)camera->TransX(yA), (int)(thickHarf*camera->GetZoom()), rgb, true);
521  Drawing::Circle((int)camera->TransX(xB), (int)camera->TransX(yB), (int)(thickHarf*camera->GetZoom()), rgb, true);
522  }
523  else
524  {
525  Drawing::Line((int)xA, (int)yA, (int)xB, (int)yB, rgb, (int)thick);
526  Drawing::Circle((int)xA, (int)yA, (int)thickHarf, rgb, true);
527  Drawing::Circle((int)xB, (int)yB, (int)thickHarf, rgb, true);
528  }
529  Screen::SetBlendMode(BlendMode::NoBlend, transRate);
530  }
531 
532  double GetXA() const
533  {
534  return xA;
535  }
536 
537  double GetYA() const
538  {
539  return yA;
540  }
541 
542  double GetXB() const
543  {
544  return xB;
545  }
546 
547  double GetYB() const
548  {
549  return yB;
550  }
551 
552  double GetThick() const
553  {
554  return thick;
555  }
556 
557  void SetThick(double thick)
558  {
559  this->thick = thick;
560  this->thickHarf = int(this->thick / 2);
561  this->thickPow = int(this->thick * this->thick / 4);
562  }
563 
564  double GetAngle() const
565  {
566  return this->angle;
567  }
568 
569  void MoveAngle(double angle)
570  {
571  this->angle += angle;
572  this->CulParam();
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->GetThickPow() );
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()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
644  if( this->LinePoint( line->GetXB() , line->GetYB() , (this->GetThickHarf() + line->GetThickHarf()) * (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()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
649  if( line->LinePoint( this->GetXB() , this->GetYB() , (this->GetThickHarf() + line->GetThickHarf()) * (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  const double dx = GetXB() - GetXA();
661  const double dy = GetYB() - GetYA();
662 
663  const double a = dx * dx + dy * dy;
664  const double b = dx *(GetXA() - px) + dy *(GetYA() - py);
665 
666  //点の場合
667  if (a == 0)
668  {
669  if(
670  ( GetXA() - px ) *( GetXA() - px ) +
671  ( GetYA() - py ) *( GetYA() - py )
672  < range ) return true;
673  return false;
674  }
675 
676  const double t = -b / a;
677 
678  const double tx = GetXA() + dx*t;
679  const double ty = GetYA() + dy*t;
680 
681  const double d = (px - tx)*(px - tx) + (py - ty) * (py - ty);
682 
683  return (d < range);
684  }
685 };
686 
688 class Rect : public Shape
690 {
691 public:
692  double x;
693  double y;
694 
695  double upLength;
696  double downLength;
697  double leftLength;
698  double rightLength;
699 
700  Rect(double x,double y,double width,double height):
701  x(x),
702  y(y),
703  upLength( height/2 ),
704  downLength( height/2 ),
705  leftLength( width/2 ),
706  rightLength( width/2 )
707  {}
708 
709  virtual Shape* Clone(double x,double y) const
710  {
711  return new Rect( x , y , GetW() , GetH() );
712  }
713 
714  void SetPos(double x , double y)
715  {
716  this->x = x;
717  this->y = y;
718  }
719 
720  void Move(double mX , double mY )
721  {
722  this->x += mX;
723  this->y += mY;
724  }
725 
726  void MultiZoom(double rateX , double rateY)
727  {
728  upLength *= rateY;
729  downLength *= rateY;
730  leftLength *= rateX;
731  rightLength *= rateX;
732 
733  zoomX *= rateX;
734  zoomY *= rateY;
735  }
736 
737  void Rotate(double angle)
738  {
739  }
740 
741  void SetAngle(double angle)
742  {
743  }
744 
745  void Draw( Color rgb , int transRate , Camera *camera = nullptr) const
746  {
747  Screen::SetBlendMode(BlendMode::Alpha, transRate);
748  if( camera )
749  {
751  (
752  (int)camera->TransX(x - leftLength) ,
753  (int)camera->TransY(y - upLength) ,
754  (int)camera->TransX(x + rightLength) ,
755  (int)camera->TransY(y + downLength) ,
756  rgb ,
757  true
758  );
759  }
760  else
761  {
763  (
764  (int)( x - leftLength ) ,
765  (int)( y - upLength ) ,
766  (int)( x + rightLength ) ,
767  (int)( y + downLength) ,
768  rgb ,
769  true
770  );
771  }
772  Screen::SetBlendMode(BlendMode::NoBlend, transRate);
773  }
774 
775  double GetX() const
776  {
777  return x;
778  }
779 
780  double GetY() const
781  {
782  return y;
783  }
784 
785  double GetW() const
786  {
787  return upLength + downLength;
788  }
789 
790  double GetH() const
791  {
792  return leftLength + rightLength;
793  }
794 
795  virtual double GetLeft() const
796  {
797  return int(x - leftLength);
798  }
799 
800  virtual double GetTop() const
801  {
802  return int(y - upLength);
803  }
804 
805  virtual double GetRight() const
806  {
807  return int(x + rightLength);
808  }
809 
810  virtual double GetBottom() const
811  {
812  return int(y + downLength);
813  }
814 
815  bool Hit(const Shape *shape) const
816  {
817  return shape->Hit( this );
818  }
819  bool Hit(const Complex *complex) const
820  {
821  for( auto it : complex->shapes )
822  {
823  if( it->Hit( this ) ) return true;
824  }
825  return false;
826  }
827  bool Hit(const Point *point) const
828  {
829  return (
830  (
831  point->x < this->GetRight()
832  ) && (
833  point->x > this->GetLeft()
834  ) && (
835  point->y < this->GetBottom()
836  ) && (
837  point->y > this->GetTop()
838  )
839  );
840  }
841  bool Hit(const Line *line) const
842  {
843  if( ! RectRect
844  (
845  line->GetMinX() - line->GetThickHarf(),
846  line->GetMinY() - line->GetThickHarf(),
847  line->GetMaxX() + line->GetThickHarf(),
848  line->GetMaxY() + line->GetThickHarf(),
849  this->GetLeft(),
850  this->GetTop(),
851  this->GetRight(),
852  this->GetBottom()
853  )
854  )
855  {
856  return false;
857  }
858 
859  //√2/2≒0.7
860 
861  if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
862  , 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) ))
863  {
864  return true;
865  }
866 
867  if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
868  , 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) ))
869  {
870  return true;
871  }
872 
873  //端の丸い所以外判定
874  if(
875  line->GetXA() + line->GetThickHarf() > this->GetLeft() && line->GetXA() - line->GetThickHarf() < this->GetRight() &&
876  line->GetYA() + line->GetThickHarf() > this->GetTop() && line->GetYA() - line->GetThickHarf() < this->GetBottom()
877  )
878  {
879  //端の丸い所判定
880  if( line->GetXA() < this->GetLeft() && line->GetYA() < this->GetTop() )
881  {//左上
882 
883  if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
884  (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
885 
886  }
887  else if( line->GetXA() > this->GetRight() && line->GetYA() < this->GetTop() )
888  {//右上
889 
890  if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
891  (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
892 
893  }
894  else if( line->GetXA() < this->GetLeft() && line->GetYA() > this->GetBottom() )
895  {//左下
896 
897  if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
898  (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
899 
900  }
901  else if( line->GetXA() > this->GetRight() && line->GetYA() > this->GetBottom() )
902  {//右下
903 
904  if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
905  (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
906 
907  }
908  else
909  {
910  return true;
911  }
912  }
913 
914  if(
915  line->GetXB() + line->GetThickHarf() > this->GetLeft() && line->GetXB() - line->GetThickHarf() < this->GetRight() &&
916  line->GetYB() + line->GetThickHarf() > this->GetTop() && line->GetYB() - line->GetThickHarf() < this->GetBottom()
917  )
918  {
919  //端の丸い所判定
920  if( line->GetXB() < this->GetLeft() && line->GetYB() < this->GetTop() )
921  {//左上
922  if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
923  (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
924 
925  }
926  else if( line->GetXB() > this->GetRight() && line->GetYB() < this->GetTop() )
927  {//右上
928 
929  if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
930  (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
931 
932  }
933  else if( line->GetXB() < this->GetLeft() && line->GetYB() > this->GetBottom() )
934  {//左下
935 
936  if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
937  (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
938 
939  }
940  else if( line->GetXB() > this->GetRight() && line->GetYB() > this->GetBottom() )
941  {//右下
942  if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
943  (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
944 
945  }
946  else
947  {
948  return true;
949  }
950  }
951 
952  return false;
953  }
954  bool Hit(const Rect *rect) const
955  {
956  return RectRect
957  (
958  this->GetLeft() , this->GetTop() , this->GetRight() , this->GetBottom() ,
959  rect->GetLeft() , rect->GetTop() , rect->GetRight() , rect->GetBottom()
960  );
961  }
962  bool Hit(const Circle *circle) const;
963 };
964 
966 class Circle : public Shape
968 {
969 public:
970  double x;
971  double y;
972  double radius;
973 
974  Circle( double x , double y , double radius):
975  x(x),
976  y(y),
977  radius(radius)
978  {}
979 
980  Shape* Clone(double x,double y) const
981  {
982  return new Circle( x , y , this->radius );
983  }
984 
985  void SetPos(double x , double y )
986  {
987  this->x = x;
988  this->y = y;
989  }
990 
991  void MultiZoom(double rateX , double rateY)
992  {
993  this->radius *= rateX;
994 
995  zoomX *= rateX;
996  zoomY *= rateY;
997  }
998 
999  void Rotate(double angle){}
1000 
1001  void SetAngle(double angle){}
1002 
1003  void Move(double mX , double mY )
1004  {
1005  this->x += mX;
1006  this->y += mY;
1007  }
1008 
1009  double GetX() const
1010  {
1011  return int(x);
1012  }
1013 
1014  double GetY() const
1015  {
1016  return int(y);
1017  }
1018 
1019  double GetW() const
1020  {
1021  return int(radius*2);
1022  }
1023 
1024  double GetH() const
1025  {
1026  return int(radius*2);
1027  }
1028 
1029  void Draw( Color rgb , int transRate , Camera *camera = 0) const
1030  {
1031  Screen::SetBlendMode(BlendMode::Alpha, transRate);
1032  if( camera )
1033  {
1034  Drawing::Circle( (int)camera->TransX(x) , (int)camera->TransY(y) , (int)(radius * camera->GetZoom()) , rgb , true );
1035  }
1036  else
1037  {
1038  Drawing::Circle( (int)x , (int)y , (int)radius , rgb , true );
1039  }
1040  Screen::SetBlendMode(BlendMode::NoBlend, transRate);
1041 
1042  }
1043 
1044  bool Hit(const Shape *shape) const
1045  {
1046  return shape->Hit( this );
1047  }
1048  bool Hit(const Complex *complex) const
1049  {
1050  for( auto it : complex->shapes )
1051  {
1052  if( it->Hit( this ) ) return true;
1053  }
1054  return false;
1055  }
1056  bool Hit(const Point *point) const
1057  {
1058  return
1059  (
1060  ( point->x - this->x ) * ( point->x - this->x ) +
1061  ( point->y - this->y ) * ( point->y - this->y )
1062  <=
1063  ( this->radius * this->radius )
1064  );
1065  }
1066  bool Hit(const Line *line) const
1067  {
1068  return line->LinePoint( x , y , (line->GetThickHarf() + radius) * (line->GetThickHarf() + radius) );
1069  }
1070  bool Hit(const Circle *circle) const
1071  {
1072  return(
1073  (this->x - circle->x) * (this->x - circle->x) +
1074  (this->y - circle->y) * (this->y - circle->y)
1075  <=
1076  (this->radius + circle->radius) * (this->radius + circle->radius)
1077  );
1078  }
1079  bool Hit(const Rect *rect) const
1080  {
1081  return
1082  (
1083  (
1084  (
1085  (
1086  this->x + this->radius >= rect->GetLeft()
1087  )&&(
1088  this->x - this->radius <= rect->GetRight()
1089  )
1090  )&&(
1091  (
1092  this->y >= rect->GetTop()
1093  )&&(
1094  this->y <= rect->GetBottom()
1095  )
1096  )
1097  ) || (
1098  (
1099  (
1100  this->x >= rect->GetLeft()
1101  )&&(
1102  this->x <= rect->GetRight()
1103  )
1104  )&&(
1105  (
1106  this->y + this->radius >= rect->GetTop()
1107  )&&(
1108  this->y - this->radius <= rect->GetBottom()
1109  )
1110  )
1111  ) || (//四角形の四隅と円の判定
1112  (this->x - rect->GetLeft() ) * (this->x - rect->GetLeft() ) +
1113  (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1114  (this->radius * this->radius )
1115  ) || (
1116  (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1117  (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1118  (this->radius * this->radius )
1119  ) || (
1120  (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) +
1121  (this->y - rect->GetBottom()) * (this->y -rect->GetBottom()) <=
1122  (this->radius * this->radius )
1123  ) || (
1124  (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1125  (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <=
1126  (this->radius * this->radius )
1127  )
1128  );
1129  }
1130 };
1131 }
void SetPos(double x, double y)
指定座標に移動.
Definition: Shape.h:714
void SetPos(double x, double y)
指定座標に移動.
Definition: Shape.h:985
static bool SetBlendMode(BlendMode ブレンドモード, int 設定値)
ブレンド描画のモードを設定.
Definition: Screen.h:189
矩形を表す図形クラス.
Definition: Shape.h:689
virtual void Move(double X移動量, double Y移動量)=0
相対座標で移動.
double GetX() const
X座標を取得.
Definition: Shape.h:775
virtual double GetH() const =0
高さを取得.
double GetW() const
幅を取得.
Definition: Shape.h:785
太さのある線を表す図形クラス.
Definition: Shape.h:384
double GetY() const
Y座標を取得.
Definition: Shape.h:780
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:261
double GetW() const
幅を取得.
Definition: Shape.h:327
virtual Shape * Clone(double x, double y) const =0
同じ形の図形を作る.
double GetY() const
Y座標を取得.
Definition: Shape.h:322
void SetAngle(double angle)
角度を指定する.
Definition: Shape.h:345
void MultiZoom(double rateX, double rateY)
縦横別で拡大率を掛け算する.
Definition: Shape.h:726
static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円を描画.
Definition: Drawing.h:72
virtual double GetW() const =0
幅を取得.
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:361
static int PointPoint(double x1, double y1, double x2, double y2)
二点間の距離を計算.
Definition: Shape.h:79
double GetDirect(Shape *比較対象)
対象との角度を取得.
Definition: Shape.h:138
double GetX() const
X座標を取得.
Definition: Shape.h:207
点を表す図形クラス.
Definition: Shape.h:284
void Move(double mX, double mY)
相対座標で移動.
Definition: Shape.h:720
double GetX() const
X座標を取得.
Definition: Shape.h:317
void SetPos(double x, double y)
指定座標に移動.
Definition: Shape.h:191
Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:179
virtual void Rotate(double angle)=0
回転する.
複合図形を表すクラス.
Definition: Shape.h:167
void Move(double mX, double mY)
相対座標で移動.
Definition: Shape.h:199
Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:980
void Draw(Color rgb, int transRate, Camera *camera=0) const
描画する.
Definition: Shape.h:1029
double GetW() const
幅を取得.
Definition: Shape.h:458
void MoveA(double 距離, double 方向)
極座標で移動.
Definition: Shape.h:123
double GetW() const
幅を取得.
Definition: Shape.h:1019
void MultiZoom(double 倍率)
拡大率を掛け算する.
Definition: Shape.h:111
double GetW() const
幅を取得.
Definition: Shape.h:217
double GetX() const
X座標を取得.
Definition: Shape.h:1009
double GetDistance(Shape *比較対象)
対象との相対座標を取得.
Definition: Shape.h:144
void Move(double mX, double mY)
相対座標で移動.
Definition: Shape.h:1003
void Rotate(double angle)
回転する.
Definition: Shape.h:487
色を表すクラス.
Definition: Color.h:7
void MultiZoom(double rateX, double rateY)
縦横別で拡大率を掛け算する.
Definition: Shape.h:991
virtual bool Hit(const Shape *shape) const =0
衝突判定.
void SetAngle(double angle)
角度を指定する.
Definition: Shape.h:493
void MultiZoom(double rateX, double rateY)
縦横別で拡大率を掛け算する.
Definition: Shape.h:337
void Draw(Color rgb, int transRate, Camera *camera=0) const
描画する.
Definition: Shape.h:514
void SetPos(double x, double y)
指定座標に移動.
Definition: Shape.h:468
void Draw(Color rgb, int transRate, Camera *camera=0) const
描画する.
Definition: Shape.h:253
virtual Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:709
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:815
static bool Pixel(int 座標X, int 座標Y, Color 色)
指定座標に点を描画.
Definition: Drawing.h:112
void MultiZoom(double rateX, double rateY)
縦横別で拡大率を掛け算する.
Definition: Shape.h:227
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:1044
double GetY() const
Y座標を取得.
Definition: Shape.h:212
double GetY() const
Y座標を取得.
Definition: Shape.h:453
double GetH() const
高さを取得.
Definition: Shape.h:1024
double GetH() const
高さを取得.
Definition: Shape.h:222
void Draw(Color rgb, int transRate, Camera *camera=0) const
描画する.
Definition: Shape.h:347
virtual void Draw(Color rgb, int transRate, Camera *camera=0) const =0
描画する.
void Move(double mX, double mY)
相対座標で移動.
Definition: Shape.h:499
2D用に座標変換を行うカメラを表すクラス.
Definition: Camera.h:16
void SetPos(double x, double y)
指定座標に移動.
Definition: Shape.h:305
void SetAngle(double angle)
角度を指定する.
Definition: Shape.h:245
bool LinePoint(double px, double py, double range) const
説明.
Definition: Shape.h:658
static bool Rect(int 座標aX, int 座標aY, int 座標bX, int 座標bY, Color 色, bool 塗りつぶしフラグ)
座標aと座標bを対角の頂点とする矩形を描画.
Definition: Drawing.h:45
double GetH() const
高さを取得.
Definition: Shape.h:332
Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:300
void Rotate(double angle)
回転する.
Definition: Shape.h:343
void Rotate(double angle)
回転する.
Definition: Shape.h:737
virtual double GetX() const =0
X座標を取得.
double GetX() const
X座標を取得.
Definition: Shape.h:448
virtual void SetPos(double X座標, double Y座標)=0
指定座標に移動.
円を表す図形クラス.
Definition: Shape.h:967
virtual void SetAngle(double angle)=0
角度を指定する.
double GetY() const
Y座標を取得.
Definition: Shape.h:1014
位置情報を持つ図形の抽象クラス.
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
virtual double GetY() const =0
Y座標を取得.
void Draw(Color rgb, int transRate, Camera *camera=nullptr) const
描画する.
Definition: Shape.h:745
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: Shape.h:23
virtual Shape * Clone(double x, double y) const
同じ形の図形を作る.
Definition: Shape.h:443
static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
始点と終点を結ぶ直線を描画.
Definition: Drawing.h:34
double GetH() const
高さを取得.
Definition: Shape.h:463
bool Hit(const Shape *shape) const
衝突判定.
Definition: Shape.h:610
void SetAngle(double angle)
角度を指定する.
Definition: Shape.h:741
void SetZoom(double X拡大率, double Y拡大率)
拡大率を設定.
Definition: Shape.h:105
void MultiZoom(double rateX, double rateY)
縦横別で拡大率を掛け算する.
Definition: Shape.h:475
void SetAngle(double angle)
角度を指定する.
Definition: Shape.h:1001
void Rotate(double angle)
回転する.
Definition: Shape.h:999
void Rotate(double angle)
回転する.
Definition: Shape.h:237
double GetH() const
高さを取得.
Definition: Shape.h:790
void Move(double mX, double mY)
相対座標で移動.
Definition: Shape.h:311