Different OpenGL actions depending on the Maya view used

I have cpp code that displays simple OpenGL forms in Maya. If using an outdated viewport, then I have exactly what I want: the arrows go along the x axis:

enter image description here

However, if I use the same code in ViewPort 2.0, then the arrows follow the movements of the camera:

enter image description here

enter image description here

This only happens if I applied glTranslatef (which I will need to use).

This is a piece of code:

for (int i=0;i<10;i++) { glPushMatrix(); glTranslatef(i,0,0); glBegin(GL_LINES); // Arrow glVertex3f(0, y, z); glVertex3f(1, y, z); glVertex3f(1, y, z); glVertex3f(0.5, y, z+0.5); glVertex3f(1, y, z); glVertex3f(0.5, y, z-0.5); glEnd(); glPopMatrix(); } 

How can I have the correct behavior in the “new” Maya viewport?

+6
source share
1 answer

Following my comment, it looks like this: the translation is performed in another frame of coordinates in rendering, which tells me that it is tied to another stack of matrices.

So, in the old viewport (where your result is “correct”) you combine the translation into the model’s viewing matrix, but in case of 2.0, you probably combine the translation into the projection matrix, which will lead to the translation apparently relative to the screen, and not to the view .

I would recommend that all the correct state be properly configured in your render call, for example by setting the desired glMatrixMode () before messing with the matrix stack, etc.

+2
source

Source: https://habr.com/ru/post/990054/


All Articles