Commit 4eb98c1c authored by Bergmann89's avatar Bergmann89

* [ugluVectorEx] implemented SqrLength and Cross

parent 37b1fe10
......@@ -10,6 +10,12 @@ uses
Classes, SysUtils,
ugluVectorEx, ugluMatrixExHelper;
const
maAxisX = 0;
maAxisY = 1;
maAxisZ = 2;
maPos = 3;
type
TgluMatrix2f = TgluMatrixF.TMat2;
TgluMatrix3f = TgluMatrixF.TMat3;
......
......@@ -428,6 +428,7 @@
type __HELPER_I = type helper(__HELPER) for __VEC
public
function Length: Double; inline;
function SqrLength: Double; inline;
function Abs: __VEC;
{$IF __SIZE <> 4}
function Add(const v: __VEC): __VEC; inline;
......@@ -453,6 +454,9 @@
{$IF __SIZE = 2}
function Angle2(const v: __VEC): Double; inline;
{$ENDIF}
{$IF __SIZE = 3}
function Cross(const v: __VEC): __VEC; inline;
{$ENDIF}
end;
operator * (const v: __VEC; const s: __IMPL.TBaseType): __VEC; inline;
operator * (const s: __IMPL.TBaseType; const v: __VEC): __VEC; inline;
......@@ -936,6 +940,11 @@
result := __IMPL.Length(self);
end;
function __HELPER_I.SqrLength: Double;
begin
result := __IMPL.SqrLength(self);
end;
function __HELPER_I.Abs: __VEC;
var i: Integer;
begin
......@@ -1011,6 +1020,13 @@
end;
{$ENDIF}
{$IF __SIZE = 3}
function __HELPER_F.Cross(const v: __VEC): __VEC; inline;
begin
result := __IMPL.Cross(self, v);
end;
{$ENDIF}
operator * (const v: __VEC; const s: __IMPL.TBaseType): __VEC;
begin
result := __IMPL.Multiply(v, s);
......
......@@ -47,6 +47,10 @@ type
class function Length(const v: TVector3): Double; overload; inline;
class function Length(const v: TVector4): Double; overload; inline;
class function SqrLength(const v: TVector2): Double; overload; inline;
class function SqrLength(const v: TVector3): Double; overload; inline;
class function SqrLength(const v: TVector4): Double; overload; inline;
class function Multiply(const v: TVector2; const a: T): TVector2; overload; inline;
class function Multiply(const v: TVector3; const a: T): TVector3; overload; inline;
class function Multiply(const v: TVector4; const a: T): TVector4; overload; inline;
......@@ -386,6 +390,21 @@ begin
result := SQRT(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]) * v[3];
end;
class function TgluVectorHelperI.SqrLength(const v: TVector2): Double;
begin
result := v[0]*v[0] + v[1]*v[1];
end;
class function TgluVectorHelperI.SqrLength(const v: TVector3): Double;
begin
result := v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
end;
class function TgluVectorHelperI.SqrLength(const v: TVector4): Double;
begin
result := (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]) * v[3];
end;
class function TgluVectorHelperI.Multiply(const v: TVector2; const a: T): TVector2;
begin
result[0] := v[0] * a;
......
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