Skip to content

Commit 2655e9a

Browse files
Moves ClipList code into Manifold.cpp
1 parent 9dffd19 commit 2655e9a

File tree

5 files changed

+63
-147
lines changed

5 files changed

+63
-147
lines changed

Build/xcode5/PlayRho.xcodeproj/project.pbxproj

-8
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@
412412
996B7B8D2A6DF25200A8207F /* PoolMemoryResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 996B7B8A2A6DF25200A8207F /* PoolMemoryResource.cpp */; };
413413
996B7B8F2A6EED6200A8207F /* polymorphic_allocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 996B7B8E2A6EED6200A8207F /* polymorphic_allocator.cpp */; };
414414
9980D10A29C8ACB700007B35 /* WorldConf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9980D10929C8ACB700007B35 /* WorldConf.cpp */; };
415-
998A7C012A801C1C00F29B01 /* ClipList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7BFF2A801C1C00F29B01 /* ClipList.cpp */; };
416-
998A7C022A801C1C00F29B01 /* ClipList.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 998A7C002A801C1C00F29B01 /* ClipList.hpp */; };
417415
998A7C052A80404600F29B01 /* StatsResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7C032A80404600F29B01 /* StatsResource.cpp */; };
418416
998A7C062A80404600F29B01 /* StatsResource.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 998A7C042A80404600F29B01 /* StatsResource.hpp */; };
419417
998A7C082A814F9300F29B01 /* StatsResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 998A7C072A814F9300F29B01 /* StatsResource.cpp */; };
@@ -920,8 +918,6 @@
920918
996B7B8A2A6DF25200A8207F /* PoolMemoryResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PoolMemoryResource.cpp; sourceTree = "<group>"; };
921919
996B7B8E2A6EED6200A8207F /* polymorphic_allocator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = polymorphic_allocator.cpp; sourceTree = "<group>"; };
922920
9980D10929C8ACB700007B35 /* WorldConf.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WorldConf.cpp; sourceTree = "<group>"; };
923-
998A7BFF2A801C1C00F29B01 /* ClipList.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClipList.cpp; sourceTree = "<group>"; };
924-
998A7C002A801C1C00F29B01 /* ClipList.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ClipList.hpp; sourceTree = "<group>"; };
925921
998A7C032A80404600F29B01 /* StatsResource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StatsResource.cpp; sourceTree = "<group>"; };
926922
998A7C042A80404600F29B01 /* StatsResource.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = StatsResource.hpp; sourceTree = "<group>"; };
927923
998A7C072A814F9300F29B01 /* StatsResource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StatsResource.cpp; sourceTree = "<group>"; };
@@ -1298,7 +1294,6 @@
12981294
470F94A51EC4C79B00AA3C82 /* BodyConf.hpp */,
12991295
474BAB2C1E5D00960058E08A /* BodyConstraint.hpp */,
13001296
80BB8936141C3E5900F1753A /* ChainShapeConf.hpp */,
1301-
998A7C002A801C1C00F29B01 /* ClipList.hpp */,
13021297
476162C71E245C9D002C7FB0 /* CodeDumper.hpp */,
13031298
99D1BE242AEF1FFD001BA497 /* ContactImpulsesFunction.hpp */,
13041299
47363E8520027FE2005912B1 /* ContactImpulsesList.hpp */,
@@ -1384,7 +1379,6 @@
13841379
80BB894D141C3E5900F1753A /* Body.cpp */,
13851380
470F9B4B1EEF20B6007EF7B6 /* BodyConf.cpp */,
13861381
80BB8935141C3E5900F1753A /* ChainShapeConf.cpp */,
1387-
998A7BFF2A801C1C00F29B01 /* ClipList.cpp */,
13881382
476162C61E245C9D002C7FB0 /* CodeDumper.cpp */,
13891383
47363E8420027FE2005912B1 /* ContactImpulsesList.cpp */,
13901384
80BB8963141C3E5900F1753A /* ContactSolver.cpp */,
@@ -1647,7 +1641,6 @@
16471641
4734B2271DC29F7C00F15E29 /* SimplexEdge.hpp in Headers */,
16481642
4787D6BB1F2E946E008C115E /* PrismaticJointConf.hpp in Headers */,
16491643
47C85D1B1F0D9D8D00F70C56 /* Units.hpp in Headers */,
1650-
998A7C022A801C1C00F29B01 /* ClipList.hpp in Headers */,
16511644
99D1BE212AEF18F8001BA497 /* ShapeFunction.hpp in Headers */,
16521645
998A7C0C2A82D55100F29B01 /* Contactable.hpp in Headers */,
16531646
470F9B181EDF2959007EF7B6 /* Transformation.hpp in Headers */,
@@ -2171,7 +2164,6 @@
21712164
47363E8920029DFD005912B1 /* Velocity.cpp in Sources */,
21722165
4787D6BA1F2E946E008C115E /* PrismaticJointConf.cpp in Sources */,
21732166
4787D6CE1F2EC902008C115E /* MotorJointConf.cpp in Sources */,
2174-
998A7C012A801C1C00F29B01 /* ClipList.cpp in Sources */,
21752167
4787D6CA1F2EA3A1008C115E /* GearJointConf.cpp in Sources */,
21762168
80BB89BE141C3E5900F1753A /* Contact.cpp in Sources */,
21772169
80BB89C0141C3E5900F1753A /* ContactSolver.cpp in Sources */,

