Bläddra i källkod

* added some more usefull methods to ugluMatrixEx

master
Bergmann89 10 år sedan
förälder
incheckning
827bc67d57
2 ändrade filer med 92 tillägg och 26 borttagningar
  1. +76
    -26
      ugluMatrixEx.inc
  2. +16
    -0
      ugluMatrixEx.pas

+ 76
- 26
ugluMatrixEx.inc Visa fil

@@ -15,44 +15,54 @@
function Transpose: __MAT; inline; function Transpose: __MAT; inline;
function Determinant: Double; inline; function Determinant: Double; inline;
function Invert: __MAT; inline; function Invert: __MAT; inline;
function Multiply(const m: __MAT): __MAT; inline;


class function TryFromString(const s: String; out m: __MAT): Boolean; inline; static; class function TryFromString(const s: String; out m: __MAT): Boolean; inline; static;
class function FromString(const s: String): __MAT; inline; static; class function FromString(const s: String): __MAT; inline; static;


{$IF __SIZE = 3} {$IF __SIZE = 3}
function AxisX: __VEC3; inline;
function AxisY: __VEC3; inline;
function Position: __VEC3; inline;

function Sub(const aCol, aRow: Integer): __IMPL.TMat2; inline; function Sub(const aCol, aRow: Integer): __IMPL.TMat2; inline;
function Adjoint: __MAT; inline; function Adjoint: __MAT; inline;
function Translate(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline;
function Translate(const v: __VEC2): __MAT; inline;
function Translate(const x, y: __IMPL.TBaseType): __MAT; inline; function Translate(const x, y: __IMPL.TBaseType): __MAT; inline;
function Scale(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline;
function Scale(const v: __VEC2): __MAT; inline;
function Scale(const v: __IMPL.TBaseType): __MAT; inline; function Scale(const v: __IMPL.TBaseType): __MAT; inline;
function Shear(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline;
function Shear(const v: __VEC2): __MAT; inline;
function Shear(const x, y: __IMPL.TBaseType): __MAT; inline; function Shear(const x, y: __IMPL.TBaseType): __MAT; inline;
function Rotate(const a: Double): __MAT; inline; function Rotate(const a: Double): __MAT; inline;


class function CreateTranslate(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline; static;
class function CreateTranslate(const v: __VEC2): __MAT; inline; static;
class function CreateTranslate(const x, y: __IMPL.TBaseType): __MAT; inline; static; class function CreateTranslate(const x, y: __IMPL.TBaseType): __MAT; inline; static;
class function CreateScale(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline; static;
class function CreateScale(const v: __VEC2): __MAT; inline; static;
class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static; class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static;
class function CreateShear(const v: __IMPL.TVectorHelper.TVector2): __MAT; inline; static;
class function CreateShear(const v: __VEC2): __MAT; inline; static;
class function CreateShear(const x, y: __IMPL.TBaseType): __MAT; inline; static; class function CreateShear(const x, y: __IMPL.TBaseType): __MAT; inline; static;
class function CreateRotate(const a: Double): __MAT; inline; static; class function CreateRotate(const a: Double): __MAT; inline; static;
{$ELSEIF __SIZE = 4} {$ELSEIF __SIZE = 4}
function AxisX: __VEC4; inline;
function AxisY: __VEC4; inline;
function AxisZ: __VEC4; inline;
function Position: __VEC4; inline;

function Sub(const aCol, aRow: Integer): __IMPL.TMat3; inline; function Sub(const aCol, aRow: Integer): __IMPL.TMat3; inline;
function Adjoint: __MAT; inline; function Adjoint: __MAT; inline;
function Translate(const v: __IMPL.TVectorHelper.TVector3): __MAT; inline;
function Translate(const v: __VEC3): __MAT; inline;
function Translate(const x, y, z: __IMPL.TBaseType): __MAT; inline; function Translate(const x, y, z: __IMPL.TBaseType): __MAT; inline;
function Scale(const v: __IMPL.TVectorHelper.TVector3): __MAT; inline;
function Scale(const v: __VEC3): __MAT; inline;
function Scale(const v: __IMPL.TBaseType): __MAT; inline; function Scale(const v: __IMPL.TBaseType): __MAT; inline;
function Rotate(const axis: __IMPL.TVectorHelper.TVector3; const a: Double): __MAT; inline;
function Rotate(const axis: __VEC3; const a: Double): __MAT; inline;


class function CreateTranslate(const v: __IMPL.TVectorHelper.TVector3): __MAT; inline; static;
class function CreateTranslate(const v: __VEC3): __MAT; inline; static;
class function CreateTranslate(const x, y, z: __IMPL.TBaseType): __MAT; inline; static; class function CreateTranslate(const x, y, z: __IMPL.TBaseType): __MAT; inline; static;
class function CreateScale(const v: __IMPL.TVectorHelper.TVector3): __MAT; inline; static;
class function CreateScale(const v: __VEC3): __MAT; inline; static;
class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static; class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static;
class function CreateShear(const x, y, z: __IMPL.TVectorHelper.TVector2): __MAT; inline; static;
class function CreateShear(const x, y, z: __VEC2): __MAT; inline; static;
class function CreateShear(const xy, xz, yx, yz, zx, zy: __IMPL.TBaseType): __MAT; inline; static; class function CreateShear(const xy, xz, yx, yz, zx, zy: __IMPL.TBaseType): __MAT; inline; static;
class function CreateRotate(const axis: __IMPL.TVectorHelper.TVector3; const a: Double): __MAT; inline; static;
class function CreateRotate(const axis: __VEC3; const a: Double): __MAT; inline; static;
{$ENDIF} {$ENDIF}
end; end;


@@ -107,6 +117,11 @@
result := __IMPL.Invert(self); result := __IMPL.Invert(self);
end; end;


function __HELPER.Multiply(const m: __MAT): __MAT;
begin
result := __IMPL.Multiply(self, m);
end;

class function __HELPER.TryFromString(const s: String; out m: __MAT): Boolean; class function __HELPER.TryFromString(const s: String; out m: __MAT): Boolean;
begin begin
result := __IMPL.TryFromString(s, m); result := __IMPL.TryFromString(s, m);
@@ -119,6 +134,21 @@
end; end;


{$IF __SIZE = 3} {$IF __SIZE = 3}
function __HELPER.AxisX: __VEC3;
begin
result := self[0];
end;

function __HELPER.AxisY: __VEC3;
begin
result := self[1];
end;

function __HELPER.Position: __VEC3;
begin
result := self[2];
end;

function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat2; function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat2;
begin begin
result := __IMPL.Sub(self, aCol, aRow); result := __IMPL.Sub(self, aCol, aRow);
@@ -129,7 +159,7 @@
result := __IMPL.Adjoint(self); result := __IMPL.Adjoint(self);
end; end;


function __HELPER.Translate(const v: __IMPL.TVectorHelper.TVector2): __MAT;
function __HELPER.Translate(const v: __VEC2): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v)); result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v));
end; end;
@@ -139,7 +169,7 @@
result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y))); result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y)));
end; end;


