-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckHit.h
194 lines (164 loc) · 6.59 KB
/
CheckHit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef CHECKHIT_H_20150619164015611654
#define CHECKHIT_H_20150619164015611654
#include <memory>
#include <utility>
#include <functional>
#include "Square.hpp"
#include "CheckHit_ISCONTACTconcept.h"
#ifdef _MSC_VER
#pragma warning( disable : 4512 )//代入演算子を生成できません。
#pragma warning( disable : 4505 )//参照されていないローカル関数は削除されました。
#endif
namespace CheckHit
{
template<typename T>
class Object_Bace
{
public:
typedef T value_type;
enum Type : int{ Dot, Line, Triangle, AABB, Circle, Polygon, Type_END };
virtual Type GetType()const = 0;
virtual bool IsContact(const Object_Bace<T>& obj2)const = 0;
virtual ~Object_Bace(){}
};
//----------IsContact----------//
template<typename ObjectT, typename T>
typename std::enable_if<std::is_base_of<Object_Bace<T>, ObjectT>::value, bool>::type
IsContact(const ObjectT& obj1, const Object_Bace<T>& obj2);
template<typename T, typename ObjectT>
typename std::enable_if<std::is_base_of<Object_Bace<T>, ObjectT>::value, bool>::type
IsContact(const Object_Bace<T>& obj1, const ObjectT& obj2);
ISCONTACT_concept IsContact(const Object_Bace<T1>& obj1, const Object_Bace<T2>& obj2);
namespace CheckHitImpl
{
template<typename T, typename Child>
class Object_Impl_Bace : public Object_Bace < T >
{
public:
bool IsContact(const Object_Bace<T>& obj2)const override;
};
}
//----------Object----------//
namespace CheckHitImpl
{
template <typename T_b, typename T = typename remove_crv_wrapper<T_b>::type>
struct add_clr{ typedef std::reference_wrapper<typename std::add_const<typename std::remove_reference<T>::type>::type> type; };
template <typename T_b, typename T = typename remove_crv_wrapper<T_b>::type>
struct add_cr{ typedef typename std::add_const < typename std::remove_reference<T>::type > ::type type; };
}
template<typename T>
class Object_Dot : public CheckHitImpl::Object_Impl_Bace < T, Object_Dot<T> >
{
public:
typedef const T& cr_T;
T x, y;
Object_Dot(){}
template<typename U, typename = typename std::enable_if<std::is_constructible<T,U>::value>::type>
Object_Dot(const Object_Dot<U>& d);
Object_Dot(cr_T param_x, cr_T param_y);
OBJECT_operator_equal_with_concept(Object_Dot);
//operator Object_Dot<cr_T>()const{ return Object_Dot<cr_T>(*this); }
Type GetType()const override{ return Dot; }
};
template < typename T >
class Object_Line : public CheckHitImpl::Object_Impl_Bace < T, Object_Line<T> >
{
public:
typedef const T& cr_T;
T x1, y1;
T x2, y2;
Object_Line(){}
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Line(const Object_Line<U>& l);
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Line(const Object_Dot<U>& d1, const Object_Dot<U>& d2);
Object_Line(cr_T param_x1, cr_T param_y1
, cr_T param_x2, cr_T param_y2);
OBJECT_operator_equal_with_concept(Object_Line);
//operator Object_Line<cr_T>()const{ return Object_Line<cr_T>(*this); }
Type GetType()const override{ return Line; }
};
template < typename T >
class Object_Triangle : public CheckHitImpl::Object_Impl_Bace < T, Object_Triangle<T> >
{
public:
typedef const T& cr_T;
T x1, y1;
T x2, y2;
T x3, y3;
Object_Triangle(){}
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Triangle(const Object_Triangle<U>& tri);
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Triangle(const Object_Dot<U>& d1, const Object_Dot<U>& d2, const Object_Dot<U>& d3);
Object_Triangle(cr_T param_x1, cr_T param_y1
, cr_T param_x2, cr_T param_y2
, cr_T param_x3, cr_T param_y3);
OBJECT_operator_equal_with_concept(Object_Triangle);
//operator Object_Triangle<cr_T>()const{ return Object_Triangle<cr_T>(*this); }
Type GetType()const override{ return Triangle; }
};
template<typename T>
//回転してない長方形
class Object_AABB : public CheckHitImpl::Object_Impl_Bace < T, Object_AABB<T> >
{
public:
typedef const T& cr_T;
T x1, y1;
T x2, y2;
Object_AABB(){}
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_AABB(const Object_AABB<U>& AABB);
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_AABB(const Object_Dot<U>& d1, const Object_Dot<U>& d2);
Object_AABB(cr_T param_x1, cr_T param_y1, cr_T param_x2, cr_T param_y2);
OBJECT_operator_equal_with_concept(Object_AABB);
//Square_Pointとの互換
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_AABB(const Square_Point<U>& s);
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_AABB<T>& operator=(const Square_Point<U>& s);
operator Square_Point<T>();
//operator Object_AABB<cr_T>()const{ return Object_AABB<cr_T>(*this); }
Type GetType()const override{ return AABB; }
};
template<typename T>
class Object_Circle : public CheckHitImpl::Object_Impl_Bace < T, Object_Circle<T> >
{
public:
typedef const T& cr_T;
T x, y, r;
Object_Circle(){}
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Circle(const Object_Circle<U>& cir);
template<typename U, typename = typename std::enable_if<std::is_constructible<T, U>::value>::type>
Object_Circle(const Object_Dot<U>& center, cr_T param_r);
Object_Circle(cr_T param_x, cr_T param_y, cr_T param_r);
OBJECT_operator_equal_with_concept(Object_Circle);
//operator Object_Circle<cr_T>()const{ return Object_Circle<cr_T>(*this); }
Type GetType()const override{ return Circle; }
};
//Container : std::vector<Object_Bace<T>*>など
//配列は使えない
template<typename T, typename Container>
//複数の図形を組み合わせて一つの図形として扱う
class Object_Combined : public CheckHitImpl::Object_Impl_Bace < T, Object_Combined<T, Container> >
{
public:
typedef Object_Combined<T, Container> This_T;
Container objects;
Object_Combined(){}
Object_Combined(const This_T& polygon);
Object_Combined(This_T&& polygon);
Object_Combined(const Container& objects);
Object_Combined(Container&& objects);
Object_Combined<T, Container>& operator=(const This_T& polygon);
Object_Combined<T, Container>& operator=(This_T&& polygon);
Object_Combined<T, Container>& operator=(const Container& objects);
Object_Combined<T, Container>& operator=(Container&& objects);
Type GetType()const override{ return Polygon; }
};
}
#include "CheckHit_ISCONTACTconcept_end.h"
#include "CheckHit.hpp"
#endif