| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestX3DNodesNurbs" -*- |
| 2 |
{ |
| 3 |
Copyright 2020-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Test NURBS from X3DNodes unit. } |
| 18 |
unit TestX3DNodesNurbs; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses |
| 23 |
Classes, SysUtils, |
| 24 |
CastleTester, CastleVectors, X3DNodes; |
| 25 |
|
| 26 |
type |
| 27 |
TTestX3DNodesNurbs = class(TCastleTestCase) |
| 28 |
procedure TestNurbsCurvePoint; |
| 29 |
procedure TestNurbsSurfacePoint; |
| 30 |
end; |
| 31 |
|
| 32 |
implementation |
| 33 |
|
| 34 |
procedure TTestX3DNodesNurbs.TestNurbsCurvePoint; |
| 35 |
var |
| 36 |
CurveNode: TNurbsCurveNode; |
| 37 |
Coordinate: TCoordinateNode; |
| 38 |
begin |
| 39 |
Coordinate := TCoordinateNode.Create; |
| 40 |
Coordinate.SetPoint([ |
| 41 |
Vector3(2.285389, 1.235778, 1.636090), |
| 42 |
Vector3(1, 0, 0), |
| 43 |
Vector3(1.141864, 1.003204, -1.775073), |
| 44 |
Vector3(1, 0, 0), |
| 45 |
Vector3(3.120634, 1.865495, 2.322197) |
| 46 |
]); |
| 47 |
|
| 48 |
CurveNode := TNurbsCurveNode.Create; |
| 49 |
CurveNode.ControlPoint := Coordinate; |
| 50 |
|
| 51 |
AssertVectorEquals(Vector3(2.285389, 1.235778, 1.636090), CurveNode.Point(0)); |
| 52 |
AssertVectorEquals(Vector3(3.120634, 1.865495, 2.322197), CurveNode.Point(1)); |
| 53 |
|
| 54 |
FreeAndNil(CurveNode); |
| 55 |
end; |
| 56 |
|
| 57 |
procedure TTestX3DNodesNurbs.TestNurbsSurfacePoint; |
| 58 |
var |
| 59 |
SurfaceNode: TNurbsPatchSurfaceNode; |
| 60 |
Coordinate: TCoordinateNode; |
| 61 |
OutputNormal: TVector3; |
| 62 |
begin |
| 63 |
Coordinate := TCoordinateNode.Create; |
| 64 |
Coordinate.SetPoint([ |
| 65 |
Vector3(2, 2, 10), |
| 66 |
Vector3(3, 2, 10), |
| 67 |
Vector3(4, 2, 10), |
| 68 |
|
| 69 |
Vector3(2, 3, 10), |
| 70 |
Vector3(3, 3, 10), |
| 71 |
Vector3(4, 3, 10), |
| 72 |
|
| 73 |
Vector3(2, 4, 10), |
| 74 |
Vector3(3, 4, 10), |
| 75 |
Vector3(4, 4, 10) |
| 76 |
]); |
| 77 |
|
| 78 |
SurfaceNode := TNurbsPatchSurfaceNode.Create; |
| 79 |
SurfaceNode.ControlPoint := Coordinate; |
| 80 |
SurfaceNode.UDimension := 3; |
| 81 |
SurfaceNode.VDimension := 3; |
| 82 |
|
| 83 |
// test TNurbsSurfaceNode.Point |
| 84 |
AssertVectorEquals(Vector3(2, 2, 10), SurfaceNode.Point(0, 0)); |
| 85 |
AssertVectorEquals(Vector3(4, 4, 10), SurfaceNode.Point(1, 1)); |
| 86 |
|
| 87 |
// test TNurbsSurfaceNode.Point with additional OutputNormal param |
| 88 |
AssertVectorEquals(Vector3(2, 2, 10), SurfaceNode.Point(0, 0, @OutputNormal)); |
| 89 |
AssertVectorEquals(Vector3(0, 0, 1), OutputNormal); |
| 90 |
AssertVectorEquals(Vector3(4, 4, 10), SurfaceNode.Point(1, 1, @OutputNormal)); |
| 91 |
AssertVectorEquals(Vector3(0, 0, 1), OutputNormal); |
| 92 |
|
| 93 |
FreeAndNil(SurfaceNode); |
| 94 |
end; |
| 95 |
|
| 96 |
initialization |
| 97 |
RegisterTest(TTestX3DNodesNurbs); |
| 98 |
end. |