DXフレームワーク　リファレンス・マニュアル 0.01 DXフレームワークのリファレンスです。詳細は公式wiki

- メインページ
- 関連ページ
- クラス
- ファイル

- ファイル一覧

Figure.h
1 #pragma once
2 #include<Camera.h>
3 #include<Drawing.h>
4 #include<xutility>
5 #include<vector>
6
7 namespace DXFW
8 {
9 class Figure;
10 class Complex;
11 class Point;
12 class Line;
13 class Circle;
14 class Rect;
15
29 class Figure
30 {
31 protected:
32 double zoomX;
33 double zoomY;
34
36 static bool RectRect( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
37 {
38 //x座標をラフチェック
39 if ( x1 >= x2)
40 {
41 if ((x1 < x3 && x1 < x4) || (x2 > x3 && x2 > x4))
42 {
43 return false;
44 }
45 }
46 else
47 {
48 if ((x2 < x3 && x2 < x4) || (x1 > x3 && x1 > x4))
49 {
50 return false;
51 }
52 }
53 //y座標をラフチェック
54 if (y1 >= y2)
55 {
56 if ((y1 < y3 && y1 < y4) || (y2 > y3 && y2 > y4))
57 {
58 return false;
59 }
60 }
61 else
62 {
63 if ((y2 < y3 && y2 < y4) || (y1 > y3 && y1 > y4))
64 {
65 return false;
66 }
67 }
68
69 return true;
70 }
71
73 static bool LineLine( double x1 , double y1 , double x2 , double y2 , double x3 , double y3 , double x4 , double y4)
74 {
75 //交差判定
76 if ((double(x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
77 (double(x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0)
78 {
79 return false;
80 }
81
82 if ((double(x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)) *
83 (double(x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)) > 0)
84 {
85 return false;
86 }
87 return true;
88
89 }
90
92 static int PointPoint(double x1 , double y1 , double x2 , double y2)
93 {
94 return int((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
95 }
96
97 public:
98 Figure():
99 zoomX(1),
100 zoomY(1)
101 {}
102
104 virtual bool Hit(const Figure *figure) const = 0;
105 virtual bool Hit(const Complex *figure) const = 0;
106 virtual bool Hit(const Point *figure) const = 0;
107 virtual bool Hit(const Line *figure) const = 0;
108 virtual bool Hit(const Rect *figure) const = 0;
109 virtual bool Hit(const Circle *figure) const = 0;
110
112 virtual void SetPos(double x , double y) = 0;
113
115 virtual Figure* Clone(double x , double y) const = 0;
116
118 void SetZoom(double rateX , double rateY)
119 {
120 MultiZoom( rateX / zoomX , rateY / zoomY);
121 }
122
124 virtual void MultiZoom(double rate) = 0;
125
127 virtual void MultiZoom(double rateX , double rateY) = 0;
128
130 virtual void Move(double x , double y) = 0;
131
133 void MoveA(double distance , double angle )
134 {
135 Move( distance * cos(angle) , distance * sin(angle) );
136 }
137
139 virtual void Draw(int rgb , int transRate , Camera *camera = 0) const = 0;
140
142 virtual void Rotate(double angle) = 0;
143
145 virtual void SetAngle(double angle) = 0;
146
148 double GetDirect(Figure* figure)
149 {
150 return atan2( figure->GetY() - this->GetY() , figure->GetX() - this->GetX() );
151 }
152
154 double GetDistance(Figure* figure)
155 {
156 const double xd = this->GetX() - figure->GetX();
157 const double yd = this->GetY() - figure->GetY();
158
159 return sqrt( xd * xd + yd * yd );
160 }
161
163 virtual double GetX() const = 0;
164 virtual double GetY() const = 0;
165 virtual double GetW() const = 0;
166 virtual double GetH() const = 0;
167 };
168
182 class Complex : public Figure
183 {
184 public:
185 std::vector<Figure*> figures;
186
187 Complex(){};
188
189 Complex(Figure *figure)
190 {
191 figures.push_back( figure );
192 }
193
194 Figure* Clone(double x,double y) const
195 {
196 Complex *buf = new Complex();
197
198 for( auto it: figures )
199 {
200 buf->figures.push_back( it );
201 }
202
203 return buf;
204 }
205
206 void SetPos(double x , double y)
207 {
208 for( auto it: figures )
209 {
210 it->SetPos( x , y );
211 }
212 }
213
214 void Move(double mX , double mY)
215 {
216 for( auto it: figures )
217 {
218 it->Move( mX , mY );
219 }
220 }
221
222 double GetX() const
223 {
224 return figures[0]->GetX();
225 }
226
227 double GetY() const
228 {
229 return figures[0]->GetY();
230 }
231
232 double GetW() const
233 {
234 return figures[0]->GetW();
235 }
236
237 double GetH() const
238 {
239 return figures[0]->GetH();
240 }
241
242 void MultiZoom(double rate)
243 {
244 for( auto it: figures )
245 {
246 it->MultiZoom( rate );
247 }
248 }
249
250 void MultiZoom(double rateX , double rateY)
251 {
252 for( auto it: figures )
253 {
254 it->MultiZoom( rateX , rateY );
255 }
256
257 }
258
259 void Rotate(double angle)
260 {
261 for( auto it: figures )
262 {
263 it->Rotate( angle );
264 }
265 }
266
267 void SetAngle(double angle)
268 {
269 for( auto it: figures )
270 {
271 it->SetAngle( angle );
272 }
273 }
274
275 void Draw( int rgb , int transRate , Camera *camera = 0) const
276 {
277 for( auto it: figures )
278 {
279 it->Draw( rgb , transRate , camera );
280 }
281 }
282
283 bool Hit(const Figure *figure) const
284 {
285 return figure->Hit( this );
286 }
287 bool Hit(const Complex *complex) const
288 {
289 for( auto itA : this->figures )
290 {
291 for( auto itB : this->figures )
292 {
293 if( itA->Hit(itB) ) return true;
294 }
295 }
296 return false;
297 }
298 bool Hit(const Point *point) const;
299 bool Hit(const Line *line) const;
300 bool Hit(const Rect *rect) const;
301 bool Hit(const Circle *circle) const;
302 };
303
317 class Point : public Figure
318 {
319 public:
320 double x;
321 double y;
322
323 Point() :
324 x(0),
325 y(0)
326 {};
327
329 Point(double x , double y):
330 x(x),
331 y(y)
332 {}
333
334 Figure* Clone(double x,double y) const
335 {
336 return new Point( x , y );
337 }
338
339 void SetPos(double x , double y)
340 {
341 this->x = x;
342 this->y = y;
343 }
344
345 void Move(double mX , double mY)
346 {
347 this->x += mX;
348 this->y += mY;
349 }
350
351 double GetX() const
352 {
353 return x;
354 }
355
356 double GetY() const
357 {
358 return y;
359 }
360
361 double GetW() const
362 {
363 return 1;
364 }
365
366 double GetH() const
367 {
368 return 1;
369 }
370
371 void MultiZoom(double rate){}
372
373 void MultiZoom(double rateX , double rateY){}
374
375 void Rotate(double angle){}
376
377 void SetAngle(double angle){}
378
379 void Draw( int rgb , int transRate , Camera *camera = 0) const
380 {
381 DxLib::SetDrawBlendMode( 1 , transRate);
382 if( camera )
383 {
384 DxLib::DrawPixel( (int)camera->TranX(x) , (int)camera->TranY(y) , rgb );
385 }
386 else
387 {
388 DxLib::DrawPixel( (int)x , (int)y , rgb );
389 }
390 DxLib::SetDrawBlendMode( 0 , transRate);
391 }
392
393 bool Hit(const Figure *figure) const
394 {
395 return figure->Hit( this );
396 }
397 bool Hit(const Complex *complex) const
398 {
399 for( auto it : complex->figures )
400 {
401 if( it->Hit( this ) ) return true;
402 }
403 return false;
404 }
405 bool Hit(const Point *point) const
406 {
407 return ( point->x == this->x && point->y == this->y );
408 }
409 bool Hit(const Line *line) const;
410 bool Hit(const Rect *rect) const;
411 bool Hit(const Circle *circle) const;
412 };
413
427 class Line : public Figure
428 {
429 private:
430 virtual void CulParam()
431 {
432 CulLine();
433 }
434
435 void CulLine()
436 {
437 this->xA = x + cos( angle ) * lengthA;
438 this->yA = y + sin( angle ) * lengthA;
439 this->xB = x + cos( angle ) * lengthB;
440 this->yB = y + sin( angle ) * lengthB;
441 this->width = int(this->xB - this->xA);
442 this->height = int(this->yB - this->yA);
443 this->thickHarf = int(this->thick / 2);
444 this->thickPow = int(this->thick * this->thick / 4);
445 this->minX = int( this->xA < this->xB ? this->xA:this->xB );
446 this->maxX = int( this->xA > this->xB ? this->xA:this->xB );
447 this->minY = int( this->yA < this->yB ? this->yA:this->yB );
448 this->maxY = int( this->yA > this->yB ? this->yA:this->yB );
449 }
450
451 double x;
452 double y;
453 double xA;
454 double yA;
455 double xB;
456 double yB;
457 double thick;//半径
458
459 double angle;//角度
460
461 double lengthA;
462 double lengthB;
463
464 double width;
465 double height;
466 double thickHarf;//半径の二条
467 double thickPow;
468 double minX;
469 double minY;
470 double maxX;
471 double maxY;
472
473 public:
474
476 Line( double x , double y , double angle , double length , double thick):
477 x(x),
478 y(y),
479 angle(angle),
480 lengthA( length/2 ),
481 lengthB( length/2 ),
482 thick( thick )
483 {
484 this->CulLine();
485 }
486
487 virtual Figure* Clone(double x,double y) const
488 {
489 return new Line( x , y , this->angle , this->lengthA , this->thick);
490 }
491
492 double GetX() const
493 {
494 return x;
495 }
496
497 double GetY() const
498 {
499 return y;
500 }
501
502 double GetW() const
503 {
504 return int(xA - xB);
505 }
506
507 double GetH() const
508 {
509 return int(yA - yB);
510 }
511
512 void SetPos(double x , double y )
513 {
514 this->x = x;
515 this->y = y;
516 this->CulParam();
517 }
518
519 void MultiZoom(double rate)
520 {
521 this->lengthA *= rate;
522 this->lengthB *= rate;
523 this->thick *= rate;
524
525 this->zoomX *= rate;
526 this->zoomY *= rate;
527 this->CulParam();
528
529 this->zoomX = rate;
530 this->zoomY = rate;
531 }
532
533 void MultiZoom(double rateX , double rateY)
534 {
535 this->lengthA *= rateX;
536 this->lengthB *= rateY;
537 this->thick *= rateX;
538
539 this->CulParam();
540
541 this->zoomX = rateX;
542 this->zoomY = rateY;
543 }
544
545 void Rotate(double angle)
546 {
547 this->angle += angle;
548 this->CulParam();
549 }
550
551 void SetAngle(double angle)
552 {
553 this->angle = angle;
554 this->CulParam();
555 }
556
557 void Move(double mX , double mY )
558 {
559 this->x += mX;
560 this->y += mY;
561 this->xA += mX;
562 this->yA += mY;
563 this->xB += mX;
564 this->yB += mY;
565
566 this->minX += mX;
567 this->minY += mY;
568 this->maxX += mX;
569 this->maxY += mY;
570 }
571
572 void Draw( int rgb , int transRate , Camera *camera = 0 ) const
573 {
574 DxLib::SetDrawBlendMode( 1 , transRate);
575 if( camera )
576 {
577 DxLib::DrawLine( (int)camera->TranX(xA) , (int)camera->TranY(yA) , (int)camera->TranX(xB) , (int)camera->TranY(yB) , rgb , (int)( camera->GetZoom() ) );
578 DxLib::DrawCircle( (int)camera->TranX(xA) , (int)camera->TranX(yA) , (int)( thickHarf*camera->GetZoom() ) , rgb , true );
579 DxLib::DrawCircle( (int)camera->TranX(xB) , (int)camera->TranX(yB) , (int)( thickHarf*camera->GetZoom() ) , rgb , true );
580 }
581 else
582 {
583 DxLib::DrawLine( (int)xA , (int)yA , (int)xB , (int)yB , rgb , (int)thick );
584 DxLib::DrawCircle( (int)xA , (int)yA , (int)thickHarf , rgb , true );
585 DxLib::DrawCircle( (int)xB , (int)yB , (int)thickHarf , rgb , true );
586 }
587
588 DxLib::SetDrawBlendMode( 0 , transRate);
589 }
590
591 double GetXA() const
592 {
593 return xA;
594 }
595
596 double GetYA() const
597 {
598 return yA;
599 }
600
601 double GetXB() const
602 {
603 return xB;
604 }
605
606 double GetYB() const
607 {
608 return yB;
609 }
610
611 double GetThick() const
612 {
613 return thick;
614 }
615
616 void SetThick(double thick)
617 {
618 this->thick = thick;
619 this->thickHarf = int(this->thick / 2);
620 this->thickPow = int(this->thick * this->thick / 4);
621 }
622
623 double GetAngle() const
624 {
625 return this->angle;
626 }
627
628 void MoveAngle(double angle)
629 {
630 this->angle += angle;
631 this->CulParam();
632 }
633
634 double GetLength() const
635 {
636 return this->lengthA + this->lengthB;
637 }
638
639 double GetThickHarf() const
640 {
641 return this->thickHarf;
642 }
643
644 double GetThickPow() const
645 {
646 return this->thickPow;
647 }
648
649 double GetMinX() const
650 {
651 return minX;
652 }
653
654 double GetMinY() const
655 {
656 return minY;
657 }
658
659 double GetMaxX() const
660 {
661 return maxX;
662 }
663
664 double GetMaxY() const
665 {
666 return maxY;
667 }
668
669 bool Hit(const Figure *figure) const
670 {
671 return figure->Hit( this );
672 }
673 bool Hit(const Complex *complex) const
674 {
675 for( auto it : complex->figures )
676 {
677 if( it->Hit( this ) ) return true;
678 }
679 return false;
680 }
681 bool Hit(const Point *point) const
682 {
683 return LinePoint( point->GetX() , point->GetY() , this->GetThickPow() );
684 }
685 bool Hit(const Line *line) const
686 {
687 //四角形でラフチェック
688 if( RectRect(this->GetXA() - this->GetThickHarf() ,this->GetYA() - this->GetThickHarf() , this->GetXB() - line->GetThickHarf() , this->GetYB() - line->GetThickHarf() ,
689 line->GetXA() - this->GetThickHarf() ,line->GetYA() - this->GetThickHarf() , line->GetXB() - line->GetThickHarf() , line->GetYB() - line->GetThickHarf() ) )
690 {
691 return true;
692 }
693 //交差チェック
694 if( LineLine(this->GetXA() ,this->GetYA() ,this->GetXB() ,this->GetYB() ,line->GetXA(),line->GetYA(),line->GetXB(),line->GetYB() ) )
695 {
696 return true;
697 }
698 //線と端のチェック
699 //線が点になっているかで分ける
700 if( this->GetLength() != 0)
701 {
702 if( this->LinePoint( line->GetXA() , line->GetYA() , (this->GetThickHarf() + line->GetThickHarf()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
703 if( this->LinePoint( line->GetXB() , line->GetYB() , (this->GetThickHarf() + line->GetThickHarf()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
704 }
705 if( line->GetLength() != 0 )
706 {
707 if( line->LinePoint( this->GetXA() , this->GetYA() , (this->GetThickHarf() + line->GetThickHarf()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
708 if( line->LinePoint( this->GetXB() , this->GetYB() , (this->GetThickHarf() + line->GetThickHarf()) * (this->GetThickHarf() + line->GetThickHarf()) ) ) return true;
709 }
710
711 return false;
712 }
713 bool Hit(const Rect *rect) const;
714 bool Hit(const Circle *circle) const;
715
717 bool LinePoint(double px , double py , double range ) const
718 {
719 if ( this->GetLength() == 0 )
720 {//線が点
721 if(
722 ( this->GetXA() - px ) *( this->GetXA() - px ) +
723 ( this->GetXA() - py ) *( this->GetXA() - py )
724 < this->GetThickHarf() * this->GetThickHarf() ) return true;
725 return false;
726 }
727
728 double t = double( -this->GetW() * (this->GetXA() - px) + this->GetH() *( this->GetYA() - py ) ) / this->GetLength();
729
730 int tx = int(this->GetXA() + this->GetW() * t);
731 int ty = int(this->GetYA() + this->GetH() * t);
732
733 if(
734 (
735 tx > this->GetMinX() &&
736 tx < this->GetMaxX() &&
737 ty > this->GetMinY() &&
738 ty < this->GetMaxY()
739 ) || (
740 PointPoint( px , py , this->GetXA() , this->GetYA() ) < range
741 ) || (
742 PointPoint( px , py , this->GetXB() , this->GetYB() ) < range
743 )
744 )
745 {
746 double d = (px - tx) * (px - tx) + (py - ty) * (py - ty);
747
748 if( d <= range ) return true;
749 }
750
751 return false;
752 }
753 };
754
768 class Rect : public Figure
769 {
770 public:
771 double x;
772 double y;
773
774 double upLength;
775 double downLength;
776 double leftLength;
777 double rightLength;
778
780 Rect(double x,double y,double width,double height):
781 x(x),
782 y(y),
783 upLength( height/2 ),
784 downLength( height/2 ),
785 leftLength( width/2 ),
786 rightLength( width/2 )
787 {}
788
789 virtual Figure* Clone(double x,double y) const
790 {
791 return new Rect( x , y , GetW() , GetH() );
792 }
793
794 void SetPos(double x , double y)
795 {
796 this->x = x;
797 this->y = y;
798 }
799
800 void Move(double mX , double mY )
801 {
802 this->x += mX;
803 this->y += mY;
804 }
805
806 void MultiZoom(double rate)
807 {
808 upLength *= rate;
809 downLength *= rate;
810 leftLength *= rate;
811 rightLength *= rate;
812 }
813
814 void MultiZoom(double rateX , double rateY)
815 {
816 upLength *= rateY;
817 downLength *= rateY;
818 leftLength *= rateX;
819 rightLength *= rateX;
820 }
821
822 void Rotate(double angle)
823 {
824 }
825
826 void SetAngle(double angle)
827 {
828 }
829
830 void Draw( int rgb , int transRate , Camera *camera = nullptr) const
831 {
832 DxLib::SetDrawBlendMode( 1 , transRate);
833 if( camera )
834 {
835 DxLib::DrawBox
836 (
837 (int)camera->TranX(x - leftLength) ,
838 (int)camera->TranY(y - upLength) ,
839 (int)camera->TranX(x + rightLength) ,
840 (int)camera->TranY(y + downLength) ,
841 rgb ,
842 true
843 );
844 }
845 else
846 {
847 DxLib::DrawBox
848 (
849 (int)( x - leftLength ) ,
850 (int)( y - upLength ) ,
851 (int)( x + rightLength ) ,
852 (int)( y + downLength) ,
853 rgb ,
854 true
855 );
856 }
857 DxLib::SetDrawBlendMode( 0 , transRate);
858 }
859
860 double GetX() const
861 {
862 return x;
863 }
864
865 double GetY() const
866 {
867 return y;
868 }
869
870 double GetW() const
871 {
872 return upLength + downLength;
873 }
874
875 double GetH() const
876 {
877 return leftLength + rightLength;
878 }
879
880 virtual double GetLeft() const
881 {
882 return int(x - leftLength);
883 }
884
885 virtual double GetTop() const
886 {
887 return int(y - upLength);
888 }
889
890 virtual double GetRight() const
891 {
892 return int(x + rightLength);
893 }
894
895 virtual double GetBottom() const
896 {
897 return int(y + downLength);
898 }
899
900 bool Hit(const Figure *figure) const
901 {
902 return figure->Hit( this );
903 }
904 bool Hit(const Complex *complex) const
905 {
906 for( auto it : complex->figures )
907 {
908 if( it->Hit( this ) ) return true;
909 }
910 return false;
911 }
912 bool Hit(const Point *point) const
913 {
914 return (
915 (
916 point->x < this->GetRight()
917 ) && (
918 point->x > this->GetLeft()
919 ) && (
920 point->y < this->GetBottom()
921 ) && (
922 point->y > this->GetTop()
923 )
924 );
925 }
926 bool Hit(const Line *line) const
927 {
928 if( ! RectRect
929 (
930 line->GetMinX() - line->GetThickHarf(),
931 line->GetMinY() - line->GetThickHarf(),
932 line->GetMaxX() + line->GetThickHarf(),
933 line->GetMaxY() + line->GetThickHarf(),
934 this->GetLeft(),
935 this->GetTop(),
936 this->GetRight(),
937 this->GetBottom()
938 )
939 )
940 {
941 return false;
942 }
943
944 //√２/2≒0.7
945
946 if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
947 , 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) ))
948 {
949 return true;
950 }
951
952 if( LineLine( line->GetXA() , line->GetYA() , line->GetXB() , line->GetYB()
953 , 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) ))
954 {
955 return true;
956 }
957
958 //端の丸い所以外判定
959 if(
960 line->GetXA() + line->GetThickHarf() > this->GetLeft() && line->GetXA() - line->GetThickHarf() < this->GetRight() &&
961 line->GetYA() + line->GetThickHarf() > this->GetTop() && line->GetYA() - line->GetThickHarf() < this->GetBottom()
962 )
963 {
964 //端の丸い所判定
965 if( line->GetXA() < this->GetLeft() && line->GetYA() < this->GetTop() )
966 {//左上
967
968 if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
969 (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
970
971 }
972 else if( line->GetXA() > this->GetRight() && line->GetYA() < this->GetTop() )
973 {//右上
974
975 if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
976 (line->GetYA() - this->GetTop()) * (line->GetYA() - this->GetTop()) < line->GetThickPow() ) return true;
977
978 }
979 else if( line->GetXA() < this->GetLeft() && line->GetYA() > this->GetBottom() )
980 {//左下
981
982 if( (line->GetXA() - this->GetLeft()) * (line->GetXA() - this->GetLeft()) +
983 (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
984
985 }
986 else if( line->GetXA() > this->GetRight() && line->GetYA() > this->GetBottom() )
987 {//右下
988
989 if( (line->GetXA() - this->GetRight()) * (line->GetXA() - this->GetRight()) +
990 (line->GetYA() - this->GetBottom()) * (line->GetYA() - this->GetBottom()) < line->GetThickPow() ) return true;
991
992 }
993 else
994 {
995 return true;
996 }
997 }
998
999 if(
1000 line->GetXB() + line->GetThickHarf() > this->GetLeft() && line->GetXB() - line->GetThickHarf() < this->GetRight() &&
1001 line->GetYB() + line->GetThickHarf() > this->GetTop() && line->GetYB() - line->GetThickHarf() < this->GetBottom()
1002 )
1003 {
1004 //端の丸い所判定
1005 if( line->GetXB() < this->GetLeft() && line->GetYB() < this->GetTop() )
1006 {//左上
1007 if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
1008 (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
1009
1010 }
1011 else if( line->GetXB() > this->GetRight() && line->GetYB() < this->GetTop() )
1012 {//右上
1013
1014 if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
1015 (line->GetYB() - this->GetTop()) * (line->GetYB() - this->GetTop()) < line->GetThickPow() ) return true;
1016
1017 }
1018 else if( line->GetXB() < this->GetLeft() && line->GetYB() > this->GetBottom() )
1019 {//左下
1020
1021 if( (line->GetXB() - this->GetLeft()) * (line->GetXB() - this->GetLeft()) +
1022 (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
1023
1024 }
1025 else if( line->GetXB() > this->GetRight() && line->GetYB() > this->GetBottom() )
1026 {//右下
1027 if( (line->GetXB() - this->GetRight()) * (line->GetXB() - this->GetRight()) +
1028 (line->GetYB() - this->GetBottom()) * (line->GetYB() - this->GetBottom()) < line->GetThickPow() ) return true;
1029
1030 }
1031 else
1032 {
1033 return true;
1034 }
1035 }
1036
1037 return false;
1038 }
1039 bool Hit(const Rect *rect) const
1040 {
1041 return RectRect
1042 (
1043 this->GetLeft() , this->GetTop() , this->GetRight() , this->GetBottom() ,
1044 rect->GetLeft() , rect->GetTop() , rect->GetRight() , rect->GetBottom()
1045 );
1046 }
1047 bool Hit(const Circle *circle) const;
1048 };
1049
1063 class Circle : public Figure
1064 {
1065 public:
1066 double x;
1067 double y;
1068 double radius;
1069
1071 Circle( double x , double y , double radius):
1072 x(x),
1073 y(y),
1074 radius(radius)
1075 {}
1076
1077 Figure* Clone(double x,double y) const
1078 {
1079 return new Circle( x , y , this->radius );
1080 }
1081
1082 void SetPos(double x , double y )
1083 {
1084 this->x = x;
1085 this->y = y;
1086 }
1087
1088 void MultiZoom(double rate)
1089 {
1090 this->radius *= rate;
1091 }
1092
1093 void MultiZoom(double rateX , double rateY)
1094 {
1095 this->radius *= rateX;
1096 }
1097
1098 void Rotate(double angle){}
1099
1100 void SetAngle(double angle){}
1101
1102 void Move(double mX , double mY )
1103 {
1104 this->x += mX;
1105 this->y += mY;
1106 }
1107
1108 double GetX() const
1109 {
1110 return int(x);
1111 }
1112
1113 double GetY() const
1114 {
1115 return int(y);
1116 }
1117
1118 double GetW() const
1119 {
1120 return int(radius*2);
1121 }
1122
1123 double GetH() const
1124 {
1125 return int(radius*2);
1126 }
1127
1128 void Draw( int rgb , int transRate , Camera *camera = 0) const
1129 {
1130 DxLib::SetDrawBlendMode( 1 , transRate);
1131 if( camera )
1132 {
1133 DxLib::DrawCircle( (int)camera->TranX(x) , (int)camera->TranY(y) , (int)(radius * camera->GetZoom()) , rgb , true );
1134 }
1135 else
1136 {
1137 DxLib::DrawCircle( (int)x , (int)y , (int)radius , rgb , true );
1138 }
1139 DxLib::SetDrawBlendMode( 0 , transRate);
1140 }
1141
1142 bool Hit(const Figure *figure) const
1143 {
1144 return figure->Hit( this );
1145 }
1146 bool Hit(const Complex *complex) const
1147 {
1148 for( auto it : complex->figures )
1149 {
1150 if( it->Hit( this ) ) return true;
1151 }
1152 return false;
1153 }
1154 bool Hit(const Point *point) const
1155 {
1156 return
1157 (
1158 ( point->x - this->x ) * ( point->x - this->x ) +
1159 ( point->y - this->y ) * ( point->y - this->y )
1160 <=
1161 ( this->radius * this->radius )
1162 );
1163 }
1164 bool Hit(const Line *line) const
1165 {
1166 return line->LinePoint( this->x , this->y , (line->GetThickHarf() + this->radius) * (line->GetThickHarf() + this->radius) );
1167 }
1168 bool Hit(const Circle *circle) const
1169 {
1170 return(
1171 (this->x - circle->x) * (this->x - circle->x) +
1172 (this->y - circle->y) * (this->y - circle->y)
1173 <=
1174 (this->radius + circle->radius) * (this->radius + circle->radius)
1175 );
1176 }
1177 bool Hit(const Rect *rect) const
1178 {
1179 return
1180 (
1181 (
1182 (
1183 (
1184 this->x + this->radius >= rect->GetLeft()
1185 )&&(
1186 this->x - this->radius <= rect->GetRight()
1187 )
1188 )&&(
1189 (
1190 this->y >= rect->GetTop()
1191 )&&(
1192 this->y <= rect->GetBottom()
1193 )
1194 )
1195 ) || (
1196 (
1197 (
1198 this->x >= rect->GetLeft()
1199 )&&(
1200 this->x <= rect->GetRight()
1201 )
1202 )&&(
1203 (
1204 this->y + this->radius >= rect->GetTop()
1205 )&&(
1206 this->y - this->radius <= rect->GetBottom()
1207 )
1208 )
1209 ) || (//四角形の四隅と円の判定
1210 (this->x - rect->GetLeft() ) * (this->x - rect->GetLeft() ) +
1211 (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1212 (this->radius * this->radius )
1213 ) || (
1214 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1215 (this->y - rect->GetTop() ) * (this->y - rect->GetTop() ) <=
1216 (this->radius * this->radius )
1217 ) || (
1218 (this->x - rect->GetLeft()) * (this->x - rect->GetLeft()) +
1219 (this->y - rect->GetBottom()) * (this->y -rect->GetBottom()) <=
1220 (this->radius * this->radius )
1221 ) || (
1222 (this->x - rect->GetRight()) * (this->x - rect->GetRight()) +
1223 (this->y - rect->GetBottom()) * (this->y - rect->GetBottom()) <=
1224 (this->radius * this->radius )
1225 )
1226 );
1227 }
1228 };
1229 }
DXFW::Point::GetX
double GetX() const
説明
Definition: Figure.h:351
DXFW::Point::MultiZoom
void MultiZoom(double rate)
説明
Definition: Figure.h:371
DXFW::Figure::Move
virtual void Move(double x, double y)=0
説明
DXFW::Line::SetPos
void SetPos(double x, double y)
説明
Definition: Figure.h:512
DXFW::Circle::Move
void Move(double mX, double mY)
説明
Definition: Figure.h:1102
DXFW::Line::GetX
double GetX() const
説明
Definition: Figure.h:492
DXFW::Point::Move
void Move(double mX, double mY)
説明
Definition: Figure.h:345
DXFW::Line::SetAngle
void SetAngle(double angle)
説明
Definition: Figure.h:551
DXFW::Figure::MoveA
void MoveA(double distance, double angle)
説明
Definition: Figure.h:133
DXFW::Line::Hit
bool Hit(const Figure *figure) const
説明
Definition: Figure.h:669
DXFW::Line::Draw
void Draw(int rgb, int transRate, Camera *camera=0) const
説明
Definition: Figure.h:572
DXFW::Complex::SetAngle
void SetAngle(double angle)
説明
Definition: Figure.h:267
DXFW::Complex::Move
void Move(double mX, double mY)
説明
Definition: Figure.h:214
DXFW::Figure::Rotate
virtual void Rotate(double angle)=0
説明
DXFW::Rect::Draw
void Draw(int rgb, int transRate, Camera *camera=nullptr) const
説明
Definition: Figure.h:830
DXFW::Rect::MultiZoom
void MultiZoom(double rate)
説明
Definition: Figure.h:806
DXFW::Rect::SetPos
void SetPos(double x, double y)
説明
Definition: Figure.h:794
DXFW::Line::Clone
virtual Figure * Clone(double x, double y) const
説明
Definition: Figure.h:487
DXFW::Line::Rotate
void Rotate(double angle)
説明
Definition: Figure.h:545
DXFW::Figure::Draw
virtual void Draw(int rgb, int transRate, Camera *camera=0) const =0
説明
DXFW::Rect::GetX
double GetX() const
説明
Definition: Figure.h:860
DXFW::Line::Line
Line(double x, double y, double angle, double length, double thick)
説明
Definition: Figure.h:476
DXFW::Figure::Clone
virtual Figure * Clone(double x, double y) const =0
説明
DXFW::Circle::Hit
bool Hit(const Figure *figure) const
説明
Definition: Figure.h:1142
DXFW::Complex::GetX
double GetX() const
説明
Definition: Figure.h:222
DXFW::Line::LinePoint
bool LinePoint(double px, double py, double range) const
説明
Definition: Figure.h:717
DXFW::Rect::MultiZoom
void MultiZoom(double rateX, double rateY)
説明
Definition: Figure.h:814
DXFW::Point::Draw
void Draw(int rgb, int transRate, Camera *camera=0) const
説明
Definition: Figure.h:379
DXFW::Complex::MultiZoom
void MultiZoom(double rateX, double rateY)
説明
Definition: Figure.h:250
DXFW::Figure::SetZoom
void SetZoom(double rateX, double rateY)
説明
Definition: Figure.h:118
DXFW::Figure::LineLine
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
説明
Definition: Figure.h:73
DXFW::Complex::Rotate
void Rotate(double angle)
説明
Definition: Figure.h:259
DXFW::Point::Point
Point(double x, double y)
説明
Definition: Figure.h:329
DXFW::Line
説明
Definition: Figure.h:427
DXFW::Circle::MultiZoom
void MultiZoom(double rateX, double rateY)
説明
Definition: Figure.h:1093
DXFW::Camera
2D用のカメラクラス
Definition: Camera.h:27
DXFW::Circle::Circle
Circle(double x, double y, double radius)
説明
Definition: Figure.h:1071
DXFW::Figure::RectRect
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
説明
Definition: Figure.h:36
DXFW::Complex::MultiZoom
void MultiZoom(double rate)
説明
Definition: Figure.h:242
DXFW::Line::MultiZoom
void MultiZoom(double rateX, double rateY)
説明
Definition: Figure.h:533
DXFW::Circle::SetAngle
void SetAngle(double angle)
説明
Definition: Figure.h:1100
DXFW::Figure::Hit
virtual bool Hit(const Figure *figure) const =0
説明
DXFW::Point::Hit
bool Hit(const Figure *figure) const
説明
Definition: Figure.h:393
DXFW::Figure::SetPos
virtual void SetPos(double x, double y)=0
説明
DXFW::Circle::SetPos
void SetPos(double x, double y)
説明
Definition: Figure.h:1082
DXFW::Complex
説明
Definition: Figure.h:182
DXFW::Figure::MultiZoom
virtual void MultiZoom(double rate)=0
説明
DXFW::Figure::GetDirect
double GetDirect(Figure *figure)
説明
Definition: Figure.h:148
DXFW::Circle::GetX
double GetX() const
説明
Definition: Figure.h:1108
DXFW::Circle::MultiZoom
void MultiZoom(double rate)
説明
Definition: Figure.h:1088
DXFW::Complex::Hit
bool Hit(const Figure *figure) const
説明
Definition: Figure.h:283
DXFW::Figure::GetDistance
double GetDistance(Figure *figure)
説明
Definition: Figure.h:154
DXFW::Point::Rotate
void Rotate(double angle)
説明
Definition: Figure.h:375
DXFW::Figure::PointPoint
static int PointPoint(double x1, double y1, double x2, double y2)
説明
Definition: Figure.h:92
DXFW::Line::Move
void Move(double mX, double mY)
説明
Definition: Figure.h:557
DXFW::Line::MultiZoom
void MultiZoom(double rate)
説明
Definition: Figure.h:519
DXFW::Rect::Clone
virtual Figure * Clone(double x, double y) const
説明
Definition: Figure.h:789
DXFW::Circle::Clone
Figure * Clone(double x, double y) const
説明
Definition: Figure.h:1077
DXFW::Point::SetAngle
void SetAngle(double angle)
説明
Definition: Figure.h:377
DXFW::Circle
説明
Definition: Figure.h:1063
DXFW::Complex::Clone
Figure * Clone(double x, double y) const
説明
Definition: Figure.h:194
DXFW::Rect::Rect
Rect(double x, double y, double width, double height)
説明
Definition: Figure.h:780
DXFW::Rect
説明
Definition: Figure.h:768
DXFW::Circle::Draw
void Draw(int rgb, int transRate, Camera *camera=0) const
説明
Definition: Figure.h:1128
DXFW::Rect::Rotate
void Rotate(double angle)
説明
Definition: Figure.h:822
DXFW::Rect::Move
void Move(double mX, double mY)
説明
Definition: Figure.h:800
DXFW::Figure::GetX
virtual double GetX() const =0
説明
DXFW::Point
クラス説明
Definition: Figure.h:317
DXFW::Point::SetPos
void SetPos(double x, double y)
説明
Definition: Figure.h:339
DXFW::Figure
説明
Definition: Figure.h:29
DXFW::Complex::SetPos
void SetPos(double x, double y)
説明
Definition: Figure.h:206
DXFW::Complex::Draw
void Draw(int rgb, int transRate, Camera *camera=0) const
説明
Definition: Figure.h:275
DXFW::Circle::Rotate
void Rotate(double angle)
説明
Definition: Figure.h:1098
DXFW::Point::MultiZoom
void MultiZoom(double rateX, double rateY)
説明
Definition: Figure.h:373
DXFW::Point::Clone
Figure * Clone(double x, double y) const
説明
Definition: Figure.h:334
DXFW::Figure::SetAngle
virtual void SetAngle(double angle)=0
説明
DXFW::Rect::Hit
bool Hit(const Figure *figure) const
説明
Definition: Figure.h:900
DXFW::Rect::SetAngle
void SetAngle(double angle)
説明
Definition: Figure.h:826