function __HELPER.Scale(const v: __IMPL.TVectorHelper.TVector2): __MAT;
function __HELPER.Scale(const v: __VEC2): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateScale(v)); result := __IMPL.Multiply(self, __IMPL.CreateScale(v));
end; end;
@@ -149,7 +179,7 @@
result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v))); result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v)));
end; end;


function __HELPER.Shear(const v: __IMPL.TVectorHelper.TVector2): __MAT;
function __HELPER.Shear(const v: __VEC2): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateShear(v)); result := __IMPL.Multiply(self, __IMPL.CreateShear(v));
end; end;
@@ -164,7 +194,7 @@
result := __IMPL.Multiply(self, __IMPL.CreateRotate(a)); result := __IMPL.Multiply(self, __IMPL.CreateRotate(a));
end; end;


class function __HELPER.CreateTranslate(const v: __IMPL.TVectorHelper.TVector2): __MAT;
class function __HELPER.CreateTranslate(const v: __VEC2): __MAT;
begin begin
result := __IMPL.CreateTranslate(v); result := __IMPL.CreateTranslate(v);
end; end;
@@ -174,7 +204,7 @@
result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y)); result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y));
end; end;


class function __HELPER.CreateScale(const v: __IMPL.TVectorHelper.TVector2): __MAT;
class function __HELPER.CreateScale(const v: __VEC2): __MAT;
begin begin
result := __IMPL.CreateScale(v); result := __IMPL.CreateScale(v);
end; end;
@@ -184,7 +214,7 @@
result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v)); result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v));
end; end;


class function __HELPER.CreateShear(const v: __IMPL.TVectorHelper.TVector2): __MAT;
class function __HELPER.CreateShear(const v: __VEC2): __MAT;
begin begin
result := __IMPL.CreateShear(v); result := __IMPL.CreateShear(v);
end; end;
@@ -199,6 +229,26 @@
result := __IMPL.CreateRotate(a); result := __IMPL.CreateRotate(a);
end; end;
{$ELSEIF __SIZE = 4} {$ELSEIF __SIZE = 4}
function __HELPER.AxisX: __VEC4;
begin
result := self[0];
end;

function __HELPER.AxisY: __VEC4;
begin
result := self[1];
end;

function __HELPER.AxisZ: __VEC4;
begin
result := self[2];
end;

function __HELPER.Position: __VEC4;
begin
result := self[3];
end;

function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat3; function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat3;
begin begin
result := __IMPL.Sub(self, aRow, aCol); result := __IMPL.Sub(self, aRow, aCol);
@@ -209,7 +259,7 @@
result := __IMPL.Adjoint(self); result := __IMPL.Adjoint(self);
end; end;


