// TODO: figure out why the heck this is required for Stella's Hydras...
// TODO: rename this gameSetting to "hydraXRotationSkew" or other sensible name
rawY += rawZ * MathHelper.sin(vrSettings.posTrackHydraYAxisDistanceSkewAngleDeg*PIOVER180 );
//Raw is the absolute coordinate in hydra reference frame of the sample (possible average of two controllers)
Vec3 raw = Vec3.createVectorHelper(rawX, rawY, rawZ);
//Rel is the relative coordinate in hydra reference frame
Vec3 rel = origin.subtract(raw);
//Account for hydra base station / head tracker orientation not aligned
//After this, rel is in body coordinates (relative to head tracker reference frame, not accounting for mouse-induced world yaw offset)
rel.rotateAroundY(baseStationYawOffset*PIOVER180);
//Now, compute the offset from the hydra controller to the camera location. Straight from the settings (although negated -
//vrSettings stores eye center -> hydra values for user readability. We need hydra -> eye center values here)
float hydraXOffset = -vrSettings.getPosTrackHydraOffsetX();
float hydraYOffset = -vrSettings.getPosTrackHydraOffsetY();
float hydraZOffset = vrSettings.getPosTrackHydraOffsetZ();
// The configured offset is for a 0,0,0 rotation head. Apply current head orientation to get final offset
Vec3 correctionToCentreEyePosition = Vec3.createVectorHelper(hydraXOffset, hydraYOffset, hydraZOffset);
correctionToCentreEyePosition.rotateAroundZ(rollHeadDegrees*PIOVER180);
correctionToCentreEyePosition.rotateAroundX(pitchHeadDegrees*PIOVER180);
correctionToCentreEyePosition.rotateAroundY(-yawHeadDegrees*PIOVER180);
//Add the hydra position (in head tracker reference frame) to the camera offset
//to get the camera position in head tracker reference frame
headPos = vecAdd(rel,correctionToCentreEyePosition);
if (resetOrigin)
{
//We compute the "ideal" neck model position, in head tracker reference frame
Vec3 neckModelToCentreEyePosition = Vec3.createVectorHelper(0, vrSettings.neckBaseToEyeHeight, -vrSettings.eyeProtrusion);
neckModelToCentreEyePosition.rotateAroundZ(rollHeadDegrees*PIOVER180);
neckModelToCentreEyePosition.rotateAroundX(pitchHeadDegrees*PIOVER180);
neckModelToCentreEyePosition.rotateAroundY(-yawHeadDegrees*PIOVER180);
//The actual hydra position on the head is offset from the eye center by this amount
Vec3 originOffset = correctionToCentreEyePosition.subtract(neckModelToCentreEyePosition);
//Counteract the base station yaw to get back to absolute razer coordinates
originOffset.rotateAroundY(-baseStationYawOffset*PIOVER180);
// save raw - originOffset as origin. That way, when origin is subtracted in the future,
// positions very close to the current location+orientation will have the eye in the correct spot
origin = originOffset.subtract(raw);
resetOrigin = false;
}
// Rotate the centre eye position around any world yaw offset (mouse/controller induced rotation)