Rotating a Group of Vectors

Solution 1:

Construct 4x4 transform matrix instead of Quaternions.

img

  1. Do not forget that OpenGL has column wise matrix

    so for double m[16];
    is X axis vector in m[ 0],m[ 1],m[ 2]
    is Y axis vector in m[ 4],m[ 5],m[ 6]
    is Z axis vector in m[ 8],m[ 9],m[10]
    and position is in m[12],m[13],m[14]

    The LCS mean local coordinate system (your triangle or object or whatever)
    and GCS mean global coordinate system (world or whatever).

    All the X,Y,Z vectors should be normalized to unit vectors otherwise scaling will occur.

  2. construction

    1. set Z-axis vector to your triangle normal
    2. set position (LCS origin) to mid point of your triangle (or average point form its vertexes)
    3. now you just need X and Y axises which is easy

      let X = any triangle vertex - triangle midpoint
      or X = substraction of any 2 vertexes of triangle

      The only condition that must be met for X is that it must lie on triangle plane.
      Now let Y = X x Z the cross product will create vector perpendicular to X and Z (which also lies in triangle plane).

    4. now put all this inside matrix and load it to OpenGL as ModelView matrix or what ever.