Skip to content

Commit eda3b92

Browse files
authored
2D 物理演算で三角形・四角形・ポリゴン・線分などの形状のセンサーを作れるように変更 (#1251)
1 parent e7d60f0 commit eda3b92

20 files changed

+481
-24
lines changed

Siv3D/include/Siv3D/Physics2D/P2Body.hpp

+49
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ namespace s3d
5959
/// @return *this
6060
P2Body& addLine(const Line& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});
6161

62+
/// @brief 線分のセンサー部品を物体に追加します。
63+
/// @remark `P2Line` の部品を物体に追加します。
64+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
65+
/// @param filter センサーの干渉フィルタ
66+
/// @return *this
67+
P2Body& addLineSensor(const Line& localPos, const P2Filter& filter = {});
68+
6269
/// @brief 連続する複数の線分の部品を物体に追加します。
6370
/// @remark `P2LineString` の部品を物体に追加します。
6471
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -68,6 +75,13 @@ namespace s3d
6875
/// @return *this
6976
P2Body& addLineString(const LineString& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});
7077

78+
/// @brief 連続する複数の線分のセンサー部品を物体に追加します。
79+
/// @remark `P2LineString` の部品を物体に追加します。
80+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
81+
/// @param filter センサーの干渉フィルタ
82+
/// @return *this
83+
P2Body& addLineStringSensor(const LineString& localPos, const P2Filter& filter = {});
84+
7185
/// @brief 連続する複数の線分(終点と始点を結ぶ)の部品を物体に追加します。
7286
/// @remark `P2LineString` の部品を物体に追加します。
7387
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -77,6 +91,13 @@ namespace s3d
7791
/// @return *this
7892
P2Body& addClosedLineString(const LineString& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});
7993

94+
/// @brief 連続する複数の線分(終点と始点を結ぶ)のセンサー部品を物体に追加します。
95+
/// @remark `P2LineString` の部品を物体に追加します。
96+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
97+
/// @param filter センサーの干渉フィルタ
98+
/// @return *this
99+
P2Body& addClosedLineStringSensor(const LineString& localPos, const P2Filter& filter = {});
100+
80101
/// @brief 円の部品を物体に追加します。
81102
/// @remark `P2Circle` の部品を物体に追加します。
82103
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -100,6 +121,13 @@ namespace s3d
100121
/// @return *this
101122
P2Body& addRect(const RectF& localPos, const P2Material& material = {}, const P2Filter& filter = {});
102123

124+
/// @brief 長方形のセンサー部品を物体に追加します。
125+
/// @remark `P2Rect` の部品を物体に追加します。
126+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
127+
/// @param filter センサーの干渉フィルタ
128+
/// @return *this
129+
P2Body& addRectSensor(const RectF& localPos, const P2Filter& filter = {});
130+
103131
/// @brief 三角形の部品を物体に追加します。
104132
/// @remark `P2Triangle` の部品を物体に追加します。
105133
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -108,6 +136,13 @@ namespace s3d
108136
/// @return *this
109137
P2Body& addTriangle(const Triangle& localPos, const P2Material& material = {}, const P2Filter& filter = {});
110138

139+
/// @brief 三角形のセンサー部品を物体に追加します。
140+
/// @remark `P2Triangle` の部品を物体に追加します。
141+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
142+
/// @param filter センサーの干渉フィルタ
143+
/// @return *this
144+
P2Body& addTriangleSensor(const Triangle& localPos, const P2Filter& filter = {});
145+
111146
/// @brief 凸な四角形の部品を物体に追加します。
112147
/// @remark `P2Quad` の部品を物体に追加します。
113148
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -116,6 +151,13 @@ namespace s3d
116151
/// @return *this
117152
P2Body& addQuad(const Quad& localPos, const P2Material& material = {}, const P2Filter& filter = {});
118153

