Contemporary OpenGL Question

In my OpenGL study (I think this is the OpenGL red book), I came across an example of an articulating robot model consisting of a “shoulder”, “lower arm”, “arm” and five or more “fingers”. Each of the sections should be able to move independently, but be restrained by the “joints” (the upper and lower “shoulders” are always connected by “elbow”).

In immediate mode (glBegin / glEnd) they use one cube grid called a “member” and use scaled copies of this single grid for each part of the arm, arm, etc. The “movements” were made by clicking the rotations on the stack of the transformation matrix for each of the following joints: shoulder, elbow, wrist, joint — you get an image.

Now this solves the problem, but since it uses the old, outdated immediate mode, I still do not understand the solution to this problem in the modern OpenGL context. My question is: how to approach this problem using modern OpenGL? In particular, should each individual “member” keep track of its own current transformation matrix, since the matrix stacks are no longer kosher?

+7
source share
3 answers

To a large extent. If you really need it, implementing your own stack interface is pretty simple. You would literally just save the stack, and then implement any matrix operations that you need using your preferred math library, and somehow initialize your desired matrix form using the top element of the stack.

In the example of your robot, assume that the link is presented in the form of a tree (or even a graphic, if you prefer), with relative transformations specified between each body. To draw the hand of a robot, you simply bypass this data structure and set the transformation of any child body to the transformation of the parent body composed with its own. For example:

def draw_linkage(body, view): //Draw the body using view matrix for child, relative_xform in body.edges: if visited[child]: continue draw_linkage(child, view * relative_xform) 
+3
source

In the case of rigid parts connected by joints, each part is usually treated as a separate submech, loading the appropriate matrix in front of the pattern.

In the case of “connected” / “continuous” meshes, like a face, animation usually occurs through bones and strain targets. Each of them determines the deformation, and each vertex in the grid is assigned a weight, how much it depends on each deformer. Technically, this can be applied to a rigid limb model, also giving each limb one deforming nonzero weight.

In any case, any decent animation system preserves traces of the transformations (matrices) themselves, the functions of the OpenGL element stack are rarely used in serious applications (since OpenGL was invented). But usually transformations are stored in a hierarchy.

+1
source

Usually you do this at a level above openGL using a script.

The same matrix transformation in each node in the scenography tree simply maps simply to openGL matrices, so it’s pretty efficient.

+1
source

All Articles