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

Updates 20240227 #574

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Moves ClipList code into Manifold.cpp
louis-langholtz committed Apr 14, 2024
commit 700289a86bb89fd729af861cb82fa8984bbe1bfb
8 changes: 0 additions & 8 deletions Build/xcode5/PlayRho.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -412,8 +412,6 @@
996B7B8D2A6DF25200A8207F /* PoolMemoryResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 996B7B8A2A6DF25200A8207F /* PoolMemoryResource.cpp */; };
996B7B8F2A6EED6200A8207F /* polymorphic_allocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 996B7B8E2A6EED6200A8207F /* polymorphic_allocator.cpp */; };
9980D10A29C8ACB700007B35 /* WorldConf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9980D10929C8ACB700007B35 /* WorldConf.cpp */; };
998A7C012A801C1C00F29B01 /* ClipList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7BFF2A801C1C00F29B01 /* ClipList.cpp */; };
998A7C022A801C1C00F29B01 /* ClipList.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 998A7C002A801C1C00F29B01 /* ClipList.hpp */; };
998A7C052A80404600F29B01 /* StatsResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7C032A80404600F29B01 /* StatsResource.cpp */; };
998A7C062A80404600F29B01 /* StatsResource.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 998A7C042A80404600F29B01 /* StatsResource.hpp */; };
998A7C082A814F9300F29B01 /* StatsResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7C072A814F9300F29B01 /* StatsResource.cpp */; };
@@ -920,8 +918,6 @@
996B7B8A2A6DF25200A8207F /* PoolMemoryResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PoolMemoryResource.cpp; sourceTree = "<group>"; };
996B7B8E2A6EED6200A8207F /* polymorphic_allocator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = polymorphic_allocator.cpp; sourceTree = "<group>"; };
9980D10929C8ACB700007B35 /* WorldConf.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WorldConf.cpp; sourceTree = "<group>"; };
998A7BFF2A801C1C00F29B01 /* ClipList.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClipList.cpp; sourceTree = "<group>"; };
998A7C002A801C1C00F29B01 /* ClipList.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ClipList.hpp; sourceTree = "<group>"; };
998A7C032A80404600F29B01 /* StatsResource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StatsResource.cpp; sourceTree = "<group>"; };
998A7C042A80404600F29B01 /* StatsResource.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = StatsResource.hpp; sourceTree = "<group>"; };
998A7C072A814F9300F29B01 /* StatsResource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StatsResource.cpp; sourceTree = "<group>"; };
@@ -1298,7 +1294,6 @@
470F94A51EC4C79B00AA3C82 /* BodyConf.hpp */,
474BAB2C1E5D00960058E08A /* BodyConstraint.hpp */,
80BB8936141C3E5900F1753A /* ChainShapeConf.hpp */,
998A7C002A801C1C00F29B01 /* ClipList.hpp */,
476162C71E245C9D002C7FB0 /* CodeDumper.hpp */,
99D1BE242AEF1FFD001BA497 /* ContactImpulsesFunction.hpp */,
47363E8520027FE2005912B1 /* ContactImpulsesList.hpp */,
@@ -1384,7 +1379,6 @@
80BB894D141C3E5900F1753A /* Body.cpp */,
470F9B4B1EEF20B6007EF7B6 /* BodyConf.cpp */,
80BB8935141C3E5900F1753A /* ChainShapeConf.cpp */,
998A7BFF2A801C1C00F29B01 /* ClipList.cpp */,
476162C61E245C9D002C7FB0 /* CodeDumper.cpp */,
47363E8420027FE2005912B1 /* ContactImpulsesList.cpp */,
80BB8963141C3E5900F1753A /* ContactSolver.cpp */,
@@ -1647,7 +1641,6 @@
4734B2271DC29F7C00F15E29 /* SimplexEdge.hpp in Headers */,
4787D6BB1F2E946E008C115E /* PrismaticJointConf.hpp in Headers */,
47C85D1B1F0D9D8D00F70C56 /* Units.hpp in Headers */,
998A7C022A801C1C00F29B01 /* ClipList.hpp in Headers */,
99D1BE212AEF18F8001BA497 /* ShapeFunction.hpp in Headers */,
998A7C0C2A82D55100F29B01 /* Contactable.hpp in Headers */,
470F9B181EDF2959007EF7B6 /* Transformation.hpp in Headers */,
@@ -2171,7 +2164,6 @@
47363E8920029DFD005912B1 /* Velocity.cpp in Sources */,
4787D6BA1F2E946E008C115E /* PrismaticJointConf.cpp in Sources */,
4787D6CE1F2EC902008C115E /* MotorJointConf.cpp in Sources */,
998A7C012A801C1C00F29B01 /* ClipList.cpp in Sources */,
4787D6CA1F2EA3A1008C115E /* GearJointConf.cpp in Sources */,
80BB89BE141C3E5900F1753A /* Contact.cpp in Sources */,
80BB89C0141C3E5900F1753A /* ContactSolver.cpp in Sources */,
2 changes: 0 additions & 2 deletions Library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -207,7 +207,6 @@ set(PLAYRHO_D2_HDRS
include/playrho/d2/BodyConf.hpp
include/playrho/d2/BodyConstraint.hpp
include/playrho/d2/ChainShapeConf.hpp
include/playrho/d2/ClipList.hpp
include/playrho/d2/CodeDumper.hpp
include/playrho/d2/ContactImpulsesFunction.hpp
include/playrho/d2/ContactImpulsesList.hpp
@@ -277,7 +276,6 @@ set(PLAYRHO_D2_SRCS
source/playrho/d2/Body.cpp
source/playrho/d2/BodyConf.cpp
source/playrho/d2/ChainShapeConf.cpp
source/playrho/d2/ClipList.cpp
source/playrho/d2/CodeDumper.cpp
source/playrho/d2/ContactImpulsesList.cpp
source/playrho/d2/ContactSolver.cpp
65 changes: 0 additions & 65 deletions Library/include/playrho/d2/ClipList.hpp

This file was deleted.

71 changes: 0 additions & 71 deletions Library/source/playrho/d2/ClipList.cpp

This file was deleted.

64 changes: 63 additions & 1 deletion Library/source/playrho/d2/Manifold.cpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
#include <playrho/StepConf.hpp>
#include <playrho/Templates.hpp> // for size

#include <playrho/d2/ClipList.hpp>
#include <playrho/d2/Distance.hpp>
#include <playrho/d2/DistanceProxy.hpp>
#include <playrho/d2/Manifold.hpp>
@@ -39,6 +38,69 @@ namespace playrho::d2 {

namespace {

/// @brief Clip vertex.
/// @details Used for computing contact manifolds.
struct ClipVertex
{
Length2 v; ///< Vertex of edge or polygon.
ContactFeature cf; ///< Contact feature information.
};

/// @brief Clip list for <code>ClipSegmentToLine</code>.
/// @see ClipSegmentToLine.
using ClipList = ArrayList<ClipVertex, MaxManifoldPoints>;

/// Clipping for contact manifolds.
/// @details This returns an array of points from the given line that are inside of the plane as
/// defined by a given normal and offset.
/// @param vIn Clip list of two points defining the line.
/// @param normal Normal of the plane with which to determine intersection.
/// @param offset Offset of the plane with which to determine intersection.
/// @param indexA Index of vertex A.
/// @return List of zero one or two clip points.
ClipList ClipSegmentToLine(const ClipList& vIn, const UnitVec& normal, Length offset,
ContactFeature::Index indexA)
{
ClipList vOut;

if (size(vIn) == 2) // must have two points (for a segment)
{
// Use Sutherland-Hodgman clipping:
// (https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm ).

// Calculate the distance of end points to the line
const auto distance0 = Dot(normal, vIn[0].v) - offset;
const auto distance1 = Dot(normal, vIn[1].v) - offset;

// If the points are behind the plane...
// Ideally they are. Then we get face-vertex contact features which are simpler to
// calculate. Note that it also helps to avoid changing the contact feature from the
// given clip vertices. So the code here also accepts distances that are just slightly
// over zero.
if (distance0 <= 0_m || AlmostZero(StripUnit(distance0)))
{
vOut.push_back(vIn[0]);
}
if (distance1 <= 0_m || AlmostZero(StripUnit(distance1)))
{
vOut.push_back(vIn[1]);
}

// If we didn't already find two points & the points are on different sides of the plane...
if (size(vOut) < 2 && signbit(StripUnit(distance0)) != signbit(StripUnit(distance1)))
{
// Neither distance0 nor distance1 is 0 and either one or the other is negative (but not both).
// Find intersection point of edge and plane
// Vertex A is hitting edge B.
const auto interp = distance0 / (distance0 - distance1);
const auto vertex = vIn[0].v + (vIn[1].v - vIn[0].v) * interp;
vOut.push_back(ClipVertex{vertex, GetVertexFaceContactFeature(indexA, vIn[0].cf.indexB)});
}
}

return vOut;
}

constexpr auto face = ContactFeature::e_face;
constexpr auto vertex = ContactFeature::e_vertex;