OpenGl: Rotate the line about the end point

I am new to OpenGL and testing some kind of experimental code. I am using Open GL 4+. I was able to draw a line using this:

glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,1.0,0.0); glEnd(); 

Now I want to rotate this line around one of its end points, for example, the hand of a clock. How can I do it? I searched on the Internet, but there is nothing that actually shows a simple rotation of the line. I tried using glRotatef , but I think I'm missing some key thing because glRotatef did not affect the drawn string. It seems that all tutorials start with triangles (not dots and lines).

What is the OpenGL workflow to complete these tasks? I continue to run into code samples that use matrices, but I don’t understand exactly. I mean, should I explicitly track my latest matrices or abstract from OpenGL and take care internally?

I understand the math and the role of transformation matrices, but I am confused about the role of matrices in writing OpenGL code. If there are functions like glRotatef , why do I explicitly define matrices?

It would be very useful to have some resources that explain everything, starting from the most basic points, lines, and then from polygons, etc.

0
source share
1 answer

standard disclaimer: do not use the glBegine / glEnd family of functions instead of migrating to a shader-based configuration.

but here is a way to rotate (ignore the parameters)

 glPushMatrix(); glTranslate();//tranlate by -p where p is the point you want to rotate about glRotate();//rotate by some degrees glTranslate();//tranlate back by p glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,1.0,0.0); glEnd(); glPopMatrix(); 
+4
source

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


All Articles