Oolite
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#pragma once
28
29#include "OOHPVector.h"
30
31typedef struct
32{
36
37extern const BoundingBox kZeroBoundingBox; /* (0, 0, 0), (0, 0, 0) */
38
39/* Extend bounding box to contain specified point. */
41OOINLINE void bounding_box_add_xyz(BoundingBox* box, GLfloat x, GLfloat y, GLfloat z) ALWAYS_INLINE_FUNC NONNULL_FUNC;
42
43/* Reset bounding box to kZeroBoundingBox. */
45
46/* Reset bounding box to a zero-sized box surrounding specified vector. */
48
49OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat* xSize, GLfloat* ySize, GLfloat* zSize) ALWAYS_INLINE_FUNC;
50
52
55
56/*** Only inline definitions beyond this point ***/
57
59{
60 assert(box != NULL);
61 box->min.x = fmin(box->min.x, vec.x);
62 box->max.x = fmax(box->max.x, vec.x);
63 box->min.y = fmin(box->min.y, vec.y);
64 box->max.y = fmax(box->max.y, vec.y);
65 box->min.z = fmin(box->min.z, vec.z);
66 box->max.z = fmax(box->max.z, vec.z);
67}
68
69OOINLINE void bounding_box_add_xyz(BoundingBox* box, GLfloat x, GLfloat y, GLfloat z)
70{
71 assert(box != NULL);
72 box->min.x = fmin(box->min.x, x);
73 box->max.x = fmax(box->max.x, x);
74 box->min.y = fmin(box->min.y, y);
75 box->max.y = fmax(box->max.y, y);
76 box->min.z = fmin(box->min.z, z);
77 box->max.z = fmax(box->max.z, z);
78}
79
81{
82 assert(box != NULL);
83 *box = kZeroBoundingBox;
84}
85
87{
88 assert(box != NULL);
89 box->min = vec;
90 box->max = vec;
91}
92
93OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat* xSize, GLfloat* ySize, GLfloat* zSize)
94{
95 if (xSize != NULL)
96 *xSize = bb.max.x - bb.min.x;
97 if (ySize != NULL)
98 *ySize = bb.max.y - bb.min.y;
99 if (zSize != NULL)
100 *zSize = bb.max.z - bb.min.z;
101}
102
const BoundingBox kZeroBoundingBox
Definition OOVector.m:36
HPVector OOHPRandomPositionInBoundingBox(BoundingBox bb)
Definition OOHPVector.m:93
OOINLINE void bounding_box_reset_to_vector(BoundingBox *box, Vector vec) ALWAYS_INLINE_FUNC NONNULL_FUNC
OOINLINE void bounding_box_add_vector(BoundingBox *box, Vector vec) ALWAYS_INLINE_FUNC NONNULL_FUNC
Vector OORandomPositionInBoundingBox(BoundingBox bb)
Definition OOVector.m:107
OOINLINE void bounding_box_add_xyz(BoundingBox *box, GLfloat x, GLfloat y, GLfloat z) ALWAYS_INLINE_FUNC NONNULL_FUNC
OOINLINE Vector OOBoundingBoxCenter(BoundingBox bb) INLINE_CONST_FUNC
OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat *xSize, GLfloat *ySize, GLfloat *zSize) ALWAYS_INLINE_FUNC
OOINLINE void bounding_box_reset(BoundingBox *box) NONNULL_FUNC
#define ALWAYS_INLINE_FUNC
#define NONNULL_FUNC
#define INLINE_CONST_FUNC
#define OOINLINE
float y
float x
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34