Commit 1105db44 authored by Ian McInerney's avatar Ian McInerney

Added to Bridge callbacks

parent 978df8ed
......@@ -21,7 +21,6 @@ class Bridge {
~Bridge();
/**
* This function will find the point located between the two endpoints.
* If the second endpoint is missing, then the 1st endpoint is returned
......@@ -32,14 +31,11 @@ class Bridge {
*/
bool getInterpolatedPosition(lateralPosition *pos, int loc);
/**
* Callbacks for the VRPN trackers on either end of the bridge
*/
static void VRPN_CALLBACK end1Callback(void* inst, const vrpn_TRACKERCB t);
static void VRPN_CALLBACK end2Callback(void* inst, const vrpn_TRACKERCB t);
};
......
......@@ -4,7 +4,9 @@
#include "structures.h"
Bridge::Bridge() {
// The endpoints are not valid yet
this->endpoint1Valid = false;
this->endpoint2Valid = false;
}
Bridge::~Bridge() {
......@@ -22,23 +24,23 @@ Bridge::~Bridge() {
bool Bridge::getInterpolatedPosition(lateralPosition *pos, int loc) {
bool retVal = false;
if (endpoint2Valid && endpoint1Valid) {
if (this->endpoint2Valid && this->endpoint1Valid) {
// If both endpoints are valid, then interpolate the location between the points
pos->x = loc*endpoint1.x + (1 - loc)*endpoint2.x;
pos->y = loc*endpoint1.y + (1 - loc)*endpoint2.y;
pos->z = loc*endpoint1.z + (1 - loc)*endpoint2.z;
pos->x = loc * this->endpoint1.x + (1 - loc) * this->endpoint2.x;
pos->y = loc * this->endpoint1.y + (1 - loc) * this->endpoint2.y;
pos->z = loc * this->endpoint1.z + (1 - loc) * this->endpoint2.z;
retVal = true;
} else if (endpoint1Valid) {
} else if (this->endpoint1Valid) {
// Return the 1st endpoint
pos->x = endpoint1.x;
pos->y = endpoint1.y;
pos->z = endpoint1.z;
pos->x = this->endpoint1.x;
pos->y = this->endpoint1.y;
pos->z = this->endpoint1.z;
retVal = true;
} else if (endpoint2Valid) {
} else if (this->endpoint2Valid) {
// Return the 2nd endpoint
pos->x = endpoint2.x;
pos->y = endpoint2.y;
pos->z = endpoint2.z;
pos->x = this->endpoint2.x;
pos->y = this->endpoint2.y;
pos->z = this->endpoint2.z;
retVal = true;
} else {
// Neither endpoint is valid
......@@ -55,15 +57,23 @@ bool Bridge::getInterpolatedPosition(lateralPosition *pos, int loc) {
void VRPN_CALLBACK Bridge::end1Callback(void *inst, const vrpn_TRACKERCB t) {
Bridge *bridge = (Bridge*) inst;
// Save the position data
bridge->endpoint1.x = t.pos[0];
bridge->endpoint1.y = t.pos[1];
bridge->endpoint1.z = t.pos[2];
// Say the endpoint is valid
bridge->endpoint1Valid = true;
}
void VRPN_CALLBACK Bridge::end2Callback(void *inst, const vrpn_TRACKERCB t) {
Bridge *bridge = (Bridge*) inst;
// Save the position data
bridge->endpoint2.x = t.pos[0];
bridge->endpoint2.y = t.pos[1];
bridge->endpoint2.z = t.pos[2];
// Say the endpoint is valid
bridge->endpoint2Valid = true;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment