Commit dc5cc222 authored by Martok's avatar Martok

[glcCamera, gluMatrix] Generalize Lookat matrix function

parent 88b0293e
......@@ -224,11 +224,7 @@ end;
procedure TglcFrustum.Activate;
begin
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
if fIsOrthogonal then
{$IFNDEF OPENGL_ES}glOrtho{$ELSE}glOrthof{$ENDIF}(fLeft, fRight, fBottom, fTop, fNear, fFar)
else
{$IFNDEF OPENGL_ES}glFrustum{$ELSE}glFrustumf{$ENDIF}(fLeft, fRight, fBottom, fTop, fNear, fFar);
glLoadMatrixf(@fProjMatrix[0, 0]);
glMatrixMode(GL_MODELVIEW);
end;
......@@ -329,19 +325,8 @@ end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcCamera.LookAt(const aEye, aCenter, aUp: TgluVector3f);
var
f, up, s, u: TgluVector3f;
M: TgluMatrix4f;
begin
f:= gluVectorNormalize(aCenter - aEye);
up:= gluVectorNormalize(aUp);
s:= gluVectorNormalize(f >< up);
u:= s >< f;
M[0]:= gluVector4f(s[0], u[0], -f[0], 0.0);
M[1]:= gluVector4f(s[1], u[1], -f[1], 0.0);
M[2]:= gluVector4f(s[2], u[2], -f[2], 0.0);
M[3]:= gluVector4f( 0, 0, 0, 1.0);
fPosition := gluMatrixMult(M, gluMatrixTranslate(-1*aEye));
fPosition:= ugluMatrix.gluLookAt(aEye, aCenter, aUp);
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -61,6 +61,7 @@ type
function gluMatrixDeterminant(const m: TgluMatrix4f): Single; overload;
function gluMatrixAdjoint(const m: TgluMatrix4f): TgluMatrix4f;
function gluMatrixInvert(const m: TgluMatrix4f): TgluMatrix4f;
function gluLookAt(const aEye, aCenter, aUp: TgluVector3f): TgluMatrix4f;
operator * (const m1, m2: TgluMatrix4f): TgluMatrix4f;
operator * (const m: TgluMatrix4f; const v: TgluVector4f): TgluVector4f;
......@@ -90,7 +91,7 @@ end;
operator * (const m: TgluMatrix4f; const v: TgluVector3f): TgluVector3f;
begin
result := gluVector3f(gluMatrixMultVec(m, gluVEctor4f(v, 1.0)));
result := gluVector3f(gluMatrixMultVec(m, gluVector4f(v, 1.0)));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -314,5 +315,26 @@ begin
result[i,j] := result[i,j] / d;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//erstellt eine Rotationsmatrix zur Sicht auf einen Punkt
//@aEye: Position des Auges;
//@aCenter: Punkt auf den geblickt wird;
//@aUp: Hoch-Vektor;
function gluLookAt(const aEye, aCenter, aUp: TgluVector3f): TgluMatrix4f;
var
f, up, s, u: TgluVector3f;
M: TgluMatrix4f;
begin
f:= gluVectorNormalize(aCenter - aEye);
up:= gluVectorNormalize(aUp);
s:= gluVectorNormalize(f >< up);
u:= s >< f;
M[0]:= gluVector4f(s[0], u[0], -f[0], 0.0);
M[1]:= gluVector4f(s[1], u[1], -f[1], 0.0);
M[2]:= gluVector4f(s[2], u[2], -f[2], 0.0);
M[3]:= gluVector4f( 0, 0, 0, 1.0);
Result:= gluMatrixMult(M, gluMatrixTranslate(-1*aEye));
end;
end.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment