summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Util
diff options
context:
space:
mode:
Diffstat (limited to 'LibOVR/Src/Util')
-rw-r--r--LibOVR/Src/Util/Util_MagCalibration.cpp57
-rw-r--r--LibOVR/Src/Util/Util_MagCalibration.h19
-rw-r--r--LibOVR/Src/Util/Util_Render_Stereo.cpp4
3 files changed, 72 insertions, 8 deletions
diff --git a/LibOVR/Src/Util/Util_MagCalibration.cpp b/LibOVR/Src/Util/Util_MagCalibration.cpp
index c537154..58b8c45 100644
--- a/LibOVR/Src/Util/Util_MagCalibration.cpp
+++ b/LibOVR/Src/Util/Util_MagCalibration.cpp
@@ -23,6 +23,12 @@ void MagCalibration::BeginAutoCalibration(SensorFusion& sf)
// This is a "hard" reset of the mag, so need to clear stored values
sf.ClearMagCalibration();
SampleCount = 0;
+
+ // reset the statistics
+ MinMagValues = Vector3f(10000.0f,10000.0f,10000.0f);
+ MaxMagValues = Vector3f(-10000.0f,-10000.0f,-10000.0f);
+ MinQuatValues = Quatf(1.0f,1.0f,1.0f,1.0f);
+ MaxQuatValues = Quatf(0.0f,0.0f,0.0f,0.0f);
}
unsigned MagCalibration::UpdateAutoCalibration(SensorFusion& sf)
@@ -36,7 +42,11 @@ unsigned MagCalibration::UpdateAutoCalibration(SensorFusion& sf)
InsertIfAcceptable(q, m);
if ((SampleCount == 4) && (Stat == Mag_AutoCalibrating))
+ {
+ //LogText("Magnetometer Output Spread: %f %f %f\n",MagSpread.x,MagSpread.y,MagSpread.z);
+ //LogText("Quaternion Spread: %f %f %f %f\n",QuatSpread.x,QuatSpread.y,QuatSpread.z,QuatSpread.w);
SetCalibration(sf);
+ }
return Stat;
@@ -83,7 +93,39 @@ bool MagCalibration::IsAcceptableSample(const Quatf& q, const Vector3f& m)
bool MagCalibration::InsertIfAcceptable(const Quatf& q, const Vector3f& m)
{
- if (IsAcceptableSample(q, m))
+ // Update some statistics
+ if (m.x < MinMagValues.x)
+ MinMagValues.x = m.x;
+ if (m.y < MinMagValues.y)
+ MinMagValues.y = m.y;
+ if (m.z < MinMagValues.z)
+ MinMagValues.z = m.z;
+ if (m.x > MaxMagValues.x)
+ MaxMagValues.x = m.x;
+ if (m.y > MaxMagValues.y)
+ MaxMagValues.y = m.y;
+ if (m.z > MaxMagValues.z)
+ MaxMagValues.z = m.z;
+ if (q.x < MinQuatValues.x)
+ MinQuatValues.x = q.x;
+ if (q.y < MinQuatValues.y)
+ MinQuatValues.y = q.y;
+ if (q.z < MinQuatValues.z)
+ MinQuatValues.z = q.z;
+ if (q.w < MinQuatValues.w)
+ MinQuatValues.w = q.w;
+ if (q.x > MaxQuatValues.x)
+ MaxQuatValues.x = q.x;
+ if (q.y > MaxQuatValues.y)
+ MaxQuatValues.y = q.y;
+ if (q.z > MaxQuatValues.z)
+ MaxQuatValues.z = q.z;
+ if (q.w > MaxQuatValues.w)
+ MaxQuatValues.w = q.w;
+ MagSpread = MaxMagValues - MinMagValues;
+ QuatSpread = MaxQuatValues - MinQuatValues;
+
+ if (IsAcceptableSample(q, m))
{
MagSamples[SampleCount] = m;
QuatSamples[SampleCount] = q;
@@ -94,6 +136,14 @@ bool MagCalibration::InsertIfAcceptable(const Quatf& q, const Vector3f& m)
return false;
}
+Matrix4f MagCalibration::GetMagCalibration() const
+{
+ Matrix4f calMat = Matrix4f();
+ calMat.M[0][3] = -MagCenter.x;
+ calMat.M[1][3] = -MagCenter.y;
+ calMat.M[2][3] = -MagCenter.z;
+ return calMat;
+}
bool MagCalibration::SetCalibration(SensorFusion& sf)
{
@@ -101,10 +151,7 @@ bool MagCalibration::SetCalibration(SensorFusion& sf)
return false;
MagCenter = CalculateSphereCenter(MagSamples[0],MagSamples[1],MagSamples[2],MagSamples[3]);
- Matrix4f calMat = Matrix4f();
- calMat.M[0][3] = -MagCenter.x;
- calMat.M[1][3] = -MagCenter.y;
- calMat.M[2][3] = -MagCenter.z;
+ Matrix4f calMat = GetMagCalibration();
sf.SetMagCalibration(calMat);
Stat = Mag_Calibrated;
//LogText("MagCenter: %f %f %f\n",MagCenter.x,MagCenter.y,MagCenter.z);
diff --git a/LibOVR/Src/Util/Util_MagCalibration.h b/LibOVR/Src/Util/Util_MagCalibration.h
index fd26d22..1f8e8cb 100644
--- a/LibOVR/Src/Util/Util_MagCalibration.h
+++ b/LibOVR/Src/Util/Util_MagCalibration.h
@@ -41,7 +41,11 @@ public:
{
MinMagDistanceSq = MinMagDistance * MinMagDistance;
MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
- }
+ MinMagValues = Vector3f(10000.0f,10000.0f,10000.0f);
+ MaxMagValues = Vector3f(-10000.0f,-10000.0f,-10000.0f);
+ MinQuatValues = Quatf(1.0f,1.0f,1.0f,1.0f);
+ MaxQuatValues = Quatf(0.0f,0.0f,0.0f,0.0f);
+ }
// Methods that are useful for either auto or manual calibration
bool IsUnitialized() const { return Stat == Mag_Uninitialized; }
@@ -93,6 +97,12 @@ public:
// A result of the calibration, which is the center of a sphere that
// roughly approximates the magnetometer data.
Vector3f GetMagCenter() const { return MagCenter; }
+ // Retrieves the full magnetometer calibration matrix
+ Matrix4f GetMagCalibration() const;
+ // Retrieves the range of each quaternion term during calibration
+ Quatf GetCalibrationQuatSpread() const { return QuatSpread; }
+ // Retrieves the range of each magnetometer term during calibration
+ Vector3f GetCalibrationMagSpread() const { return MagSpread; }
private:
// Determine the unique sphere through 4 non-coplanar points
@@ -109,6 +119,13 @@ private:
float MinQuatDistance;
float MinMagDistanceSq;
float MinQuatDistanceSq;
+ // For gathering statistics during calibration
+ Vector3f MinMagValues;
+ Vector3f MaxMagValues;
+ Vector3f MagSpread;
+ Quatf MinQuatValues;
+ Quatf MaxQuatValues;
+ Quatf QuatSpread;
unsigned SampleCount;
Vector3f MagSamples[4];
diff --git a/LibOVR/Src/Util/Util_Render_Stereo.cpp b/LibOVR/Src/Util/Util_Render_Stereo.cpp
index b16cfb5..e2600a9 100644
--- a/LibOVR/Src/Util/Util_Render_Stereo.cpp
+++ b/LibOVR/Src/Util/Util_Render_Stereo.cpp
@@ -247,7 +247,7 @@ void StereoConfig::update2D()
// eye, where hmd screen projection surface is at 0.05m distance.
// This introduces an extra off-center pixel projection shift based on eye distance.
// This offCenterShift is the pixel offset of the other camera's center
- // in your reference camera based on surface distance.
+ // in your reference camera based on surface distance.
float metersToPixels = (HMD.HResolution / HMD.HScreenSize);
float lensDistanceScreenPixels= metersToPixels * HMD.LensSeparationDistance;
float eyeDistanceScreenPixels = metersToPixels * InterpupillaryDistance;
@@ -278,7 +278,7 @@ void StereoConfig::update2D()
void StereoConfig::updateEyeParams()
{
// Projection matrix for the center eye, which the left/right matrices are based on.
- Matrix4f projCenter = Matrix4f::PerspectiveRH(YFov, Aspect, 0.01f, 1000.0f);
+ Matrix4f projCenter = Matrix4f::PerspectiveRH(YFov, Aspect, 0.01f, 2000.0f);
switch(Mode)
{