Plotting lines between two time varying points

Discussion in 'Visualization' started by AQLK, Oct 12, 2016.

  1. While using the whole OpenGL handling provided by MuJoCo Pro (C++):

    Is there a straightforward way to draw a straight line (i.e. a thin cylinder, or tendon) or an arrow-like vector (like the reaction forces in the simulate.cpp demo program) between two time varying points, given in global coordinates?

    Right now I move my visual movement 'target points' around by adding them as multiple spheres (that are excluded from collision) as geometry in the <worldbody></worldbody>. Before every visual render instance I change their positions 'm->geom_pos[i + 3 * bodyNo]' dependent on simulation time (where i = 0,1,2). This works fine. But the same 'trick' did not work for me for cylinders drawn with the 'fromto' option. I want to avoid the work-around of moving 1 attachment point around and then rotating my cylinder such that it points in the direction of the other and then scaling the cylinder length (if I find the way to do that).

    For example, among other uses, I would like to draw a line or arrow-vector to show the COM velocity of a moving system, or a straight line reference trajectory that changes over time. For me it is OK to have these lines as geometry in <worldbody></worldbody> or in any other way.
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    You can define a tendon between two sites. It will be rendered as a thin cylinder, and you can adjust the color and width of the cylinder in the XML.

    Alternatively, you can add abstract geoms yourself to mjvScene, after mjv_updateScene and before mjr_render. See the new VR code sample for an illustration -- in that case I am adding geoms that are not in the model, so as show the handheld Vive controllers in space. This new sample is now available in the Programming chapter.
  3. Hi
    Isn't this possible to draw lines without having to add tendons to the model?
    For example, I'm thinking of having a function drawLine(P0, P1) that draws a lines between two points in the current frame. This could be a great tool for visualization.
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    Yes, you can do it in two ways without adding tendons:

    1. Add abstract geoms (cylinders or capsules) to mjvScene, and then mjr_render will render them
    2. Add your own OpenGL code, after mjr_render
    Amin likes this.
  5. Thanks for your help.
    Yeah I did that but now the line is always in black. I tried disabling shaders and textures but it didn't work. It seems mjlib.mjr_render is changing some settings that stays permanent. Any idea how to fix that?
  6. Emo Todorov

    Emo Todorov Administrator Staff Member

    If you write your OpenGL code, make sure you set all OpenGL states that you need for your code to work. This has to be done at each frame, because mjr_render sets many things internally. So it is better to add abstract geoms to mjvScene.