0
votes

I've been asked to draw a 3D tetrahedron and make it rotate around x, y or z axes, depending on the input give. Now I have 2 questions.

1) I drew my tetrahedron using GL_TRIANGLES (4 triangles). Is this the better way of drawing primitives that will be transformed?

2) I belive (from other questions I've seen) that axis rotation is about translating to that specific axis, something like (0, -y, -z), then rotate around that axis and finally translate back. Ok now, what should be values for translating? y, z? I have lots of values representing each vertex, do I translate them all?

1

1 Answers

0
votes

I think it will be faster to just write complete answer than ask a lot questions:

  1. To ease and speed things up a bit, use GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP instead.

  2. Depends on the pipeline you are using:

    2.1 Old OpenGL (< 2.0, shaderless)

    You shouldn't translate and rotate them by hand. Use appropriate glRotate and glTranslate functions. Values you need to pass to these functions are obviously related to desired position and rotation of your object; you will find more about them in documentation.

    2.2 Programmable pipeline

    Create a transformation matrix (either by yourself or by using library such as GLM) and pass it as uniform to vertex shader.

And oh, you don't translate to an axis. You multiply the current view matrix by appropriate rotation matrix.

You should try to read a bit more before digging into more complicated topics. This tutorial covers modern OpenGL very well; if you are forced to use old OpenGL, take a look at NeHe tutorials instead.