How to display basic shapes (circle, lines, rectangles)

Typically: "How do I... ", "How can I... " questions
Post Reply
andypark
Posts: 13
Joined: 04 Jun 2015, 19:10

How to display basic shapes (circle, lines, rectangles)

Post by andypark » 29 Jun 2015, 16:31

Hi I would like to know how I can display basic shapes (circle, lines, rectangles, and etc.) on the objects of the simulation environment. For example, I would like to display footprints for a humanoid robot on the floor while the robot performs a locomotion task, so we could compare the desired footsteps and the actual footsteps for checking the accuracy of the controller. Could you give me any example which can be helpful for me to learn about how to display and manipulate those basic shapes in the simulation environment?

Thanks!

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: How to display basic shapes (circle, lines, rectangles)

Post by coppelia » 29 Jun 2015, 18:04

Hello,

you can use the API function simAddDrawingObject and similar. It will allow you to draw lines or triangles (or points, simple discs, simple boxes). The idea is to create a container (with simAddDrawingObject), then add items to that container with simAddDrawingObjectItem.

Following example will draw random lines in the scene (put this in a non-threaded child script):

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
	lineContainer=simAddDrawingObject(sim_drawing_lines,2,0,-1,9999,{1,1,1})
end


if (sim_call_type==sim_childscriptcall_actuation) then
	local line={math.random(),math.random(),math.random(),math.random(),math.random(),math.random()}
	simAddDrawingObjectItem(lineContainer,line)
-- To empty the container:
--	simAddDrawingObjectItem(lineContainer,nil)
end
Cheers

andypark
Posts: 13
Joined: 04 Jun 2015, 19:10

Re: How to display basic shapes (circle, lines, rectangles)

Post by andypark » 29 Jun 2015, 18:11

Wow, this example is very helpful! Thanks a lot! :)
coppelia wrote:Hello,

you can use the API function simAddDrawingObject and similar. It will allow you to draw lines or triangles (or points, simple discs, simple boxes). The idea is to create a container (with simAddDrawingObject), then add items to that container with simAddDrawingObjectItem.

Following example will draw random lines in the scene (put this in a non-threaded child script):

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
	lineContainer=simAddDrawingObject(sim_drawing_lines,2,0,-1,9999,{1,1,1})
end


if (sim_call_type==sim_childscriptcall_actuation) then
	local line={math.random(),math.random(),math.random(),math.random(),math.random(),math.random()}
	simAddDrawingObjectItem(lineContainer,line)
-- To empty the container:
--	simAddDrawingObjectItem(lineContainer,nil)
end
Cheers

Post Reply