Browse Source

* fixed some small bugs

master
Bergmann89 9 years ago
parent
commit
0a5d1c5344
1 changed files with 17 additions and 12 deletions
  1. +17
    -12
      ugluMatrixExHelper.pas

+ 17
- 12
ugluMatrixExHelper.pas View File

@@ -64,9 +64,9 @@ type
class function Multiply(const m: TMat3; const v: TBaseType): TMat3; overload; inline; class function Multiply(const m: TMat3; const v: TBaseType): TMat3; overload; inline;
class function Multiply(const m: TMat4; const v: TBaseType): TMat4; overload; inline; class function Multiply(const m: TMat4; const v: TBaseType): TMat4; overload; inline;


class function Invert(const m: TMat2): TMat2; overload; inline;
class function Invert(const m: TMat3): TMat3; overload; inline;
class function Invert(const m: TMat4): TMat4; overload; inline;
class function Invert(m: TMat2): TMat2; overload; inline;
class function Invert(m: TMat3): TMat3; overload; inline;
class function Invert(m: TMat4): TMat4; overload; inline;


class function CreateTranslate(const v: TVectorHelper.TVector2): TMat3; class function CreateTranslate(const v: TVectorHelper.TVector2): TMat3;
class function CreateTranslate(const v: TVectorHelper.TVector3): TMat4; class function CreateTranslate(const v: TVectorHelper.TVector3): TMat4;
@@ -80,8 +80,8 @@ type
class function CreateShear(const v: TVectorHelper.TVector2): TMat3; class function CreateShear(const v: TVectorHelper.TVector2): TMat3;
class function CreateShear(const x, y, z: TVectorHelper.TVector2): TMat4; class function CreateShear(const x, y, z: TVectorHelper.TVector2): TMat4;
private private
class function GetElement(p: PBaseType; x, y, sz: Integer): TBaseType; // TODO inline;
class procedure SetElement(p: PBaseType; x, y, sz: Integer; v: TBaseType); // TODO inline;
class function GetElement(p: PBaseType; x, y, sz: Integer): TBaseType; inline;
class procedure SetElement(p: PBaseType; x, y, sz: Integer; v: TBaseType); inline;


class procedure Transpose(src, dst: PBaseType; sz: Integer); class procedure Transpose(src, dst: PBaseType; sz: Integer);
class procedure Sub(src, dst: PBaseType; sz, c, r: Integer); class procedure Sub(src, dst: PBaseType; sz, c, r: Integer);
@@ -285,25 +285,30 @@ begin
Mult(@m[0,0], @result[0,0], 4, 4, v); Mult(@m[0,0], @result[0,0], 4, 4, v);
end; end;


class function TgluMatrixHelper.Invert(const m: TMat2): TMat2;
class function TgluMatrixHelper.Invert(m: TMat2): TMat2;
begin begin
result[0,0] := m[1,1]; result[0,0] := m[1,1];
result[0,1] := -m[0,1]; result[0,1] := -m[0,1];
result[1,0] := -m[1,0]; result[1,0] := -m[1,0];
result[1,1] := m[0,0]; result[1,1] := m[0,0];
Mult(@result[0,0], @result[0,0], 2, 2, 1 / Determinant(m));
m := result;
Mult(@m[0,0], @result[0,0], 2, 2, 1 / Determinant(m));
end; end;


class function TgluMatrixHelper.Invert(const m: TMat3): TMat3;
class function TgluMatrixHelper.Invert(m: TMat3): TMat3;
var d: TBaseType;
begin begin
result := Adjoint(m);
Mult(@result[0,0], @result[0,0], 2, 2, 1 / Determinant(m));
d := Determinant(m);
m := Adjoint(m);
Mult(@m[0,0], @result[0,0], 3, 3, 1 / d);
end; end;


class function TgluMatrixHelper.Invert(const m: TMat4): TMat4;
class function TgluMatrixHelper.Invert(m: TMat4): TMat4;
var d: TBaseType;
begin begin
d := Determinant(m);
result := Adjoint(m); result := Adjoint(m);
Mult(@result[0,0], @result[0,0], 3, 3, 1 / Determinant(m));
Mult(@m[0,0], @result[0,0], 4, 4, 1 / d);
end; end;


class function TgluMatrixHelper.CreateTranslate(const v: TVectorHelper.TVector2): TMat3; class function TgluMatrixHelper.CreateTranslate(const v: TVectorHelper.TVector2): TMat3;


Loading…
Cancel
Save