Debian Codegraph @

external/cubicvr2/math/sphere.h

raw
1 //
2 // sphere.h
3 // CubicVR2
4 //
5 // Created by Charles J. Cliffe on 2013-02-22.
6 // Copyright (c) 2013 Charles J. Cliffe. All rights reserved.
7 //
8
9 #ifndef CubicVR2_sphere_h
10 #define CubicVR2_sphere_h
11
12 #include "vec3.h"
13 #include "vec4.h"
14
15 namespace CubicVR {
16
17 struct sphere {
18 bool intersects(vec4 sphere, vec4 other) {
19 vec3 spherePos(sphere[0], sphere[1], sphere[2]);
20 vec3 otherPos(other[0], other[1], other[2]);
21 vec3 diff = vec3::subtract(spherePos, otherPos);
22
23 __float mag = sqrtf(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]);
24 __float sum_radii = sphere[3] + other[3];
25
26 if (mag * mag < sum_radii * sum_radii) {
27 return true;
28 }
29 return false;
30 }
31 };
32 }
33
34 #endif