I use sim.addGraphCurve to add moving tracks in the environment. I can see the tracks normally in Legacy OpenGL, but I find that the tracks are gone in OpenGL3. I think I can still see the tracks in OpenGL3. What should I do?
Cheers
The problem of trajectory display in Simulation
Re: The problem of trajectory display in Simulation
Hello,
this is correct. The same actually also happens with drawing objects.
What you should do is create primitive shapes, similar to as in following example:
Cheers
this is correct. The same actually also happens with drawing objects.
What you should do is create primitive shapes, similar to as in following example:
Code: Select all
function createTubeStrip(path, color, diameter, singleShape)
function createTube(coord1, coord2, color, diameter)
color = color or {0, 0, 0}
diameter = diameter or 0.005
local retVal = -1
local v1 = Vector3(coord1)
local v2 = Vector3(coord2)
local dv = v2 - v1
local length = dv:norm()
if length > 0.001 then
local dw = dv / length
local a = math.acos(dw[3])
retVal = sim.createPrimitiveShape(sim.primitiveshape_cylinder, {diameter, diameter, length}, 4 + 8)
local p = sim.getObjectPosition(retVal)
sim.setObjectPosition(retVal, {p[1], p[2], p[3] + length * 0.5})
sim.setObjectColor(retVal, 0, sim.colorcomponent_ambient_diffuse, color)
sim.relocateShapeFrame(retVal, {0, 0, 0, 0, 0, 0, 1})
if dw[3] < 0.9999 then
local np = sim.rotateAroundAxis({0, 0, 0, 0, 0, 0, 1}, {1, 0, 0}, {0, 0, 0}, a)
a = math.pi * 0.5 + math.atan2(dw[2], dw[1])
np = sim.rotateAroundAxis(np, {0, 0, 1}, {0, 0, 0}, a)
sim.setObjectPose(retVal, np)
sim.setObjectPosition(retVal, coord1)
end
end
return retVal
end
local allTubes = {}
for i = 0, #path // 3 - 2, 1 do
local coord1 = {path[3 * i + 1], path[3 * i + 2], path[3 * i + 3]}
local coord2 = {path[3 * i + 4], path[3 * i + 5], path[3 * i + 6]}
local h = createTube(coord1, coord2, color, diameter)
if h >= 0 then
allTubes[#allTubes + 1] = h
end
end
local retVal = -1
if singleShape then
if #allTubes >= 1 then
if #allTubes > 1 then
retVal = sim.groupShapes(allTubes, true)
else
retVal = allTubes[1]
end
sim.relocateShapeFrame(retVal, {0, 0, 0, 0, 0, 0, 1})
end
else
retVal = allTubes
end
return retVal
end
function sysCall_init()
sim = require('sim')
local path = {0.0, 0.0, 0.0, 0.5, 0.0, 0.1, 0.5, 0.5, 0.2, 0.0, 0.5, 0.3, 0.0, 0.0, 0.4, 0.0, 0.0, 0.0}
local color = {1.0, 0.0, 0.0}
local diameter = 0.02
local singleShape = true
local ret = createTubeStrip(path, color, diameter, singleShape)
print(ret)
end