154+
/// @brief 凸な四角形のセンサー部品を物体に追加します。
155+
/// @remark `P2Quad` の部品を物体に追加します。
156+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
157+
/// @param filter センサーの干渉フィルタ
158+
/// @return *this
159+
P2Body& addQuadSensor(const Quad& localPos, const P2Filter& filter = {});
160+
119161
/// @brief 多角形の部品を物体に追加します。
120162
/// @remark `P2Polygon` の部品を物体に追加します。
121163
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
@@ -124,6 +166,13 @@ namespace s3d
124166
/// @return *this
125167
P2Body& addPolygon(const Polygon& localPos, const P2Material& material = {}, const P2Filter& filter = {});
126168

169+
/// @brief 多角形のセンサー部品を物体に追加します。
170+
/// @remark `P2Polygon` の部品を物体に追加します。
171+
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
172+
/// @param filter センサーの干渉フィルタ
173+
/// @return *this
174+
P2Body& addPolygonSensor(const Polygon& localPos, const P2Filter& filter = {});
175+
127176
/// @brief 複数の多角形の部品を物体に追加します。
128177
/// @remark 複数の `P2Polygon` の部品を物体に追加します。
129178
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)

Siv3D/include/Siv3D/Physics2D/P2Line.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace s3d
2323
public:
2424

2525
SIV3D_NODISCARD_CXX20
26-
P2Line(b2Body& body, const Line& localPos, OneSided oneSided, const P2Material& material, const P2Filter& filter);
26+
P2Line(b2Body& body, const Line& localPos, OneSided oneSided, const P2Material& material, const P2Filter& filter, bool isSensor);
2727

2828
[[nodiscard]]
2929
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2LineString.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace s3d
2222
public:
2323

2424
SIV3D_NODISCARD_CXX20
25-
P2LineString(b2Body& body, const LineString& lines, CloseRing closeRing, OneSided oneSided, const P2Material& material, const P2Filter& filter);
25+
P2LineString(b2Body& body, const LineString& lines, CloseRing closeRing, OneSided oneSided, const P2Material& material, const P2Filter& filter, bool isSensor);
2626

2727
[[nodiscard]]
2828
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2Polygon.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace s3d
2222
public:
2323

2424
SIV3D_NODISCARD_CXX20
25-
P2Polygon(b2Body& body, const Polygon& polygon, const P2Material& material, const P2Filter& filter);
25+
P2Polygon(b2Body& body, const Polygon& polygon, const P2Material& material, const P2Filter& filter, bool isSensor);
2626

2727
[[nodiscard]]
2828
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2Quad.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace s3d
2222
public:
2323

2424
SIV3D_NODISCARD_CXX20
25-
P2Quad(b2Body& body, const Quad& quad, const P2Material& material, const P2Filter& filter);
25+
P2Quad(b2Body& body, const Quad& quad, const P2Material& material, const P2Filter& filter, bool isSensor);
2626

2727
[[nodiscard]]
2828
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2Rect.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace s3d
2222
public:
2323

2424
SIV3D_NODISCARD_CXX20
25-
P2Rect(b2Body& body, const RectF& rect, const P2Material& material, const P2Filter& filter);
25+
P2Rect(b2Body& body, const RectF& rect, const P2Material& material, const P2Filter& filter, bool isSensor);
2626

2727
[[nodiscard]]
2828
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2Triangle.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace s3d
2222
public:
2323

2424
SIV3D_NODISCARD_CXX20
25-
P2Triangle(b2Body& body, const Triangle& triangle, const P2Material& material, const P2Filter& filter);
25+
P2Triangle(b2Body& body, const Triangle& triangle, const P2Material& material, const P2Filter& filter, bool isSensor);
2626

2727
[[nodiscard]]
2828
P2ShapeType getShapeType() const noexcept override;

Siv3D/include/Siv3D/Physics2D/P2World.hpp

+111
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ namespace s3d
9696
[[nodiscard]]
9797
P2Body createLine(P2BodyType bodyType, const Vec2& worldPos, const Line& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});
9898

