delphi - OpenGL: Help with camera transformation -
After the details given in the OpenGL Superbible, I am trying to implement the camera-model in Delphi / OpenGL. The position of the camera is a forward vector and an up vector. Translating the camera works fine, but when I try to rotate the camera according to the forward vector, then I lose sight of my object.
function TCamera.GetCameraOrientation: TMatrix4f; Var x, z: T3DVector; Start z: = T3DVector.Create (-FForward.X, -FForward.y, -FForward.z); X: = T3DVector.Cross (z, FUp); Results [0, 0]: = x.x; Results [1, 0]: = x.Y; Results [2, 0]: = x. Zed; Results [3, 0]: = 0; Results [0, 1]: = FUp.X; Results [1, 1]: = FUp.Y; Results [2, 1]: = FUP.Z; Results [3, 1]: = 0; Results [0, 2]: = z.x; Results [1, 2]: = z.y; Results [2, 2]: = z.z; Results [3, 2]: = 0; Results [0, 3]: = 0; Results [1, 3]: = 0; Results [2, 3]: = 0; Results [3, 3]: = 1; End; Process TCamera.ApplyTransformation; Var Cameras: TMatrix4f; A, B, C: TMTix 4F; Start Camera: Orientation = getcamera; GlMultMatrixf (@cameraOrient); GlTranslatef (-FPosition.x, -FPosition.y, -FPosition.z); End; Looking at the position (0, 0, -15), the forward vector (0 to 1) and the up vector (0 to 0), I expect to get an identity-matrix from GetCameraOrientation -Math, but instead of me < / P> (1, 0, 0, 0) (0, 1, 0, 0) (0, 0, -1, 0) (0, 0, 0, 1)
If I change the vector forward (0 to -1) then I get the following matrix:
(- 1, 0, 0, 0) GlMultMatrix () and GlTranslate () after calling (0, 1, 0, 0) (0, 0, 1, 0) (0, 0, 0, 1)
, Glag () gives me the following GL_MODELVIEW_MATRIX:
(1, 0, 0, 0) ( 0, 1, 0, 0) (0, 0, -1, 0)) (0, 0, 15, 1)
I expected that 15 should be in column 4 , Line 3, column 3, line 4
Can anyone see where I get this wrong?
Edit: The original code of OpenGL Superbibile:
Inline zero gate camarometer orientation (M3d matrix 44FM) {M3D Vector 3Fx, Zed; // Create rotation matrix // Jade vector is reversed [0] = -Worfound [0]; Jade [1] = -Wordword [1]; Z [2] = -Wiford [2]; // x vector = y cross jade m3 deccross product (x, vv, z); // matrix has no translation information and // is transparent .... (Rows instead of columns) # Defined M (row, color) m [column * 4 + line] m (0, 0) = x [0 ]; M (0, 1) = x [1]; M (0, 2) = x [2]; M (0, 3) = 0.0; M (1, 0) = VEEP [0]; M (1, 1) = V V [1]; M (1, 2) = VEEP [2]; M (1, 3) = 0.0; M (2, 0) = z [0]; M (2, 1) = z [1]; M (2, 2) = z [2]; M (2, 3) = 0.0; M (3, 0) = 0.0; M (3, 1) = 0.0; M (3, 2) = 0.0; M (3, 3) = 1.0; #undef M} Inline Records ApplyCameraTransform (bool bRotOnly = false) {M3DMatrix44f m; GetCameraOrientation (M); // Camera Global Matrix (M) conversion; // If rotation only, do not translate (! BrotOnly) glTranslatef (-vOrigin [0], -VOrigin [1], -Orgin [2]); }
The result of the georrheination given to your code is quite clear: forward = ( 0, 0, 1) yields z = (0, 0, -1), which corresponds to the third line of matrix. The cross product of Z = (0, 0, -1) and FUP = (0, 1, 0) is in x = (1, 0, 0), which corresponds to the first row of the matrix. The second line is just a copy of the FEP and the fourth line is just fixed.
I did not really understand what you want to achieve, but when you rotate the camera, you will keep a clear eye on your object. If you look at a point in the real world and change your head - this is the only thing you have tried to reverse the order of translation and rotation?
Comments
Post a Comment