File: v3dsceneboxes.pas

package info (click to toggle)
view3dscene 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,824 kB
  • sloc: pascal: 3,961; sh: 330; xml: 261; makefile: 133
file content (87 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  Copyright 2006-2022 Michalis Kamburelis.

  This file is part of "view3dscene".

  "view3dscene" is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  "view3dscene" 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.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with "view3dscene"; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

  ----------------------------------------------------------------------------
}

{ glDrawCornerMarkers utility. }
unit V3DSceneBoxes;

{$I v3dsceneconf.inc}

interface

uses CastleBoxes;

{$ifndef OpenGLES}

{ Draw corner markers (3 lines) at the 8 corners of the box.
  Proportion is the fraction of the box length, the marker extends too. }
procedure glDrawCornerMarkers(const Box: TBox3D; const Proportion: Single = 0.1);

{$endif}

implementation

uses {$ifdef FPC} CastleGL {$else} GL, GLExt {$endif};

{$ifndef OpenGLES}

procedure glDrawCornerMarkers(const Box: TBox3D; const Proportion: Single);

  procedure glDrawCorners(const minx, miny, minz, maxx, maxy, maxz: Single);

    procedure glDrawCornerLines(const x, y, z, dx, dy, dz: Single);
    begin
      glVertex3f(x, y, z);
      glVertex3f(x+dx, y, z);
      glVertex3f(x, y, z);
      glVertex3f(x, y+dy, z);
      glVertex3f(x, y, z);
      glVertex3f(x, y, z+dz);
    end;

  var
    Xlength, Ylength, Zlength: Single;
  begin
    Xlength := (maxx - minx) * Proportion;
    Ylength := (maxy - miny) * Proportion;
    Zlength := (maxz - minz) * Proportion;
    glBegin(GL_LINES);
      glDrawCornerLines(minx,miny,minz,Xlength,Ylength,Zlength);
      glDrawCornerLines(minx,miny,maxz,Xlength,Ylength,-Zlength);
      glDrawCornerLines(minx,maxy,minz,Xlength,-Ylength,Zlength);
      glDrawCornerLines(minx,maxy,maxz,Xlength,-Ylength,-Zlength);
      glDrawCornerLines(maxx,miny,minz,-Xlength,Ylength,Zlength);
      glDrawCornerLines(maxx,miny,maxz,-Xlength,Ylength,-Zlength);
      glDrawCornerLines(maxx,maxy,minz,-Xlength,-Ylength,Zlength);
      glDrawCornerLines(maxx,maxy,maxz,-Xlength,-Ylength,-Zlength);
    glEnd;
  end;

begin
  glDrawCorners(
    Box.Data[0].X, Box.Data[0].Y, Box.Data[0].Z,
    Box.Data[1].X, Box.Data[1].Y, Box.Data[1].Z
  );
end;

{$endif}

end.