SDXFrameWork 0.12 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
IShape.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Framework/IPosition.h>
6 #include <vector>
7 #include <algorithm>
8
9 namespace SDX
10 {
11 class Complex;
12 class Point;
13 class Line;
14 class Circle;
15 class Rect;
16
17 class Camera;
18 class Color;
21 class IShape : public IPosition
22 {
23 protected:
25 static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
26 {
27 //x座標をラフチェック
28 if (x1 >= x2)
29 {
30 if ((x1 < x3 && x1 < x4) || (x2 > x3 && x2 > x4))
31 {
32 return false;
33 }
34 }
35 else
36 {
37 if ((x2 < x3 && x2 < x4) || (x1 > x3 && x1 > x4))
38 {
39 return false;
40 }
41 }
42 //y座標をラフチェック
43 if (y1 >= y2)
44 {
45 if ((y1 < y3 && y1 < y4) || (y2 > y3 && y2 > y4))
46 {
47 return false;
48 }
49 }
50 else
51 {
52 if ((y2 < y3 && y2 < y4) || (y1 > y3 && y1 > y4))
53 {
54 return false;
55 }
56 }
57
58 return true;
59 }
60
62 static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
63 {
64 //交差判定
65 if ((double(x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
66 (double(x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0)
67 {
68 return false;
69 }
70
71 if ((double(x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)) *
72 (double(x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)) > 0)
73 {
74 return false;
75 }
76 return true;
77 }
78
80 static int PointPoint(double x1, double y1, double x2, double y2)
81 {
82 return int((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
83 }
84
85 public:
86
87 virtual ~IShape() = default;
88
90 virtual IShape* Clone(double x, double y) const = 0;
91
93 virtual bool Hit(const IShape *iShape) const = 0;
95 virtual bool Hit(const Complex *complex) const = 0;
97 virtual bool Hit(const Point *point) const = 0;
99 virtual bool Hit(const Line *line) const = 0;
101 virtual bool Hit(const Rect *rect) const = 0;
103 virtual bool Hit(const Circle *circle) const = 0;
104
106 virtual void Draw(const Color &描画色) const = 0;
107 };
108 }
SDX::Rect
矩形を表す図形クラス.
Definition: Rect.h:22
SDX::Line
太さのある線を表す図形クラス.
Definition: Line.h:20
SDX::IShape::Clone
virtual IShape * Clone(double x, double y) const =0
同じ形の図形を作る.
SDX::IShape::PointPoint
static int PointPoint(double x1, double y1, double x2, double y2)
二点間の距離を計算.
Definition: IShape.h:80
SDX::Point
点を表す図形クラス.
Definition: Point.h:22
SDX::IShape
衝突判定可能な図形の抽象クラス.
Definition: IShape.h:21
SDX::IShape::Hit
virtual bool Hit(const IShape *iShape) const =0
衝突判定.
SDX::Complex
複合図形を表すクラス.
Definition: Complex.h:20
SDX::Color
色を表すクラス.
Definition: Color.h:11
SDX::IShape::LineLine
static bool LineLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
線分の交差判定.
Definition: IShape.h:62
SDX::IPosition
位置と方向を持つクラスのインターフェース.
Definition: IPosition.h:11
SDX::IShape::RectRect
static bool RectRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
矩形の交差判定.
Definition: IShape.h:25
SDX::Circle
円を表す図形クラス.
Definition: Circle.h:20
SDX::IShape::Draw
virtual void Draw(const Color &描画色) const =0
描画する.