-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathContact display.lua
82 lines (73 loc) · 2.81 KB
/
Contact display.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
sim = require 'sim'
function sysCall_info()
return {autoStart = false, menu = 'Tools\nContact display'}
end
function sysCall_addOnScriptSuspend()
return {cmd = 'cleanup'}
end
function sysCall_init()
sim.addLog(
sim.verbosity_scriptinfos,
"During simulation, all dynamic contacts in the scenes will be parsed and visualized."
)
end
function sysCall_afterSimulation()
clean()
end
function sysCall_cleanup()
clean()
end
function sysCall_sensing()
if lineContainer == nil then
black = {0, 0, 0}
purple = {1, 0, 1}
lightBlue = {0, 1, 1}
forceVectorScaling = 0.05
forceVectorWidth = 4
contactPointSize = 0.01
-- Add a line and a sphere container:
lineContainer = sim.addDrawingObject(
sim.drawing_lines, forceVectorWidth, 0, -1, 1000, black, black, black,
purple
)
sphereContainer = sim.addDrawingObject(
sim.drawing_spherepoints, contactPointSize, 0, -1, 1000, black, black,
black, lightBlue
)
end
-- empty the containers:
sim.addDrawingObjectItem(lineContainer, nil)
sim.addDrawingObjectItem(sphereContainer, nil)
-- Fill the containers with contact information:
index = 0
while (true) do
objectsInContact, contactPt, forceDirectionAndAmplitude = sim.getContactInfo(
sim.handle_all,
sim.handle_all, index
)
if #objectsInContact == 2 then
line = {contactPt[1], contactPt[2], contactPt[3], 0, 0, 0}
line[4] = contactPt[1] + forceDirectionAndAmplitude[1] * forceVectorScaling
line[5] = contactPt[2] + forceDirectionAndAmplitude[2] * forceVectorScaling
line[6] = contactPt[3] + forceDirectionAndAmplitude[3] * forceVectorScaling
sim.addDrawingObjectItem(lineContainer, line)
line[4] = contactPt[1] - forceDirectionAndAmplitude[1] * forceVectorScaling
line[5] = contactPt[2] - forceDirectionAndAmplitude[2] * forceVectorScaling
line[6] = contactPt[3] - forceDirectionAndAmplitude[3] * forceVectorScaling
sim.addDrawingObjectItem(lineContainer, line)
sim.addDrawingObjectItem(sphereContainer, line)
index = index + 1
else
break
end
end
end
function clean()
-- Remove the containers:
if lineContainer then
sim.removeDrawingObject(lineContainer)
lineContainer = nil
sim.removeDrawingObject(sphereContainer)
sphereContainer = nil
end
end