Board index » delphi » How does OpenGL work with matrices under the hood?
Paul Nicholls
![]() Delphi Developer |
How does OpenGL work with matrices under the hood?2004-04-30 11:23:16 AM delphi249 Hi all, pardon me if this is a silly question (tm)....<G> when using OpenGL and I want to roate some object (in object coordinates) and then translate it to some position I do this type of thing: glLoadIdentity; ... glTranslatef(ObjectX,ObjectY,ObjectZ) glRotatef(ObjectAngle,0,1,0); DrawObject. I am used to doing it this way, but why is it necessary for the translation to come before the rotation in the code? Mathematically the rotation should be done before the translation, right? Does OpenGL do something similar to this in the background? (ignore exact code, only look at what it is doing) ModelMatrix: TMatrix3d; ModelMatrixOperationsIndex: Integer; ModelMatrixOperationsStack: array[0..MaxModelMatrixOperations - 1] of TMatrix3d; procedure glRotatef(Angle,ax,ay,az: Single); overload; begin ModelMatrixOperationsStack[ModelMatrixOperationsIndex] := ArbitaryAxisRotationMatrix(Vector3d(ax,ay,az),Angle); Inc(ModelMatrixOperationsIndex); end; procedure glTranslatef(tx,ty,tz: Single); begin ModelMatrixOperationsStack[ModelMatrixOperationsIndex] := TranslationMatrix3d(tx,ty,tz); Inc(ModelMatrixOperationsIndex); end; procedure glBegin(...); begin while(ModelMatrixOperationsIndex>0)do begin Dec(ModelMatrixOperationsIndex); ModelMatrix := MatrixMultiply(ModelMatrix,ModelMatrixOperationsStack[ModelMatrixOperationsI ndex]); end; ... end; procedure glVertex3f(x,y,z: Single); begin NewVertex := TransformVector(Vector3f(x,y,z),ModelMatrix); ... end; I am trying to understand why one needs to specify the matrix operations (rotation, translation, etc) around the other way... I am itching to know :) Thanks in advance, Paul Nicholls (Delphi 5/6 Professional) "See No Evil, Hear No Evil, EMail No Evil !" - Paul Nicholls XXXX@XXXXX.COM Replace '-' with '_' to reply |