123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2023 by Michael Van Canneyt
- member of the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- unit utcmatrix3d;
- {$mode ObjFPC}{$H+}
- interface
- uses
- Classes, SysUtils, fpcunit, testregistry, utmathvectorbase, types, system.math.vectors;
- Type
- { TTestMatrix3D }
- TTestMatrix3D = class(TCMathVectorsBase)
- Private
- FM : Array[1..3] of TMatrix3D;
- procedure ClearMatrices;
- function GetM(AIndex: Integer): TMatrix3D;
- procedure SetM(AIndex: Integer; AValue: TMatrix3D);
- Protected
- procedure SetUp; override;
- procedure TearDown; override;
- Property M1 : TMatrix3D Index 1 Read GetM Write SetM;
- Property M2 : TMatrix3D Index 2 Read GetM Write SetM;
- Property M3 : TMatrix3D Index 3 Read GetM Write SetM;
- Published
- procedure TestHookUp;
- constructor TestCreate;
- constructor TestCreateArray;
- Procedure TestZero;
- Procedure TestCreateLookAtDirLH;
- Procedure TestCreateLookAtDirRH;
- Procedure TestCreateLookAtLH;
- Procedure TestCreateLookAtRH;
- Procedure TestCreateOrthoLH;
- Procedure TestCreateOrthoOffCenterLH;
- Procedure TestCreateOrthoOffCenterRH;
- Procedure TestCreateOrthoRH;
- Procedure TestCreatePerspectiveFovLH;
- Procedure TestCreatePerspectiveFovRH;
- Procedure TestCreateRotation;
- Procedure TestCreateRotationX;
- Procedure TestCreateRotationY;
- Procedure TestCreateRotationZ;
- Procedure TestCreateRotationHeadingPitchBank;
- Procedure TestCreateRotationYawPitchRoll;
- Procedure TestCreateScaling;
- Procedure TestCreateTranslation;
- Procedure TestMultiplyPoint;
- Procedure TestMultiplyMatrix;
- Procedure TestMultiplyVector3D;
- Procedure TestMultiplyFactor;
- Procedure TestMultiplyFactor2;
- Procedure TestDiv;
- Procedure TestAdjoint;
- Procedure TestDeterminant;
- Procedure TestEyePosition;
- Procedure TestInverse;
- Procedure TestScale;
- Procedure TestToMatrix;
- Procedure TestTranspose;
- end;
- implementation
- procedure TTestMatrix3D.ClearMatrices;
- var
- I : integer;
- begin
- For I:=1 to 3 do
- FM[I]:=Default(TMatrix3D);
- end;
- Function TTestMatrix3D.GetM(AIndex: Integer): TMatrix3D;
- begin
- Result:=FM[aIndex];
- end;
- procedure TTestMatrix3D.SetM(AIndex: Integer; AValue: TMatrix3D);
- begin
- FM[aIndex]:=aValue;
- end;
- procedure TTestMatrix3D.SetUp;
- begin
- inherited SetUp;
- ClearMatrices;
- end;
- procedure TTestMatrix3D.TearDown;
- begin
- inherited TearDown;
- ClearMatrices;
- end;
- procedure TTestMatrix3D.TestHookUp;
- var
- I,C,R : Integer;
- begin
- For I:=1 to 3 do
- For R:=0 to 3 do
- For C:=0 to 3 do
- AssertEquals(Format('M%d[%d,%d]',[I,C,R]),0.0,FM[I].M[R].V[C]);
- end;
- constructor TTestMatrix3D.TestCreate;
- begin
- M1:=TMatrix3D.Create(1,2,3,4,
- 5,6,7,8,
- 9,10,11,12,
- 13,14,15,16);
- // actual test
- AssertMatrix3D('Create',1,2,3,4,
- 5,6,7,8,
- 9,10,11,12,
- 13,14,15,16,M1);
- // Test assert using array
- AssertMatrix3D('Create',[1,2,3,4,
- 5,6,7,8,
- 9,10,11,12,
- 13,14,15,16],M1);
- // Test assert using second matrix
- M2:=M1;
- AssertMatrix3D('Create',M2,M1);
- end;
- constructor TTestMatrix3D.TestCreateArray;
- begin
- M1:=TMatrix3D.Create([ 1, 2, 3, 4,
- 5, 6, 7, 8,
- 9, 10, 11, 12,
- 13, 14, 15, 16]);
- AssertMatrix3D('Create',1, 5, 9, 13,
- 2, 6, 10, 14,
- 3, 7, 11, 15,
- 4, 8, 12, 16, M1);
- end;
- procedure TTestMatrix3D.TestZero;
- begin
- M1:=TMatrix3D.Zero;
- AssertMatrix3D('Create',0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0, M1);
- end;
- procedure TTestMatrix3D.TestCreateLookAtDirLH;
- begin
- M1:=TMatrix3D.CreateLookAtDirLH(Point3D(0,0,0),Point3D(0,0,1),Point3D(0,0,1));
- // test 46
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 47
- M1:=TMatrix3D.CreateLookAtDirLH(Point3D(0,0,0),Point3D(0,1,0),Point3D(0,0,1));
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 48
- M1:=TMatrix3D.CreateLookAtDirLH(Point3D(0,0,0),Point3D(1,0,0),Point3D(0,0,1));
- AssertMatrix3D('Create 3',[ 0.0000, 0.0000,-1.0000, 0.0000,
- -1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateLookAtDirRH;
- begin
- // test 49
- M1:=TMatrix3D.CreateLookAtDirRH(Point3D(0,0,0),Point3D(0,0,1),Point3D(0,0,1));
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 50
- M1:=TMatrix3D.CreateLookAtDirRH(Point3D(0,0,0),Point3D(0,1,0),Point3D(0,0,1));
- AssertMatrix3D('Create 2',[ -1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 51
- M1:=TMatrix3D.CreateLookAtDirRH(Point3D(0,0,0),Point3D(1,0,0),Point3D(0,0,1));
- AssertMatrix3D('Create 3',[ 0.0000, 0.0000, 1.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateLookAtLH;
- begin
- M1:=TMatrix3D.CreateLookAtLH(Point3D(0,0,0),Point3D(0,0,1),Point3D(0,0,1));
- // test 52
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 53
- M1:=TMatrix3D.CreateLookAtLH(Point3D(0,0,0),Point3D(0,1,0),Point3D(0,0,1));
- AssertMatrix3D('Create 2',[ -1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 54
- M1:=TMatrix3D.CreateLookAtLH(Point3D(0,0,0),Point3D(1,0,0),Point3D(0,0,1));
- AssertMatrix3D('Create 3',[ 0.0000, 0.0000, 1.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateLookAtRH;
- begin
- M1:=TMatrix3D.CreateLookAtRH(Point3D(0,0,0),Point3D(0,0,1),Point3D(0,0,1));
- // test 55
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 56
- M1:=TMatrix3D.CreateLookAtRH(Point3D(0,0,0),Point3D(0,1,0),Point3D(0,0,1));
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 57
- M1:=TMatrix3D.CreateLookAtRH(Point3D(0,0,0),Point3D(1,0,0),Point3D(0,0,1));
- AssertMatrix3D('Create 3',[ 0.0000, 0.0000,-1.0000, 0.0000,
- -1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateOrthoLH;
- begin
- // test 58
- M1:=TMatrix3D.CreateOrthoLH(1,1,0,1);
- AssertMatrix3D('Create 1',[ 2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 59
- M1:=TMatrix3D.CreateOrthoLH(1,1,0,2);
- AssertMatrix3D('Create 2',[2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.5000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateOrthoRH;
- begin
- // test 60
- M1:=TMatrix3D.CreateOrthoRH(1,1,0,1);
- AssertMatrix3D('Create 1',[ 2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 61
- M1:=TMatrix3D.CreateOrthoRH(1,1,0,2);
- AssertMatrix3D('Create 2',[ 2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-0.5000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateOrthoOffCenterLH;
- begin
- // test 62
- M1:=TMatrix3D.CreateOrthoOffCenterLH(0,0,1,1,0,1);
- AssertMatrix3D('Create 1',[2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000,-2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- -1.0000, 1.0000, 0.0000, 1.0000],M1);
- // test 63
- M1:=TMatrix3D.CreateOrthoOffCenterLH(0,0,1,1,0,2);
- AssertMatrix3D('Create 2',[2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000,-2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.5000, 0.0000,
- -1.0000, 1.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateOrthoOffCenterRH;
- begin
- // test 64
- M1:=TMatrix3D.CreateOrthoOffCenterRH(0,0,1,1,0,1);
- AssertMatrix3D('Create 1',[2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000,-2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- -1.0000, 1.0000, 0.0000, 1.0000],M1);
- // test 65
- M1:=TMatrix3D.CreateOrthoOffCenterRH(0,0,1,1,0,2);
- AssertMatrix3D('Create 2',[ 2.0000, 0.0000, 0.0000, 0.0000,
- 0.0000,-2.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-0.5000, 0.0000,
- -1.0000, 1.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreatePerspectiveFovLH;
- begin
- // Test 66
- M1:=TMatrix3D.CreatePerspectiveFovLH(pi/2,1,0,1);
- AssertMatrix3D('Create 1',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 1.0000,
- 0.0000, 0.0000, 0.0000, 0.0000],M1);
- // Test 67
- M1:=TMatrix3D.CreatePerspectiveFovLH(pi/2,1,0,1,True);
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 1.0000,
- 0.0000, 0.0000,-0.0000, 0.0000], M1);
- end;
- procedure TTestMatrix3D.TestCreatePerspectiveFovRH;
- begin
- // Test 68
- M1:=TMatrix3D.CreatePerspectiveFovRH(pi/2,1,0,1);
- AssertMatrix3D('Create 1',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000,-1.0000,
- 0.0000, 0.0000, 0.0000, 0.0000],M1);
- // Test 69
- M1:=TMatrix3D.CreatePerspectiveFovRH(pi/2,1,0,1,True);
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000,-1.0000,
- 0.0000, 0.0000, 0.0000, 0.0000 ],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotation;
- begin
- // test 32
- M1:=TMatrix3D.CreateRotation(Point3D(1,0,0),Pi/2);
- AssertMatrix3D('Create 1',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000,-1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 33
- M1:=TMatrix3D.CreateRotation(Point3D(0,1,0),Pi/2);
- AssertMatrix3D('Create 2',[ 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 34
- M1:=TMatrix3D.CreateRotation(Point3D(0,0,1),pi/2);
- AssertMatrix3D('Create 3',[ -0.0000, 1.0000, 0.0000, 0.0000,
- -1.0000,-0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotationX;
- begin
- // test 40
- M1:=TMatrix3D.CreateRotationX(Pi/2);
- AssertMatrix3D('Create 1',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000,-1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotationY;
- begin
- // test 41
- M1:=TMatrix3D.CreateRotationY(Pi/2);
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotationZ;
- begin
- // test 42
- M1:=TMatrix3D.CreateRotationZ(Pi/2);
- AssertMatrix3D('Create 1',[ -0.0000, 1.0000, 0.0000, 0.0000,
- -1.0000,-0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotationHeadingPitchBank;
- begin
- // Test 37
- M1:=TMatrix3D.CreateRotationHeadingPitchBank(Pi/2,0,0);
- AssertMatrix3D('Create 1',[ 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- -1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // Test 38
- M1:=TMatrix3D.CreateRotationHeadingPitchBank(0,Pi/2,0);
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // Test 39
- M1:=TMatrix3D.CreateRotationHeadingPitchBank(0,0,Pi/2);
- AssertMatrix3D('Create 3',[ 0.0000,-1.0000, 0.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000 ],M1);
- end;
- procedure TTestMatrix3D.TestCreateRotationYawPitchRoll;
- begin
- // test 43
- M1:=TMatrix3D.CreateRotationYawPitchRoll(Pi/2,0,0);
- AssertMatrix3D('Create 1',[ 0.0000,-1.0000, 0.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000 ],M1);
- // test 44
- M1:=TMatrix3D.CreateRotationYawPitchRoll(0,Pi/2,0);
- AssertMatrix3D('Create 2',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000,-1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- // test 45
- M1:=TMatrix3D.CreateRotationYawPitchRoll(0,0,Pi/2);
- AssertMatrix3D('Create 3',[ 0.0000, 0.0000,-1.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M1);
- end;
- procedure TTestMatrix3D.TestCreateScaling;
- begin
- // test 71
- M1:=TMatrix3D.CreateScaling(Point3D(1,2,3));
- AssertMatrix3D('Create 1',[ 1, 0, 0, 0,
- 0, 2, 0, 0,
- 0, 0, 3, 0,
- 0, 0, 0, 1],M1);
- end;
- procedure TTestMatrix3D.TestCreateTranslation;
- begin
- // test 72
- M1:=TMatrix3D.CreateTranslation(Point3D(1,2,3));
- AssertMatrix3D('Create 1',[ 1.0000, 0.0000, 0.0000, 0.0000,
- 0.0000, 1.0000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 1.0000, 2.0000, 3.0000, 1.0000 ],M1);
- end;
- procedure TTestMatrix3D.TestMultiplyPoint;
- var
- P1,P2 : TPoint3D;
- begin
- P1:=Point3D(1,0,0);
- M1:=TMatrix3D.CreateRotationZ(pi/2);
- P2:=P1*M1;
- AssertPoint3D('Multiply 1',0,1,0,P2);
- M1:=TMatrix3D.CreateRotationY(pi/2);
- P2:=P1*M1;
- AssertPoint3D('Multiply 2',0,0,-1,P2);
- P1:=Point3D(0,1,0);
- M1:=TMatrix3D.CreateRotationX(pi/2);
- P2:=P1*M1;
- AssertPoint3D('Multiply 3',0,0,1,P2);
- end;
- procedure TTestMatrix3D.TestMultiplyMatrix;
- begin
- // Test 73
- M1:=TMatrix3D.Create( [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
- M2:=TMatrix3D.Create([16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]);
- M3:=M1*M2;
- AssertMatrix3D('Multiplied',[ 386.0000,274.0000,162.0000,50.0000,
- 444.0000,316.0000,188.0000,60.0000,
- 502.0000,358.0000,214.0000,70.0000,
- 560.0000,400.0000,240.0000,80.0000],m3);
- end;
- procedure TTestMatrix3D.TestMultiplyVector3D;
- var
- P1,P2 : TVector3D;
- begin
- P1:=Vector3D(1,0,0);
- M1:=TMatrix3D.CreateRotationZ(pi/2);
- P2:=P1*M1;
- AssertVector3D('Multiply 1',0,1,0,1,P2);
- M1:=TMatrix3D.CreateRotationY(pi/2);
- P2:=P1*M1;
- AssertVector3D('Multiply 2',0,0,-1,1,P2);
- P1:=Point3D(0,1,0);
- M1:=TMatrix3D.CreateRotationX(pi/2);
- P2:=P1*M1;
- AssertVector3D('Multiply 3',0,0,1,1,P2);
- end;
- procedure TTestMatrix3D.TestMultiplyFactor;
- begin
- M1:=TMatrix3D.Create( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
- M2:=2*M1;
- AssertMatrix3D('Multiplied',[ 2, 4, 6, 8,
- 10, 12, 14, 16,
- 18, 20, 22, 24,
- 26, 28, 30, 32],M2);
- end;
- procedure TTestMatrix3D.TestMultiplyFactor2;
- begin
- M1:=TMatrix3D.Create( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
- M3:=M1*2;
- AssertMatrix3D('Multiplied',[ 2, 4, 6, 8,
- 10, 12, 14, 16,
- 18, 20, 22, 24,
- 26, 28, 30, 32],M3);
- end;
- procedure TTestMatrix3D.TestDiv;
- begin
- M1:=TMatrix3D.Create( 2, 4, 6, 8,
- 10, 12, 14, 16,
- 18, 20, 22, 24,
- 26, 28, 30, 32);
- M3:=M1/2;
- AssertMatrix3D('Divided',[ 1 , 2, 3, 4,
- 5 , 6, 7, 8,
- 9 , 10, 11, 12,
- 13, 14, 15, 16 ],M3);
- end;
- procedure TTestMatrix3D.TestAdjoint;
- begin
- // Test 74
- M1:=TMatrix3D.CreateRotationZ(Pi/3);
- M2:=M1.Adjoint;
- AssertMatrix3D('Adjoint',[0.5000,-0.8660, 0.0000, 0.0000,
- 0.8660, 0.5000, 0.0000, 0.0000,
- 0.0000, 0.0000, 1.0000, 0.0000,
- 0.0000, 0.0000, 0.0000, 1.0000],M2);
- end;
- procedure TTestMatrix3D.TestDeterminant;
- begin
- // Test 75
- M1:=TMatrix3D.CreateRotationZ(Pi/3);
- AssertEquals('Determinant',1.0,M1.Determinant);
- // Test 76
- M1:=TMatrix3D.Create(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
- AssertEquals('Determinant',0,M1.Determinant);
- M1:=TMatrix3D.Create(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
- AssertEquals('Determinant',1,M1.Determinant);
- end;
- procedure TTestMatrix3D.TestEyePosition;
- begin
- // Test 77
- M1:=TMatrix3D.CreateRotationZ(Pi/3);
- AssertPoint3D('EyePosition 1',0,0,0,M1.EyePosition);
- // Test 78
- M1:=TMatrix3D.CreateRotationZ(Pi/3)*TMatrix3D.CreateTranslation(Point3D(1,0,0));
- AssertPoint3D('EyePosition 2',-0.50, 0.8660, 0,M1.EyePosition);
- end;
- procedure TTestMatrix3D.TestInverse;
- begin
- // Test 77
- M1:=TMatrix3D.CreateRotationZ(Pi/3);
- M2:=TMatrix3D.CreateRotationZ(-Pi/3);
- AssertMatrix3D('Inverse 1',M2,M1.Inverse);
- AssertMatrix3D('Inverse 2',TMatrix3D.Identity,M1*M1.Inverse);
- end;
- procedure TTestMatrix3D.TestScale;
- begin
- M1:=TMatrix3D.Create( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
- M3:=M1.Scale(2);
- AssertMatrix3D('Multiplied',[ 2, 4, 6, 8,
- 10, 12, 14, 16,
- 18, 20, 22, 24,
- 26, 28, 30, 32],M3);
- end;
- procedure TTestMatrix3D.TestToMatrix;
- Var
- M : TMatrix;
- begin
- M1:=TMatrix3D.CreateRotationZ(Pi/3);
- M:=M1.ToMatrix;
- AssertMatrix('To Matrix',TMatrix.CreateRotation(Pi/3),M);
- end;
- procedure TTestMatrix3D.TestTranspose;
- begin
- M1:=TMatrix3D.Create( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
- M2:=TMatrix3D.Create( [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
- M3:=M1.Transpose;
- AssertMatrix3D('Transposed',M2,M3);
- end;
- initialization
- RegisterTest(TTestMatrix3D);
- end.
|