99+
/// @brief 線分のセンサー部品を持つ物体を作成します。
100+
/// @remark 物体は `P2Line` の部品を持ちます。
101+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
102+
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
103+
/// @param worldPos 物体のワールド座標 (cm)
104+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
105+
/// @param filter センサーの干渉フィルタ
106+
/// @return 作成した物体
107+
[[nodiscard]]
108+
P2Body createLineSensor(P2BodyType bodyType, const Vec2& worldPos, const Line& localPos, const P2Filter& filter = {});
109+
99110
/// @brief 連続する複数の線分を部品として持つ物体を作成します。
100111
/// @remark 物体は `P2LineString` の部品を持ちます。
101112
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
@@ -108,6 +119,17 @@ namespace s3d
108119
[[nodiscard]]
109120
P2Body createLineString(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});
110121

122+
/// @brief 連続する複数の線分のセンサー部品を持つ物体を作成します。
123+
/// @remark 物体は `P2LineString` の部品を持ちます。
124+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
125+
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
126+
/// @param worldPos 物体のワールド座標 (cm)
127+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
128+
/// @param filter センサーの干渉フィルタ
129+
/// @return 作成した物体
130+
[[nodiscard]]
131+
P2Body createLineStringSensor(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, const P2Filter& filter = {});
132+
111133
/// @brief 連続する複数の線分(終点と始点を結ぶ)を部品として持つ物体を作成します。
112134
/// @remark 物体は `P2LineString` の部品を持ちます。
113135
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
@@ -120,6 +142,17 @@ namespace s3d
120142
[[nodiscard]]
121143
P2Body createClosedLineString(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});
122144

145+
/// @brief 連続する複数の線分(終点と始点を結ぶ)のセンサー部品を持つ物体を作成します。
146+
/// @remark 物体は `P2LineString` の部品を持ちます。
147+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
148+
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
149+
/// @param worldPos 物体のワールド座標 (cm)
150+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
151+
/// @param filter センサーの干渉フィルタ
152+
/// @return 作成した物体
153+
[[nodiscard]]
154+
P2Body createClosedLineStringSensor(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, const P2Filter& filter = {});
155+
123156
/// @brief 円を部品として持つ物体を作成します。
124157
/// @remark 物体は `P2Circle` の部品を持ちます。
125158
/// @remark 円の中心座標は `worldPos` です。
@@ -154,6 +187,17 @@ namespace s3d
154187
[[nodiscard]]
155188
P2Body createCircleSensor(P2BodyType bodyType, const Vec2& worldPos, double r, const P2Filter& filter = {});
156189

190+
/// @brief 円形のセンサー部品を持つ物体を作成します。
191+
/// @remark 物体は `P2Circle` の部品を持ちます。
192+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
193+
/// @param bodyType 物体の種類
194+
/// @param worldPos 物体のワールド座標 (cm)
195+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
196+
/// @param filter センサーの干渉フィルタ
197+
/// @return 作成した物体
198+
[[nodiscard]]
199+
P2Body createCircleSensor(P2BodyType bodyType, const Vec2& worldPos, const Circle& localPos, const P2Filter& filter = {});
200+
157201
/// @brief 正方形を部品として持つ物体を作成します。
158202
/// @remark 物体は `P2Rect` の部品を持ちます。
159203
/// @remark 正方形の中心座標は `worldPos` です。
@@ -189,6 +233,41 @@ namespace s3d
189233
[[nodiscard]]
190234
P2Body createRect(P2BodyType bodyType, const Vec2& worldPos, const RectF& localPos, const P2Material& material = {}, const P2Filter& filter = {});
191235

