Debian Codegraph @

src/scene/load/collada/x3dloadinternalcollada_matrix.inc

raw
1 {
2 Copyright 2008-2022 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 {$ifdef read_interface}
17
18 {$endif read_interface}
19
20 {$ifdef read_implementation}
21
22 {$endif read_implementation}
23
24 {$ifdef read_implementation_nested}
25
26 { Read <matrix> or <bind_shape_matrix> element to given Matrix. }
27 function ReadMatrix(MatrixElement: TDOMElement): TMatrix4;
28 var
29 SeekPos: Integer;
30 Row, Col: Integer;
31 Token, Content: string;
32 begin
33 Content := MatrixElement.TextData;
34
35 SeekPos := 1;
36
37 for Row := 0 to 3 do
38 for Col := 0 to 3 do
39 begin
40 Token := NextToken(Content, SeekPos);
41 if Token = '' then
42 begin
43 WritelnWarning('Collada', 'Matrix (<matrix> or <bind_shape_matrix> ' +
44 'element) has not enough items');
45 Break;
46 end;
47 Result[Col, Row] := StrToFloatDot(Token);
48 end;
49 end;
50
51 { Read <lookat> element, return appropriate matrix. }
52 function ReadLookAt(MatrixElement: TDOMElement): TMatrix4;
53 var
54 SeekPos: Integer;
55 Content: string;
56
57 function ReadVector(out Vector: TVector3): boolean;
58 var
59 Token: string;
60 I: Integer;
61 begin
62 Result := true;
63
64 for I := 0 to 2 do
65 begin
66 Token := NextToken(Content, SeekPos);
67 if Token = '' then
68 begin
69 WritelnWarning('Collada', 'Unexpected end of data of <lookat>');
70 Exit(false);
71 end;
72 Vector.Data[I] := StrToFloatDot(Token);
73 end;
74 end;
75
76 var
77 Eye, Center, Up: TVector3;
78 begin
79 Content := MatrixElement.TextData;
80
81 SeekPos := 1;
82
83 if ReadVector(Eye) and
84 ReadVector(Center) and
85 ReadVector(Up) then
86 Result := LookAtMatrix(Eye, Center, Up);
87 end;
88
89 {$endif read_implementation_nested}