source: nanovis/branches/1.1/vrmath/include/vrmath/BBox.h @ 4890

Last change on this file since 4890 was 4890, checked in by ldelgass, 9 years ago

merge r3627:3628 from trunk

File size: 2.4 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author: Insoo Woo <iwoo@purdue.edu>
6 */
7#ifndef VRBBOX_H
8#define VRBBOX_H
9
10#include <vrmath/Vector3f.h>
11
12namespace vrmath {
13
14class Matrix4x4d;
15
16class BBox
17{
18public:
19    /**
20     * @brief constructor
21     */
22    BBox();
23
24    /**
25     * @brief constructor
26     * @param bbox bounding box
27     */
28    BBox(const BBox& bbox);
29
30    /**
31     * @brief constructor
32     * @param min minimum point of the bounding box
33     * @param max maximum point of the bounding box
34     */
35    BBox(const Vector3f& min, const Vector3f& max);
36
37    BBox& operator=(const BBox& other)
38    {
39        if (&other != this) {
40            min = other.min;
41            max = other.max;
42        }
43        return *this;
44    }
45
46    /**
47     * @brief make an empty bounding box
48     */
49    void makeEmpty();
50
51    /**
52     * @brief make an bouning box
53     * @param center the center of bounding box
54     * @param size the size of bounding box
55     */
56    void make(const Vector3f& center, const Vector3f& size);
57
58    /**
59     * @brief check if the bounding box is empty
60     */
61    bool isEmpty();
62    bool isEmptyX();
63    bool isEmptyY();
64    bool isEmptyZ();
65
66    /**
67     * @brief extend the bounding box by a point
68     */
69    void extend(const Vector3f& point);
70
71    /**
72     * @brief extend the bounding box by a bbox
73     */
74    void extend(const BBox& bbox);
75
76    /**
77     * @brief transform a bounding box with a matrix and set the bounding box
78     */
79    void transform(const BBox& box, const Matrix4x4d& mat);
80
81    /**
82     * @brief check if the bounding box intersect with a box
83     */
84    bool intersect(const BBox& box);
85
86    /**
87     * @brief check if the bounding box contains a point
88     */
89    bool contains(const Vector3f& point);
90
91    float getRadius() const;
92    Vector3f getCenter() const;
93    Vector3f getSize() const;
94
95    Vector3f min;
96    Vector3f max;
97};
98
99inline float BBox::getRadius() const
100{
101    return max.distance( min ) * 0.5f;
102}
103
104inline Vector3f BBox::getCenter() const
105{
106    Vector3f temp;
107    temp.x = (max.x + min.x) * 0.5f;
108    temp.y = (max.y + min.y) * 0.5f;
109    temp.z = (max.z + min.z) * 0.5f;
110    return temp;
111}
112
113inline Vector3f  BBox::getSize() const
114{
115    Vector3f temp;
116    temp.x = max.x - min.x;
117    temp.y = max.y - min.y;
118    temp.z = max.z - min.z;
119    return temp;
120}
121
122}
123
124#endif
Note: See TracBrowser for help on using the repository browser.