1

In OpenGL, I can easily rotate a triangle by something like this:

glRotate(90, 1, 0, 0); glBegin(GL_TRIANGLES); glVertex3f(-1,0,0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); glRotate(-90, 1, 0, 0); 

However, I would like to rotate only ONE of the vertices, not all three that make up the triangle, but I would still like it to draw the triangle in the end.

I've tried things like this, but with no success:

glBegin(GL_TRIANGLES); // Rotate only this vertex. glRotate(90, 1, 0, 0); glVertex3f(-1,0,0); glRotate(-90, 1, 0, 0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); 

Any ideas?

1 Answer 1

2

You can't put glRotate calls between glBegin and glEnd.

Only a subset of GL commands can be used between glBegin and glEnd. The commands are glVertex, glColor, glIndex, glNormal, glTexCoord, glEvalCoord, glEvalPoint, glMaterial, and glEdgeFlag.

See http://www.cs.uccs.edu/~ssemwal/glman.html for the full description.

To answer your question, if you only want to rotate a single vertex you will need to do that manually before calling glVertex3f.

In your specific case (rotation about the x axis) the code would look like this:

glBegin(GL_TRIANGLES); // Rotate only the vertex <x,y,z> about the x axis an angle of theta. glVertex3f(x, y*cos(theta) - z*sin(theta), y*sin(theta) + z*cos(theta)); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); 

If you need to rotate about a different axis or a generic axis then see the wikipedia page about 3D rotation matrices: http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply. Would you happen to know what the code would look like for that, while still drawing the triangle (with one point rotated)?
I've edited the answer to show code for doing that in your specific example. By the way rotating the point (-1,0,0) about the x axis doesn't move the point.
Worked like a charm! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.