Rotating a Group of Vectors
Solution 1:
Construct 4x4 transform matrix instead of Quaternions.
-
Do not forget that OpenGL has column wise matrix
so for
double m[16];
isX
axis vector inm[ 0],m[ 1],m[ 2]
isY
axis vector inm[ 4],m[ 5],m[ 6]
isZ
axis vector inm[ 8],m[ 9],m[10]
and position is inm[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. -
construction
- set
Z
-axis vector to your triangle normal - set position (LCS origin) to mid point of your triangle (or average point form its vertexes)
-
now you just need
X
andY
axises which is easylet
X = any triangle vertex - triangle midpoint
orX = 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 letY = X x Z
the cross product will create vector perpendicular toX
andZ
(which also lies in triangle plane). now put all this inside matrix and load it to OpenGL as
ModelView
matrix or what ever.
- set