Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D 物理演算で三角形・四角形・ポリゴン・線分などの形状のセンサーを作れるように変更 #1251

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Siv3D/include/Siv3D/Physics2D/P2Body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ namespace s3d
/// @return *this
P2Body& addLine(const Line& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 線分のセンサー部品を物体に追加します。
/// @remark `P2Line` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addLineSensor(const Line& localPos, const P2Filter& filter = {});

/// @brief 連続する複数の線分の部品を物体に追加します。
/// @remark `P2LineString` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -68,6 +75,13 @@ namespace s3d
/// @return *this
P2Body& addLineString(const LineString& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 連続する複数の線分のセンサー部品を物体に追加します。
/// @remark `P2LineString` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addLineStringSensor(const LineString& localPos, const P2Filter& filter = {});

/// @brief 連続する複数の線分(終点と始点を結ぶ)の部品を物体に追加します。
/// @remark `P2LineString` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -77,6 +91,13 @@ namespace s3d
/// @return *this
P2Body& addClosedLineString(const LineString& localPos, OneSided oneSided, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 連続する複数の線分(終点と始点を結ぶ)のセンサー部品を物体に追加します。
/// @remark `P2LineString` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addClosedLineStringSensor(const LineString& localPos, const P2Filter& filter = {});

/// @brief 円の部品を物体に追加します。
/// @remark `P2Circle` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -100,6 +121,13 @@ namespace s3d
/// @return *this
P2Body& addRect(const RectF& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 長方形のセンサー部品を物体に追加します。
/// @remark `P2Rect` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addRectSensor(const RectF& localPos, const P2Filter& filter = {});

/// @brief 三角形の部品を物体に追加します。
/// @remark `P2Triangle` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -108,6 +136,13 @@ namespace s3d
/// @return *this
P2Body& addTriangle(const Triangle& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 三角形のセンサー部品を物体に追加します。
/// @remark `P2Triangle` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addTriangleSensor(const Triangle& localPos, const P2Filter& filter = {});

/// @brief 凸な四角形の部品を物体に追加します。
/// @remark `P2Quad` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -116,6 +151,13 @@ namespace s3d
/// @return *this
P2Body& addQuad(const Quad& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 凸な四角形のセンサー部品を物体に追加します。
/// @remark `P2Quad` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return *this
P2Body& addQuadSensor(const Quad& localPos, const P2Filter& filter = {});

/// @brief 多角形の部品を物体に追加します。
/// @remark `P2Polygon` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand All @@ -124,6 +166,13 @@ namespace s3d
/// @return *this
P2Body& addPolygon(const Polygon& localPos, const P2Material& material = {}, const P2Filter& filter = {});

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

/// @brief 複数の多角形の部品を物体に追加します。
/// @remark 複数の `P2Polygon` の部品を物体に追加します。
/// @param localPos 物体のワールド座標から見たローカルでの形状の座標 (cm)
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2Line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace s3d
public:

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

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2LineString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
public:

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

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2Polygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
public:

SIV3D_NODISCARD_CXX20
P2Polygon(b2Body& body, const Polygon& polygon, const P2Material& material, const P2Filter& filter);
P2Polygon(b2Body& body, const Polygon& polygon, const P2Material& material, const P2Filter& filter, bool isSensor);

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2Quad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
public:

SIV3D_NODISCARD_CXX20
P2Quad(b2Body& body, const Quad& quad, const P2Material& material, const P2Filter& filter);
P2Quad(b2Body& body, const Quad& quad, const P2Material& material, const P2Filter& filter, bool isSensor);

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2Rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
public:

SIV3D_NODISCARD_CXX20
P2Rect(b2Body& body, const RectF& rect, const P2Material& material, const P2Filter& filter);
P2Rect(b2Body& body, const RectF& rect, const P2Material& material, const P2Filter& filter, bool isSensor);

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/include/Siv3D/Physics2D/P2Triangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace s3d
public:

SIV3D_NODISCARD_CXX20
P2Triangle(b2Body& body, const Triangle& triangle, const P2Material& material, const P2Filter& filter);
P2Triangle(b2Body& body, const Triangle& triangle, const P2Material& material, const P2Filter& filter, bool isSensor);

[[nodiscard]]
P2ShapeType getShapeType() const noexcept override;
Expand Down
111 changes: 111 additions & 0 deletions Siv3D/include/Siv3D/Physics2D/P2World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ namespace s3d
[[nodiscard]]
P2Body createLine(P2BodyType bodyType, const Vec2& worldPos, const Line& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 線分のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Line` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createLineSensor(P2BodyType bodyType, const Vec2& worldPos, const Line& localPos, const P2Filter& filter = {});

/// @brief 連続する複数の線分を部品として持つ物体を作成します。
/// @remark 物体は `P2LineString` の部品を持ちます。
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
Expand All @@ -108,6 +119,17 @@ namespace s3d
[[nodiscard]]
P2Body createLineString(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 連続する複数の線分のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2LineString` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createLineStringSensor(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, const P2Filter& filter = {});

/// @brief 連続する複数の線分(終点と始点を結ぶ)を部品として持つ物体を作成します。
/// @remark 物体は `P2LineString` の部品を持ちます。
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
Expand All @@ -120,6 +142,17 @@ namespace s3d
[[nodiscard]]
P2Body createClosedLineString(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, OneSided oneSided = OneSided::No, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 連続する複数の線分(終点と始点を結ぶ)のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2LineString` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類(P2BodyType::Dynamic は指定不可)
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createClosedLineStringSensor(P2BodyType bodyType, const Vec2& worldPos, const LineString& localPos, const P2Filter& filter = {});

/// @brief 円を部品として持つ物体を作成します。
/// @remark 物体は `P2Circle` の部品を持ちます。
/// @remark 円の中心座標は `worldPos` です。
Expand Down Expand Up @@ -154,6 +187,17 @@ namespace s3d
[[nodiscard]]
P2Body createCircleSensor(P2BodyType bodyType, const Vec2& worldPos, double r, const P2Filter& filter = {});

/// @brief 円形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Circle` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createCircleSensor(P2BodyType bodyType, const Vec2& worldPos, const Circle& localPos, const P2Filter& filter = {});

/// @brief 正方形を部品として持つ物体を作成します。
/// @remark 物体は `P2Rect` の部品を持ちます。
/// @remark 正方形の中心座標は `worldPos` です。
Expand Down Expand Up @@ -189,6 +233,41 @@ namespace s3d
[[nodiscard]]
P2Body createRect(P2BodyType bodyType, const Vec2& worldPos, const RectF& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 正方形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Rect` の部品を持ちます。
/// @remark 正方形の中心座標は `worldPos` です。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param size センサーの一辺の長さ (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, double size, const P2Filter& filter = {});

/// @brief 長方形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Rect` の部品を持ちます。
/// @remark 長方形の中心座標は `worldPos` です。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param size センサーの幅と高さ (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, const SizeF& size, const P2Filter& filter = {});

/// @brief 長方形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Rect` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createRectSensor(P2BodyType bodyType, const Vec2& worldPos, const RectF& localPos, const P2Filter& filter = {});

/// @brief 三角形を部品として持つ物体を作成します。
/// @remark 物体は `P2Triangle` の部品を持ちます。
/// @param bodyType 物体の種類
Expand All @@ -200,6 +279,17 @@ namespace s3d
[[nodiscard]]
P2Body createTriangle(P2BodyType bodyType, const Vec2& worldPos, const Triangle& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 三角形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Triangle` の部品を持ちます。
/// @remark センサーは他の物体と干渉しませんが接触情報は発生します。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createTriangleSensor(P2BodyType bodyType, const Vec2& worldPos, const Triangle& localPos, const P2Filter& filter = {});

/// @brief 凸な四角形を部品として持つ物体を作成します。
/// @remark 物体は `P2Quad` の部品を持ちます。
/// @param bodyType 物体の種類
Expand All @@ -211,6 +301,16 @@ namespace s3d
[[nodiscard]]
P2Body createQuad(P2BodyType bodyType, const Vec2& worldPos, const Quad& localPos, const P2Material& material = {}, const P2Filter& filter = {});

/// @brief 凸な四角形のセンサー部品を持つ物体を作成します。
/// @remark 物体は `P2Quad` の部品を持ちます。
/// @param bodyType 物体の種類
/// @param worldPos 物体のワールド座標 (cm)
/// @param localPos `worldPos` から見たローカルでの形状の座標 (cm)
/// @param filter センサーの干渉フィルタ
/// @return 作成した物体
[[nodiscard]]
P2Body createQuadSensor(P2BodyType bodyType, const Vec2& worldPos, const Quad& localPos, const P2Filter& filter = {});

/// @brief 多角形を部品として持つ物体を作成します。
/// @remark 物体は `P2Polygon` の部品を持ちます。
/// @param bodyType 物体の種類
Expand All @@ -222,6 +322,17 @@ namespace s3d
[[nodiscard]]
P2Body createPolygon(P2BodyType bodyType, const Vec2& worldPos, const Polygon& localPos, const P2Material& material = {}, const P2Filter& filter = {});

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

/// @brief 複数の多角形を部品として持つ物体を作成します。
/// @remark 物体は複数の `P2Polygon` の部品を持ちます。
/// @param bodyType 物体の種類
Expand Down
Loading
Loading