236+
/// @brief 正方形のセンサー部品を持つ物体を作成します。
237+
/// @remark 物体は `P2Rect` の部品を持ちます。
238+
/// @remark 正方形の中心座標は `worldPos` です。
239+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
240+
/// @param bodyType 物体の種類
241+
/// @param worldPos 物体のワールド座標 (cm)
242+
/// @param size センサーの一辺の長さ (cm)
243+
/// @param filter センサーの干渉フィルタ
244+
/// @return 作成した物体
245+
[[nodiscard]]
246+
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, double size, const P2Filter& filter = {});
247+
248+
/// @brief 長方形のセンサー部品を持つ物体を作成します。
249+
/// @remark 物体は `P2Rect` の部品を持ちます。
250+
/// @remark 長方形の中心座標は `worldPos` です。
251+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
252+
/// @param bodyType 物体の種類
253+
/// @param worldPos 物体のワールド座標 (cm)
254+
/// @param size センサーの幅と高さ (cm)
255+
/// @param filter センサーの干渉フィルタ
256+
/// @return 作成した物体
257+
[[nodiscard]]
258+
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, const SizeF& size, const P2Filter& filter = {});
259+
260+
/// @brief 長方形のセンサー部品を持つ物体を作成します。
261+
/// @remark 物体は `P2Rect` の部品を持ちます。
262+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
263+
/// @param bodyType 物体の種類
264+
/// @param worldPos 物体のワールド座標 (cm)
265+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
266+
/// @param filter センサーの干渉フィルタ
267+
/// @return 作成した物体
268+
[[nodiscard]]
269+
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, const RectF& localPos, const P2Filter& filter = {});
270+
192271
/// @brief 三角形を部品として持つ物体を作成します。
193272
/// @remark 物体は `P2Triangle` の部品を持ちます。
194273
/// @param bodyType 物体の種類
@@ -200,6 +279,17 @@ namespace s3d
200279
[[nodiscard]]
201280
P2Body createTriangle(P2BodyType bodyType, const Vec2& worldPos, const Triangle& localPos, const P2Material& material = {}, const P2Filter& filter = {});
202281

282+
/// @brief 三角形のセンサー部品を持つ物体を作成します。
283+
/// @remark 物体は `P2Triangle` の部品を持ちます。
284+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
285+
/// @param bodyType 物体の種類
286+
/// @param worldPos 物体のワールド座標 (cm)
287+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
288+
/// @param filter センサーの干渉フィルタ
289+
/// @return 作成した物体
290+
[[nodiscard]]
291+
P2Body createTriangleSensor(P2BodyType bodyType, const Vec2& worldPos, const Triangle& localPos, const P2Filter& filter = {});
292+
203293
/// @brief 凸な四角形を部品として持つ物体を作成します。
204294
/// @remark 物体は `P2Quad` の部品を持ちます。
205295
/// @param bodyType 物体の種類
@@ -211,6 +301,16 @@ namespace s3d
211301
[[nodiscard]]
212302
P2Body createQuad(P2BodyType bodyType, const Vec2& worldPos, const Quad& localPos, const P2Material& material = {}, const P2Filter& filter = {});
213303

304+
/// @brief 凸な四角形のセンサー部品を持つ物体を作成します。
305+
/// @remark 物体は `P2Quad` の部品を持ちます。
306+
/// @param bodyType 物体の種類
307+
/// @param worldPos 物体のワールド座標 (cm)
308+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
309+
/// @param filter センサーの干渉フィルタ
310+
/// @return 作成した物体
311+
[[nodiscard]]
312+
P2Body createQuadSensor(P2BodyType bodyType, const Vec2& worldPos, const Quad& localPos, const P2Filter& filter = {});
313+
214314
/// @brief 多角形を部品として持つ物体を作成します。
215315
/// @remark 物体は `P2Polygon` の部品を持ちます。
216316
/// @param bodyType 物体の種類
@@ -222,6 +322,17 @@ namespace s3d
222322
[[nodiscard]]
223323
P2Body createPolygon(P2BodyType bodyType, const Vec2& worldPos, const Polygon& localPos, const P2Material& material = {}, const P2Filter& filter = {});
224324

325+
/// @brief 多角形のセンサー部品を持つ物体を作成します。
326+
/// @remark 物体は `P2Polygon` の部品を持ちます。
327+
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
328+
/// @param bodyType 物体の種類
329+
/// @param worldPos 物体のワールド座標 (cm)
330+
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
331+
/// @param filter センサーの干渉フィルタ
332+
/// @return 作成した物体
333+
[[nodiscard]]
334+
P2Body createPolygonSensor(P2BodyType bodyType, const Vec2& worldPos, const Polygon& localPos, const P2Filter& filter = {});
335+
225336
/// @brief 複数の多角形を部品として持つ物体を作成します。
226337
/// @remark 物体は複数の `P2Polygon` の部品を持ちます。
227338
/// @param bodyType 物体の種類

0 commit comments

Comments
 (0)