function __HELPER.Translate(const v: __IMPL.TVectorHelper.TVector3): __MAT;
function __HELPER.Translate(const v: __VEC3): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v)); result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v));
end; end;
@@ -219,7 +269,7 @@
result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z))); result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z)));
end; end;


function __HELPER.Scale(const v: __IMPL.TVectorHelper.TVector3): __MAT;
function __HELPER.Scale(const v: __VEC3): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateScale(v)); result := __IMPL.Multiply(self, __IMPL.CreateScale(v));
end; end;
@@ -229,12 +279,12 @@
result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v))); result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v)));
end; end;


function __HELPER.Rotate(const axis: __IMPL.TVectorHelper.TVector3; const a: Double): __MAT;
function __HELPER.Rotate(const axis: __VEC3; const a: Double): __MAT;
begin begin
result := __IMPL.Multiply(self, __IMPL.CreateRotate(axis, a)); result := __IMPL.Multiply(self, __IMPL.CreateRotate(axis, a));
end; end;


class function __HELPER.CreateTranslate(const v: __IMPL.TVectorHelper.TVector3): __MAT;
class function __HELPER.CreateTranslate(const v: __VEC3): __MAT;
begin begin
result := __IMPL.CreateTranslate(v); result := __IMPL.CreateTranslate(v);
end; end;
@@ -244,7 +294,7 @@
result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z)); result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z));
end; end;


class function __HELPER.CreateScale(const v: __IMPL.TVectorHelper.TVector3): __MAT;
class function __HELPER.CreateScale(const v: __VEC3): __MAT;
begin begin
result := __IMPL.CreateScale(v); result := __IMPL.CreateScale(v);
end; end;
@@ -254,7 +304,7 @@
result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v)); result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v));
end; end;


class function __HELPER.CreateShear(const x, y, z: __IMPL.TVectorHelper.TVector2): __MAT;
class function __HELPER.CreateShear(const x, y, z: __VEC2): __MAT;
begin begin
result := __IMPL.CreateShear(x, y, z); result := __IMPL.CreateShear(x, y, z);
end; end;
@@ -267,7 +317,7 @@
__IMPL.TVectorHelper.Vector2(zx, zy)); __IMPL.TVectorHelper.Vector2(zx, zy));
end; end;


class function __HELPER.CreateRotate(const axis: __IMPL.TVectorHelper.TVector3; const a: Double): __MAT;
class function __HELPER.CreateRotate(const axis: __VEC3; const a: Double): __MAT;
begin begin
result := __IMPL.CreateRotate(axis, a); result := __IMPL.CreateRotate(axis, a);
end; end;


+ 16
- 0
ugluMatrixEx.pas Visa fil

@@ -32,6 +32,10 @@ type




{$DEFINE __MATRIX_HELPER_INTERFACE} {$DEFINE __MATRIX_HELPER_INTERFACE}
{$DEFINE __VEC2 := TgluVector2f}
{$DEFINE __VEC3 := TgluVector3f}
{$DEFINE __VEC4 := TgluVector4f}

{$DEFINE __IMPL := TgluMatrixF} {$DEFINE __IMPL := TgluMatrixF}
{$DEFINE __SIZE := 2} {$DEFINE __SIZE := 2}
{$DEFINE __VEC := TgluVector2f} {$DEFINE __VEC := TgluVector2f}
@@ -55,6 +59,10 @@ type






{$DEFINE __VEC2 := TgluVector2d}
{$DEFINE __VEC3 := TgluVector3d}
{$DEFINE __VEC4 := TgluVector4d}

{$DEFINE __IMPL := TgluMatrixD} {$DEFINE __IMPL := TgluMatrixD}
{$DEFINE __SIZE := 2} {$DEFINE __SIZE := 2}
{$DEFINE __VEC := TgluVector2d} {$DEFINE __VEC := TgluVector2d}
@@ -80,6 +88,10 @@ type
implementation implementation


{$DEFINE __MATRIX_HELPER_IMPL} {$DEFINE __MATRIX_HELPER_IMPL}
{$DEFINE __VEC2 := TgluVector2f}
{$DEFINE __VEC3 := TgluVector3f}
{$DEFINE __VEC4 := TgluVector4f}

{$DEFINE __IMPL := TgluMatrixF} {$DEFINE __IMPL := TgluMatrixF}
{$DEFINE __SIZE := 2} {$DEFINE __SIZE := 2}
{$DEFINE __VEC := TgluVector2f} {$DEFINE __VEC := TgluVector2f}
@@ -103,6 +115,10 @@ implementation






{$DEFINE __VEC2 := TgluVector2d}
{$DEFINE __VEC3 := TgluVector3d}
{$DEFINE __VEC4 := TgluVector4d}

{$DEFINE __IMPL := TgluMatrixD} {$DEFINE __IMPL := TgluMatrixD}
{$DEFINE __SIZE := 2} {$DEFINE __SIZE := 2}
{$DEFINE __VEC := TgluVector2d} {$DEFINE __VEC := TgluVector2d}


Laddar…
Avbryt
Spara