-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sphere.cpp
57 lines (48 loc) · 1.26 KB
/
Sphere.cpp
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
#include "og_pch.hpp"
#include "Sphere.hpp"
namespace og
{
Sphere::Sphere(const vec3f & centre, float radius)
: centre_(centre),
radius_(radius)
{
bounds_.FromCentreHalf ( centre_, vec3f ( radius_, radius_, radius_ ) );
CalcContainedPoints();
}
bool Sphere::isPointInside(const vec3i & point) const
{
// Check whether the distance between the point and the centre
// is greater then the radius.
if((intToFloatSpace(point) - centre_).length() > radius_)
return false;
return true;
}
void Sphere::CalcContainedPoints()
{
contained_points_.clear();
const vec3i & min = bounds_.min_i();
const vec3i & max = bounds_.max_i();
vec3i check_point ( min );
for( ; check_point[0] != max[0]; ++check_point[0] )
{
for( ; check_point[1] != max[1]; ++check_point[1] )
{
for( ; check_point[2] != max[2]; ++check_point[2] )
{
if ( isPointInside ( check_point ) )
{
contained_points_.push_back ( check_point );
}
}
check_point[2] = min[2];
}
check_point[1] = min[1];
}
}
void Sphere::centre(const vec3f & centre)
{
bounds_.Translate( centre - centre_ );
centre_ = centre;
CalcContainedPoints();
}
}