Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOBoundingBox.h
Go to the documentation of this file.
1/*
2
3OOBoundingBox.h
4
5Mathematical framework for Oolite.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27
28#ifndef INCLUDED_OOMATHS_h
29 #error Do not include OOBoundingBox.h directly; include OOMaths.h.
30#else
31
32
33typedef struct
34{
35 Vector min;
36 Vector max;
37} BoundingBox;
38
39
40extern const BoundingBox kZeroBoundingBox; /* (0, 0, 0), (0, 0, 0) */
41
42
43/* Extend bounding box to contain specified point. */
44OOINLINE void bounding_box_add_vector(BoundingBox *box, Vector vec) ALWAYS_INLINE_FUNC NONNULL_FUNC;
45OOINLINE void bounding_box_add_xyz(BoundingBox *box, GLfloat x, GLfloat y, GLfloat z) ALWAYS_INLINE_FUNC NONNULL_FUNC;
46
47/* Reset bounding box to kZeroBoundingBox. */
48OOINLINE void bounding_box_reset(BoundingBox *box) NONNULL_FUNC;
49
50/* Reset bounding box to a zero-sized box surrounding specified vector. */
51OOINLINE void bounding_box_reset_to_vector(BoundingBox *box, Vector vec) ALWAYS_INLINE_FUNC NONNULL_FUNC;
52
53OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat *xSize, GLfloat *ySize, GLfloat *zSize) ALWAYS_INLINE_FUNC;
54
55OOINLINE Vector OOBoundingBoxCenter(BoundingBox bb) INLINE_CONST_FUNC;
56
57Vector OORandomPositionInBoundingBox(BoundingBox bb);
58HPVector OOHPRandomPositionInBoundingBox(BoundingBox bb);
59
60
61
62/*** Only inline definitions beyond this point ***/
63
64OOINLINE void bounding_box_add_vector(BoundingBox *box, Vector vec)
65{
66 assert(box != NULL);
67 box->min.x = fmin(box->min.x, vec.x);
68 box->max.x = fmax(box->max.x, vec.x);
69 box->min.y = fmin(box->min.y, vec.y);
70 box->max.y = fmax(box->max.y, vec.y);
71 box->min.z = fmin(box->min.z, vec.z);
72 box->max.z = fmax(box->max.z, vec.z);
73}
74
75
76OOINLINE void bounding_box_add_xyz(BoundingBox *box, GLfloat x, GLfloat y, GLfloat z)
77{
78 assert(box != NULL);
79 box->min.x = fmin(box->min.x, x);
80 box->max.x = fmax(box->max.x, x);
81 box->min.y = fmin(box->min.y, y);
82 box->max.y = fmax(box->max.y, y);
83 box->min.z = fmin(box->min.z, z);
84 box->max.z = fmax(box->max.z, z);
85}
86
87
88OOINLINE void bounding_box_reset(BoundingBox *box)
89{
90 assert(box != NULL);
91 *box = kZeroBoundingBox;
92}
93
94
95OOINLINE void bounding_box_reset_to_vector(BoundingBox *box, Vector vec)
96{
97 assert(box != NULL);
98 box->min = vec;
99 box->max = vec;
100}
101
102
103OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat *xSize, GLfloat *ySize, GLfloat *zSize)
104{
105 if (xSize != NULL) *xSize = bb.max.x - bb.min.x;
106 if (ySize != NULL) *ySize = bb.max.y - bb.min.y;
107 if (zSize != NULL) *zSize = bb.max.z - bb.min.z;
108}
109
110
111OOINLINE Vector OOBoundingBoxCenter(BoundingBox bb)
112{
113 return vector_multiply_scalar(vector_add(bb.min, bb.max), 0.5f);
114}
115
116#endif
#define ALWAYS_INLINE_FUNC
#define NONNULL_FUNC
#define INLINE_CONST_FUNC
#define OOINLINE
HPVector OOHPRandomPositionInBoundingBox(BoundingBox bb)
Definition OOHPVector.m:104
float y
float x
const BoundingBox kZeroBoundingBox
Definition OOVector.m:38
Vector OORandomPositionInBoundingBox(BoundingBox bb)
Definition OOVector.m:121