PDA

View Full Version : draw a skeleton OpenGL



ensberg
05-16-2014, 01:18 AM
Hello
I am newbie in opengl programming, I have a problem I want to draw a skeleton.

I wrote a program but uses Loop, so I draw closed shapes.

I want to have a form like this:
1304

carsten neumann
05-16-2014, 01:50 AM
It seems to me you've already identified the problem: using GL_LINE_LOOP as primitive type will produce a closed loop, try GL_LINES or GL_LINE_STRIP instead. Note that for GL_LINES you'll have to repeat vertices that are both endpoint of a line and startpoint of the next one. Or perhaps I'm misunderstanding your question?

ensberg
05-16-2014, 02:04 AM
It seems to me you've already identified the problem: using GL_LINE_LOOP as primitive type will produce a closed loop, try GL_LINES or GL_LINE_STRIP instead. Note that for GL_LINES you'll have to repeat vertices that are both endpoint of a line and startpoint of the next one. Or perhaps I'm misunderstanding your question?

thank you

but that I use strip but I can draw without lifting the pen, and so I can not rlier members' arms legs ..... "

carsten neumann
05-16-2014, 02:27 AM
Draw multiple GL_LINE_STRIPs: if you are using glBegin()/glEnd(), end the current strip with glEnd() and start a new one with glBegin(GL_LINE_STRIP), if you are using glDrawArrays or some similar draw call you need multiple of those [1], one for each STRIP. Alternatively you can draw individual GL_LINES.

[1] When using indices (glDrawElements and friends) you could also make use of glPrimitiveRestartIndex, but that is more of an advanced topic.

PS: As you can see from the various alternatives in my reply it would be helpful if you included more details about what you are doing in future questions, that makes it easier to give an answer to your specific problem, see also Forum Posting Guidelines for suggestions of what to include in questions.

ensberg
05-16-2014, 03:49 AM
PS: As you can see from the various alternatives in my reply it would be helpful if you included more details about what you are doing in future questions, that makes it easier to give an answer to your specific problem, see also Forum Posting Guidelines for suggestions of what to include in questions.



if (pointsSupprimer.size() >= 2)
{
glBegin(GL_LINE_LOOP);


// glBegin(GL_POINTS);
for (int unsigned i = 0; i<pointsSupprimer.size(); i++) {
glColor3f(1.0, 0.0, 0.0);
glVertex2i(pointsSupprimer[i].xval, pointsSupprimer[i].yval);

}




glEnd();

glutSwapBuffers();

}

carsten neumann
05-16-2014, 05:01 AM
Please use
around source code snippets to preserve formatting, thanks!

Ok, so you are using glBegin()/glEnd(), but the code is still drawing one GL_LINE_LOOP, so all parts of the skeleton will be connected. As mentioned before, you'll have to draw multiple GL_LINE_STRIPs, one for each part of the skeleton, something like this pseudo code:



for each skeleton_part in skeleton:
{
glBegin(GL_LINE_STRIP);
for each vertex in skeleton_part:
{
glVertex2(vertex.x, vertex.y);
}
glEnd();
}

ensberg
05-16-2014, 05:47 AM
GL_LINE_STRIPs, one for each part of the skeleton, something like this pseudo code:



for each skeleton_part in skeleton:
{
glBegin(GL_LINE_STRIP);
for each vertex in skeleton_part:
{
glVertex2(vertex.x, vertex.y);
}
glEnd();
}

please every part of the skeleton will be stored in a table ?

carsten neumann
05-16-2014, 07:32 AM
I guess so, yes.
It really depends on what you want to do. If all you need is drawing the skeleton as lines and points representing a skeleton_part as an array (or std::vector) of vertices is sufficient; a skeleton would then be an array (or std::vector) of skeleton_parts. If on the other hand you want to eventually use the skeleton to animate a mesh it may be better to represent each joint as a distinct object.

ensberg
05-16-2014, 12:33 PM
I guess so, yes.
It really depends on what you want to do. If all you need is drawing the skeleton as lines and points representing a skeleton_part as an array (or std::vector) of vertices is sufficient; a skeleton would then be an array (or std::vector) of skeleton_parts. If on the other hand you want to eventually use the skeleton to animate a mesh it may be better to represent each joint as a distinct object.
oui je veux animer le squelette comme ša , c'est notre propre simulateur :
https://www.youtube.com/watch?v=XGjTt5H5Qt0

I did not understand "each joint as a distinct object "is what I have to define structures

thanks

carsten neumann
05-18-2014, 02:50 AM
Yes, I meant making a joint a struct or class, since in case you want to animate them you'll likely want to store a bunch of information about each joint. So, perhaps something along these lines:



struct Joint
{
vec3f offset_;
quatf rotation_;

Joint* parent_;
std::vector<Joint*> children_;
};

struct Skeleton
{
std::vector<Joint*> roots_;
};


Where quatf stores a quaternion. Note that the above is merely for illustration, there are other ways to represent the joint hierarchies and lots of options of what information to store in the joints.