Library/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ set(PLAYRHO_D2_HDRS
207207
include/playrho/d2/BodyConf.hpp
208208
include/playrho/d2/BodyConstraint.hpp
209209
include/playrho/d2/ChainShapeConf.hpp
210-
include/playrho/d2/ClipList.hpp
211210
include/playrho/d2/CodeDumper.hpp
212211
include/playrho/d2/ContactImpulsesFunction.hpp
213212
include/playrho/d2/ContactImpulsesList.hpp
@@ -277,7 +276,6 @@ set(PLAYRHO_D2_SRCS
277276
source/playrho/d2/Body.cpp
278277
source/playrho/d2/BodyConf.cpp
279278
source/playrho/d2/ChainShapeConf.cpp
280-
source/playrho/d2/ClipList.cpp
281279
source/playrho/d2/CodeDumper.cpp
282280
source/playrho/d2/ContactImpulsesList.cpp
283281
source/playrho/d2/ContactSolver.cpp

Library/include/playrho/d2/ClipList.hpp

-65
This file was deleted.

Library/source/playrho/d2/ClipList.cpp

-71
This file was deleted.

Library/source/playrho/d2/Manifold.cpp

+63-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <playrho/StepConf.hpp>
2727
#include <playrho/Templates.hpp> // for size
2828

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

4039
namespace {
4140

41+
/// @brief Clip vertex.
42+
/// @details Used for computing contact manifolds.
43+
struct ClipVertex
44+
{
45+
Length2 v; ///< Vertex of edge or polygon.
46+
ContactFeature cf; ///< Contact feature information.
47+
};
48+
49+
/// @brief Clip list for <code>ClipSegmentToLine</code>.
50+
/// @see ClipSegmentToLine.
51+
using ClipList = ArrayList<ClipVertex, MaxManifoldPoints>;
52+
53+
/// Clipping for contact manifolds.
54+
/// @details This returns an array of points from the given line that are inside of the plane as
55+
/// defined by a given normal and offset.
56+
/// @param vIn Clip list of two points defining the line.
57+
/// @param normal Normal of the plane with which to determine intersection.
58+
/// @param offset Offset of the plane with which to determine intersection.
59+
/// @param indexA Index of vertex A.
60+
/// @return List of zero one or two clip points.
61+
ClipList ClipSegmentToLine(const ClipList& vIn, const UnitVec& normal, Length offset,
62+
ContactFeature::Index indexA)
63+
{
64+
ClipList vOut;
65+
66+
if (size(vIn) == 2) // must have two points (for a segment)
67+
{
68+
// Use Sutherland-Hodgman clipping:
69+
// (https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm ).
70+
71+
// Calculate the distance of end points to the line
72+
const auto distance0 = Dot(normal, vIn[0].v) - offset;
73+
const auto distance1 = Dot(normal, vIn[1].v) - offset;
74+
75+
// If the points are behind the plane...
76+
// Ideally they are. Then we get face-vertex contact features which are simpler to
77+
// calculate. Note that it also helps to avoid changing the contact feature from the
78+
// given clip vertices. So the code here also accepts distances that are just slightly
79+
// over zero.
80+
if (distance0 <= 0_m || AlmostZero(StripUnit(distance0)))
81+
{
82+
vOut.push_back(vIn[0]);
83+
}
84+
if (distance1 <= 0_m || AlmostZero(StripUnit(distance1)))
85+
{
86+
vOut.push_back(vIn[1]);
87+
}
88+
89+
// If we didn't already find two points & the points are on different sides of the plane...
90+
if (size(vOut) < 2 && signbit(StripUnit(distance0)) != signbit(StripUnit(distance1)))
91+
{
92+
// Neither distance0 nor distance1 is 0 and either one or the other is negative (but not both).
93+
// Find intersection point of edge and plane
94+
// Vertex A is hitting edge B.
95+
const auto interp = distance0 / (distance0 - distance1);
96+
const auto vertex = vIn[0].v + (vIn[1].v - vIn[0].v) * interp;
97+
vOut.push_back(ClipVertex{vertex, GetVertexFaceContactFeature(indexA, vIn[0].cf.indexB)});
98+
}
99+
}
100+
101+
return vOut;
102+
}
103+
42104
constexpr auto face = ContactFeature::e_face;
43105
constexpr auto vertex = ContactFeature::e_vertex;
44106

0 commit comments

Comments
 (0)