Skip to content

Commit 1711d4e

Browse files
committed
moved some code from scene.jl to contactPairs.jl
1 parent c85ca93 commit 1711d4e

File tree

3 files changed

+64
-67
lines changed

3 files changed

+64
-67
lines changed

src/Composition/_module.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ include(joinpath("joints", "Fix.jl"))
9999
include(joinpath("joints", "Revolute.jl"))
100100
include(joinpath("joints", "Prismatic.jl"))
101101

102+
include("contactPairs.jl")
103+
include(joinpath(Modia3D.path, "src", "contactDetection", "ContactDetectionMPR", "ContactDetectionMPR_handler.jl"))
104+
102105
include("scene.jl") # must be included after superObjects.jl
103106
include(joinpath("joints", "joints.jl"))
104107
include(joinpath("joints", "changeJointState.jl"))

src/Composition/contactPairs.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
#-------------------------------------- Default Contact Detection -------------------------------
3+
4+
"""
5+
ContactPairs(nzmax, collSuperObjs, noCPairs, dummyObject3D)
6+
7+
Generate a new ContactPairs structure used for communication between the Object3D handler and a ContactDetection handler.
8+
9+
- `DummyObject3D::Modia3D.AbstractObject3DFeature`: A dummy Object3D that can be used in the struct as element of a vector of Object3Ds
10+
to fill the vector with a dummy value of the correct type.
11+
"""
12+
mutable struct ContactPairs
13+
# Solid shapes used in contact detection (provided by Object3D handler)
14+
allowedToMove::Vector{Union{Bool,Nothing}}
15+
dummyObject3D::Modia3D.AbstractObject3DFeature # Dummy Object3D for non-used elements of z-Vector.
16+
17+
# Dimensions
18+
ne::Int # length(collSuperObjs)
19+
nz::Int # length(z)
20+
nzContact::Int # length(z | z has contact) length of z where zi has contact
21+
22+
function ContactPairs(world::Composition.Object3D, AABB::Vector{Vector{Basics.BoundingBox}}, superObjs::Vector{SuperObjsRow},
23+
allowedToMove::Vector{Union{Bool,Nothing}}, visualizeBoundingBox::Bool, nVisualContSupPoints::Int,
24+
visualizeContactPoints::Bool, visualizeSupportPoints::Bool, defaultContactSphereDiameter::Float64)
25+
@assert(length(superObjs) > 0)
26+
@assert(nVisualContSupPoints > 0)
27+
dummyObject3D = Composition.emptyObject3DFeature
28+
29+
lengthCollSuperObjs = length(superObjs)
30+
if lengthCollSuperObjs <= 1
31+
error("There's nothing to collide. All Object3Ds are rigidly connected.")
32+
end
33+
34+
nzContact = 0
35+
nz = 2
36+
37+
if lengthCollSuperObjs > 2
38+
nz = lengthCollSuperObjs
39+
end
40+
41+
if visualizeContactPoints
42+
addContactVisuObjToWorld!(world, nVisualContSupPoints, defaultContactSphereDiameter)
43+
end
44+
if visualizeSupportPoints
45+
addSupportVisuObjToWorld!(world, nVisualContSupPoints, defaultContactSphereDiameter)
46+
end
47+
48+
if visualizeBoundingBox
49+
addAABBVisuToWorld!(world, AABB)
50+
end
51+
52+
new(allowedToMove, dummyObject3D, lengthCollSuperObjs, nz, nzContact)
53+
end
54+
end
55+
56+
initializeContactDetection!(ch::Modia3D.AbstractContactDetection, collSuperObjs::Vector{Vector{Modia3D.AbstractObject3DFeature}}, noCPairs::Vector{Vector{Int64}}) = error("No contact detection handler defined.")
57+
selectContactPairsWithEvent!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
58+
selectContactPairsNoEvent!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
59+
getDistances!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
60+
setComputationFlag(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
61+
closeContactDetection!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")

src/Composition/scene.jl

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,6 @@ visualize!(renderer::Modia3D.AbstractRenderer, time::Float64) = error("No render
1414
closeVisualization(renderer::Modia3D.AbstractRenderer) = error("No renderer defined.")
1515

1616

17-
#-------------------------------------- Default Contact Detection -------------------------------
18-
19-
"""
20-
ContactPairs(nzmax, collSuperObjs, noCPairs, dummyObject3D)
21-
22-
Generate a new ContactPairs structure used for communication between the Object3D handler and a ContactDetection handler.
23-
24-
- `DummyObject3D::Modia3D.AbstractObject3DFeature`: A dummy Object3D that can be used in the struct as element of a vector of Object3Ds
25-
to fill the vector with a dummy value of the correct type.
26-
"""
27-
mutable struct ContactPairs
28-
# Solid shapes used in contact detection (provided by Object3D handler)
29-
allowedToMove::Vector{Union{Bool,Nothing}}
30-
dummyObject3D::Modia3D.AbstractObject3DFeature # Dummy Object3D for non-used elements of z-Vector.
31-
32-
# Dimensions
33-
ne::Int # length(collSuperObjs)
34-
nz::Int # length(z)
35-
nzContact::Int # length(z | z has contact) length of z where zi has contact
36-
37-
function ContactPairs(world::Composition.Object3D, AABB::Vector{Vector{Basics.BoundingBox}}, superObjs::Vector{SuperObjsRow},
38-
allowedToMove::Vector{Union{Bool,Nothing}}, visualizeBoundingBox::Bool, nVisualContSupPoints::Int,
39-
visualizeContactPoints::Bool, visualizeSupportPoints::Bool, defaultContactSphereDiameter::Float64)
40-
@assert(length(superObjs) > 0)
41-
@assert(nVisualContSupPoints > 0)
42-
dummyObject3D = Composition.emptyObject3DFeature
43-
44-
lengthCollSuperObjs = length(superObjs)
45-
if lengthCollSuperObjs <= 1
46-
error("There's nothing to collide. All Object3Ds are rigidly connected.")
47-
end
48-
49-
nzContact = 0
50-
nz = 2
51-
52-
if lengthCollSuperObjs > 2
53-
nz = lengthCollSuperObjs
54-
end
55-
56-
amountVisuPoints = 1
57-
amountSuppPoints = 1
58-
if visualizeContactPoints
59-
addContactVisuObjToWorld!(world, nVisualContSupPoints, defaultContactSphereDiameter)
60-
end
61-
if visualizeSupportPoints
62-
addSupportVisuObjToWorld!(world, nVisualContSupPoints, defaultContactSphereDiameter)
63-
end
64-
65-
if visualizeBoundingBox
66-
addAABBVisuToWorld!(world, AABB)
67-
end
68-
69-
70-
new(allowedToMove, dummyObject3D, lengthCollSuperObjs, nz, nzContact)
71-
end
72-
end
73-
74-
initializeContactDetection!(ch::Modia3D.AbstractContactDetection, collSuperObjs::Vector{Vector{Modia3D.AbstractObject3DFeature}}, noCPairs::Vector{Vector{Int64}}) = error("No contact detection handler defined.")
75-
selectContactPairsWithEvent!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
76-
selectContactPairsNoEvent!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
77-
getDistances!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
78-
setComputationFlag(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
79-
closeContactDetection!(ch::Modia3D.AbstractContactDetection) = error("No contact detection handler defined.")
80-
81-
include(joinpath(Modia3D.path, "src", "contactDetection", "ContactDetectionMPR", "ContactDetectionMPR_handler.jl"))
82-
83-
8417

8518
#-------------------------------------- Gravity field ----------------------------------
8619

0 commit comments

Comments
 (0)