Commit 88f4552e authored by Bergmann89's avatar Bergmann89

* added invert camera position

parent 3aca9124
......@@ -73,9 +73,15 @@ type
TglcCamera = class(TglcFrustum)
private
fPosition: TgluMatrix4f;
fInvertPos: TgluMatrix4f;
fInvertValid: Boolean;
function GetInvertPos: TgluMatrix4f;
function GetPositionPtr: Pointer;
procedure SetPosition(aValue: TgluMatrix4f);
public
property Position: TgluMatrix4f read fPosition write fPosition;
property Position: TgluMatrix4f read fPosition write SetPosition;
property InvertPos: TgluMatrix4f read GetInvertPos;
property PositionPtr: Pointer read GetPositionPtr;
procedure Move(const aVec: TgluVector3f);
......@@ -279,6 +285,23 @@ begin
result := @fPosition[0, 0];
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcCamera.GetInvertPos: TgluMatrix4f;
begin
if not fInvertValid then begin
fInvertValid := true;
fInvertPos := gluMatrixInvert(fPosition);
end;
result := fInvertPos;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcCamera.SetPosition(aValue: TgluMatrix4f);
begin
fPosition := aValue;
fInvertValid := false;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcCamera.Move(const aVec: TgluVector3f);
begin
......@@ -339,7 +362,8 @@ end;
constructor TglcCamera.Create;
begin
inherited Create;
fPosition := gluMatrixIdentity;
fPosition := gluMatrixIdentity;
fInvertValid := false
end;
end.
......
......@@ -194,6 +194,7 @@ type
function gluVectorScalar(const v1, v2: TgluVector2f): Single; overload;
function gluVectorAngle(const v1, v2: TgluVector3f): Single; overload;
function gluVectorAngle(const v1, v2: TgluVector2f): Single; overload;
function gluVectorAngle2(const v1, v2: TgluVector2f): Single;
function gluVectorEquals(const v1, v2: TgluVector2f): Boolean; overload;
function gluVectorEquals(const v1, v2: TgluVector3f): Boolean; overload;
function gluVectorEquals(const v1, v2: TgluVector4f): Boolean; overload;
......@@ -699,12 +700,24 @@ end;
//Berechnet den Winkel zwischen den übergebenen Vectoren
//@v1: 1. vektor;
//@v2: 2. Vektor;
//@result: Winkel zwischen v1 und v2;
//@result: Winkel zwischen v1 und v2 im Bereich: (0°; 180°);
function gluVectorAngle(const v1, v2: TgluVector2f): Single;
begin
result := ArcCos(gluVectorScalar(v1, v2)/(gluVectorLength(v1)*gluVectorLength(v2)));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Berechnet den Winkel zwischen den übergebenen Vectoren
//@v1: 1. vektor;
//@v2: 2. Vektor;
//@result: Winkel zwischen v1 und v2 im Bereich: [-180°; 180°) ;
function gluVectorAngle2(const v1, v2: TgluVector2f): Single;
begin
result := arctan2(
v2[0] * v1[1] - v2[1] * v1[0],
v2[0] * v1[0] + v2[1] * v1[1]);
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function gluVectorEquals(const v1, v2: TgluVector2f): Boolean;
begin
......
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