forked from Omnifinity/OpenVR-Tracking-Example
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cylinder.cpp
47 lines (39 loc) · 1009 Bytes
/
cylinder.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
#include "cylinder.h"
//Destructor
Cylinder::~Cylinder()
{
}
//Constructor
Cylinder::Cylinder()
{
hasInit = false;
s1 = new float[3];
s2 = new float[3];
s1[1] = std::numeric_limits<float>::max();
s2[1] = -std::numeric_limits<float>::max();
yMin = -std::numeric_limits<float>::max();
yMax = std::numeric_limits<float>::max();
radius = 0;
}
void Cylinder::init()
{
//The center is set to the midpoint between the two trigger button events
xOrigin = (s1[0] + s2[0])/2;
zOrigin = (s1[2] + s2[2])/2;
//Calculates the radius based on the distance between the two base points
float deltaX = s1[0]-s2[0];
float deltaZ = s1[2]-s2[2];
radius= std::sqrt((deltaX*deltaX) + (deltaZ*deltaZ)) / 2;
yMax = std::max(s1[1],s2[1]);
yMin = std::min(s1[1],s2[1]);
hasInit = true;
}
bool Cylinder::isInside(float x, float y, float z)
{
if(y > yMax || y < yMin)
return false;
float dX = x-xOrigin;
float dZ = z-zOrigin;
float testDist = std::sqrt(((dX*dX) + (dZ*dZ)));
return (testDist <= radius);
}