Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bsphere.h
Go to the documentation of this file.
1#pragma once
2#include "math_types.h"
3#include "transform.hpp"
4namespace math
5{
6using namespace glm;
7//-----------------------------------------------------------------------------
8// Main class declarations
9//-----------------------------------------------------------------------------
10//-----------------------------------------------------------------------------
11// Name : bsphere (Class)
16//-----------------------------------------------------------------------------
18{
19public:
20 //-------------------------------------------------------------------------
21 // Constructors & Destructors
22 //-------------------------------------------------------------------------
23 bsphere() : position(0.0f, 0.0f, 0.0f), radius(0.0f)
24 {
25 }
26 bsphere(const vec3& _position, float _radius) : position(_position), radius(_radius)
27 {
28 }
29 bsphere(float x, float y, float z, float _radius) : position(x, y, z), radius(_radius)
30 {
31 }
32
33 //-------------------------------------------------------------------------
34 // Public Inline Methods
35 //-------------------------------------------------------------------------
36 //-------------------------------------------------------------------------
37 // Name : contains_point()
43 //-------------------------------------------------------------------------
44 inline bool contains_point(const vec3& point) const
45 {
46 return (glm::length2(position - point) < (radius * radius));
47 }
48
49 //-------------------------------------------------------------------------
50 // Name : contains_point()
56 //-------------------------------------------------------------------------
57 inline bool contains_point(const vec3& point, float tolerance) const
58 {
59 return (glm::length2(position - point) <= ((radius + tolerance) * (radius + tolerance)));
60 }
61
62 //-------------------------------------------------------------------------
63 // Public Methods
64 //-------------------------------------------------------------------------
65 bsphere& from_points(const char* point_buffer, unsigned int point_count, unsigned int point_stride);
66
67 //-------------------------------------------------------------------------
68 // Public Inline Operators
69 //-------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 // Name : operator+=()
75 //-----------------------------------------------------------------------------
76 inline bsphere& operator+=(const vec3& shift)
77 {
78 position += shift;
79 return *this;
80 }
81
82 //-----------------------------------------------------------------------------
83 // Name : operator-=()
87 //-----------------------------------------------------------------------------
88 inline bsphere& operator-=(const vec3& shift)
89 {
90 position -= shift;
91 return *this;
92 }
93
94 //-----------------------------------------------------------------------------
95 // Name : operator!=()
99 //-----------------------------------------------------------------------------
100 inline bool operator!=(const bsphere& bounds) const
101 {
102 return (position != bounds.position || radius != bounds.radius);
103 }
104
105 //-----------------------------------------------------------------------------
106 // Name : operator==()
110 //-----------------------------------------------------------------------------
111 inline bool operator==(const bsphere& bounds) const
112 {
113 return (position == bounds.position && radius == bounds.radius);
114 }
115
116 //-------------------------------------------------------------------------
117 // Public Variables
118 //-------------------------------------------------------------------------
120 float radius;
121
122 //-------------------------------------------------------------------------
123 // Public Static Variables
124 //-------------------------------------------------------------------------
126};
127} // namespace math
Provides storage for common representation of spherical bounding volume, and wraps up common function...
Definition bsphere.h:18
bool contains_point(const vec3 &point) const
Tests to see if the specified point falls within this bounding sphere or not. A point precisely on th...
Definition bsphere.h:44
float radius
Definition bsphere.h:120
static bsphere empty
Definition bsphere.h:125
bsphere & operator-=(const vec3 &shift)
Adjusts the position of the bounding sphere by the specified amount.
Definition bsphere.h:88
bsphere(float x, float y, float z, float _radius)
Definition bsphere.h:29
bool operator==(const bsphere &bounds) const
Test for equality between this bounding sphere and another.
Definition bsphere.h:111
vec3 position
Definition bsphere.h:119
bool operator!=(const bsphere &bounds) const
Test for inequality between this bounding sphere and another.
Definition bsphere.h:100
bsphere(const vec3 &_position, float _radius)
Definition bsphere.h:26
bsphere & from_points(const char *point_buffer, unsigned int point_count, unsigned int point_stride)
Calculates a tight fitting bounding sphere from the points supplied.
Definition bsphere.cpp:20
bool contains_point(const vec3 &point, float tolerance) const
Tests to see if the specified point falls within this bounding sphere or not, taking into account the...
Definition bsphere.h:57
bsphere & operator+=(const vec3 &shift)
Adjusts the position of the bounding sphere by the specified amount.
Definition bsphere.h:76
Definition bbox.cpp:5
float y
float x
float z