Commit dce20821 authored by Martok's avatar Martok

* [ugluMatrixEx] implemented Create(Vector)

* [ugluVectorEx] implemented Multiply(vec,vec), redefine operator *
* [ugluVectorEx] provide Add/Sub & operator +/- also for Vec4
parent ecd1cfe2
......@@ -35,6 +35,7 @@
function Shear(const x, y: __IMPL.TBaseType): __MAT; inline;
function Rotate(const a: Double): __MAT; inline;
class function Create(const x, y, z: __VEC3): __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 CreateScale(const v: __VEC2): __MAT; inline; static;
......@@ -56,6 +57,7 @@
function Scale(const v: __IMPL.TBaseType): __MAT; inline;
function Rotate(const axis: __VEC3; const a: Double): __MAT; inline;
class function Create(const x, y, z, w: __VEC4): __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 CreateScale(const v: __VEC3): __MAT; inline; static;
......@@ -194,6 +196,11 @@
result := __IMPL.Multiply(self, __IMPL.CreateRotate(a));
end;
class function __HELPER.Create(const x, y, z: __VEC3): __MAT;
begin
result := __IMPL.Create(x, y, z);
end;
class function __HELPER.CreateTranslate(const v: __VEC2): __MAT;
begin
result := __IMPL.CreateTranslate(v);
......@@ -284,6 +291,11 @@
result := __IMPL.Multiply(self, __IMPL.CreateRotate(axis, a));
end;
class function __HELPER.Create(const x, y, z, w: __VEC4): __MAT;
begin
result := __IMPL.Create(x, y, z, w);
end;
class function __HELPER.CreateTranslate(const v: __VEC3): __MAT;
begin
result := __IMPL.CreateTranslate(v);
......
......@@ -68,6 +68,9 @@ type
class function Invert(m: TMat3): TMat3; overload; inline;
class function Invert(m: TMat4): TMat4; overload; inline;
class function Create(const x, y, z: TVectorHelper.TVector3): TMat3;
class function Create(const x, y, z, w: TVectorHelper.TVector4): TMat4;
class function CreateTranslate(const v: TVectorHelper.TVector2): TMat3;
class function CreateTranslate(const v: TVectorHelper.TVector3): TMat4;
......@@ -311,6 +314,21 @@ begin
Mult(@m[0,0], @result[0,0], 4, 4, 1 / d);
end;
class function TgluMatrixHelper.Create(const x, y, z: TVectorHelper.TVector3): TMat3;
begin
Result[0]:= x;
Result[1]:= y;
Result[2]:= z;
end;
class function TgluMatrixHelper.Create(const x, y, z, w: TVectorHelper.TVector4): TMat4;
begin
Result[0]:= x;
Result[1]:= y;
Result[2]:= z;
Result[3]:= w;
end;
class function TgluMatrixHelper.CreateTranslate(const v: TVectorHelper.TVector2): TMat3;
begin
result[0, 0] := 1.0;
......
......@@ -430,18 +430,15 @@
function Length: Double; inline;
function SqrLength: Double; inline;
function Abs: __VEC;
{$IF __SIZE <> 4}
function Add(const v: __VEC): __VEC; inline;
function Subtract(const v: __VEC): __VEC; inline;
{$ENDIF}
function Multiply(const v: __IMPL.TBaseType): __VEC; inline;
function Multiply(const v: __IMPL.TBaseType): __VEC; overload; inline;
function Multiply(const v: __VEC): __VEC; overload; inline;
function Clamp(const min, max: __VEC): __VEC; inline;
function Clamp(const min, max: __IMPL.TBaseType): __VEC; inline;
end;
{$IF __SIZE <> 4}
operator + (const v1, v2: __VEC): __VEC; inline;
operator - (const v1, v2: __VEC): __VEC; inline;
{$ENDIF}
{$IFDEF __HELPER_F}
type __HELPER_F = type helper(__HELPER_I) for __VEC
public
......@@ -460,7 +457,7 @@
end;
operator * (const v: __VEC; const s: __IMPL.TBaseType): __VEC; inline;
operator * (const s: __IMPL.TBaseType; const v: __VEC): __VEC; inline;
operator * (const v1, v2: __VEC): __IMPL.TBaseType; inline;
operator * (const v1, v2: __VEC): __VEC; inline;
operator / (const v: __VEC; const s: __IMPL.TBaseType): __VEC; inline;
{$ENDIF}
{$ENDIF}
......@@ -952,7 +949,6 @@
result[i] := System.abs(self[i]);
end;
{$IF __SIZE <> 4}
function __HELPER_I.Add(const v: __VEC): __VEC;
begin
result := __IMPL.Add(self, v);
......@@ -962,13 +958,17 @@
begin
result := __IMPL.Sub(self, v);
end;
{$ENDIF}
function __HELPER_I.Multiply(const v: __IMPL.TBaseType): __VEC;
begin
result := __IMPL.Multiply(self, v);
end;
function __HELPER_I.Multiply(const v: __VEC): __VEC;
begin
result := __IMPL.Multiply(self, v);
end;
function __HELPER_I.Clamp(const min, max: __VEC): __VEC;
begin
result := __IMPL.Clamp(self, min, max);
......@@ -979,7 +979,6 @@
result := __IMPL.Clamp(self, min, max);
end;
{$IF __SIZE <> 4}
operator + (const v1, v2: __VEC): __VEC;
begin
result := __IMPL.Add(v1, v2);
......@@ -989,7 +988,6 @@
begin
result := __IMPL.Sub(v1, v2);
end;
{$ENDIF}
{$IFDEF __HELPER_F}
function __HELPER_F.Normalize: __VEC;
begin
......@@ -1037,9 +1035,9 @@
result := __IMPL.Multiply(v, s);
end;
operator * (const v1, v2: __VEC): __IMPL.TBaseType;
operator * (const v1, v2: __VEC): __VEC;
begin
result := __IMPL.Dot(v1, v2);
result := __IMPL.Multiply(v1, v2);
end;
operator / (const v: __VEC; const s: __IMPL.TBaseType): __VEC;
......
......@@ -55,11 +55,17 @@ type
class function Multiply(const v: TVector3; const a: T): TVector3; overload; inline;
class function Multiply(const v: TVector4; const a: T): TVector4; overload; inline;
class function Multiply(const v1, v2: TVector2): TVector2; overload; inline;
class function Multiply(const v1, v2: TVector3): TVector3; overload; inline;
class function Multiply(const v1, v2: TVector4): TVector4; overload; inline;
class function Add(const v1, v2: TVector2): TVector2; overload; inline;
class function Add(const v1, v2: TVector3): TVector3; overload; inline;
class function Add(const v1, v2: TVector4): TVector4; overload; inline;
class function Sub(const v1, v2: TVector2): TVector2; overload; inline;
class function Sub(const v1, v2: TVector3): TVector3; overload; inline;
class function Sub(const v1, v2: TVector4): TVector4; overload; inline;
class function ClampVal(const v, aMin, aMax: T): T; overload; inline;
class function Clamp(const v, aMin, aMax: TVector2): TVector2; overload; inline;
......@@ -426,6 +432,27 @@ begin
result[3] := v[3] * a;
end;
class function TgluVectorHelperI.Multiply(const v1, v2: TVector2): TVector2;
begin
result[0] := v1[0] * v2[0];
result[1] := v1[1] * v2[1];
end;
class function TgluVectorHelperI.Multiply(const v1, v2: TVector3): TVector3;
begin
result[0] := v1[0] * v2[0];
result[1] := v1[1] * v2[1];
result[2] := v1[2] * v2[2];
end;
class function TgluVectorHelperI.Multiply(const v1, v2: TVector4): TVector4;
begin
result[0] := v1[0] * v2[0];
result[1] := v1[1] * v2[1];
result[2] := v1[2] * v2[2];
result[3] := v1[3] * v2[3];
end;
class function TgluVectorHelperI.Add(const v1, v2: TVector2): TVector2;
begin
result[0] := v1[0] + v2[0];
......@@ -439,6 +466,15 @@ begin
result[2] := v1[2] + v2[2];
end;
class function TgluVectorHelperI.Add(const v1, v2: TVector4): TVector4;
begin
result[0] := v1[0] + v2[0];
result[1] := v1[1] + v2[1];
result[2] := v1[2] + v2[2];
result[3] := v1[3] + v2[3];
end;
class function TgluVectorHelperI.Sub(const v1, v2: TVector2): TVector2;
begin
result[0] := v1[0] - v2[0];
......@@ -452,6 +488,14 @@ begin
result[2] := v1[2] - v2[2];
end;
class function TgluVectorHelperI.Sub(const v1, v2: TVector4): TVector4;
begin
result[0] := v1[0] - v2[0];
result[1] := v1[1] - v2[1];
result[2] := v1[2] - v2[2];
result[3] := v1[3] - v2[3];
end;
class function TgluVectorHelperI.ClampVal(const v, aMin, aMax: T): T;
begin
if (v < aMin) then
......
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