2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2014-07-09 23:24:49 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
#include "gfxVR.h"
|
2015-07-02 18:58:24 +03:00
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
# define M_PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
|
2015-04-07 20:26:44 +03:00
|
|
|
using namespace mozilla;
|
2014-07-09 23:24:49 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2016-10-01 02:43:33 +03:00
|
|
|
Matrix4x4 VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar,
|
|
|
|
bool rightHanded) const {
|
2015-07-02 18:58:24 +03:00
|
|
|
float upTan = tan(upDegrees * M_PI / 180.0);
|
|
|
|
float downTan = tan(downDegrees * M_PI / 180.0);
|
|
|
|
float leftTan = tan(leftDegrees * M_PI / 180.0);
|
|
|
|
float rightTan = tan(rightDegrees * M_PI / 180.0);
|
|
|
|
|
|
|
|
float handednessScale = rightHanded ? -1.0 : 1.0;
|
|
|
|
|
|
|
|
float pxscale = 2.0f / (leftTan + rightTan);
|
|
|
|
float pxoffset = (leftTan - rightTan) * pxscale * 0.5;
|
|
|
|
float pyscale = 2.0f / (upTan + downTan);
|
|
|
|
float pyoffset = (upTan - downTan) * pyscale * 0.5;
|
|
|
|
|
|
|
|
Matrix4x4 mobj;
|
|
|
|
float* m = &mobj._11;
|
|
|
|
|
|
|
|
m[0 * 4 + 0] = pxscale;
|
|
|
|
m[2 * 4 + 0] = pxoffset * handednessScale;
|
|
|
|
|
|
|
|
m[1 * 4 + 1] = pyscale;
|
|
|
|
m[2 * 4 + 1] = -pyoffset * handednessScale;
|
|
|
|
|
|
|
|
m[2 * 4 + 2] = zFar / (zNear - zFar) * -handednessScale;
|
|
|
|
m[3 * 4 + 2] = (zFar * zNear) / (zNear - zFar);
|
|
|
|
|
|
|
|
m[2 * 4 + 3] = handednessScale;
|
|
|
|
m[3 * 4 + 3] = 0.0f;
|
|
|
|
|
|
|
|
return mobj;
|
|
|
|
}
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2017-10-24 00:23:03 +03:00
|
|
|
void VRHMDSensorState::CalcViewMatrices(
|
|
|
|
const gfx::Matrix4x4* aHeadToEyeTransforms) {
|
|
|
|
gfx::Matrix4x4 matHead;
|
|
|
|
if (flags & VRDisplayCapabilityFlags::Cap_Orientation) {
|
2018-07-11 22:20:51 +03:00
|
|
|
matHead.SetRotationFromQuaternion(
|
2020-07-11 00:52:57 +03:00
|
|
|
gfx::Quaternion(-pose.orientation[0], -pose.orientation[1],
|
|
|
|
-pose.orientation[2], pose.orientation[3]));
|
2017-10-24 00:23:03 +03:00
|
|
|
}
|
2018-07-11 22:20:51 +03:00
|
|
|
matHead.PreTranslate(-pose.position[0], -pose.position[1], -pose.position[2]);
|
2017-10-24 00:23:03 +03:00
|
|
|
|
2018-03-14 03:09:54 +03:00
|
|
|
gfx::Matrix4x4 matView =
|
|
|
|
matHead * aHeadToEyeTransforms[VRDisplayState::Eye_Left];
|
2017-10-24 00:23:03 +03:00
|
|
|
matView.Normalize();
|
|
|
|
memcpy(leftViewMatrix, matView.components, sizeof(matView.components));
|
2018-03-14 03:09:54 +03:00
|
|
|
matView = matHead * aHeadToEyeTransforms[VRDisplayState::Eye_Right];
|
2017-10-24 00:23:03 +03:00
|
|
|
matView.Normalize();
|
|
|
|
memcpy(rightViewMatrix, matView.components, sizeof(matView.components));
|
|
|
|
}
|
2018-03-14 03:09:54 +03:00
|
|
|
|
|
|
|
const IntSize VRDisplayInfo::SuggestedEyeResolution() const {
|
2019-01-10 00:57:36 +03:00
|
|
|
return IntSize(mDisplayState.eyeResolution.width,
|
|
|
|
mDisplayState.eyeResolution.height);
|
2018-03-14 03:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Point3D VRDisplayInfo::GetEyeTranslation(uint32_t whichEye) const {
|
2019-01-10 00:57:36 +03:00
|
|
|
return Point3D(mDisplayState.eyeTranslation[whichEye].x,
|
|
|
|
mDisplayState.eyeTranslation[whichEye].y,
|
|
|
|
mDisplayState.eyeTranslation[whichEye].z);
|
2018-03-14 03:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Size VRDisplayInfo::GetStageSize() const {
|
2019-01-10 00:57:36 +03:00
|
|
|
return Size(mDisplayState.stageSize.width, mDisplayState.stageSize.height);
|
2018-03-14 03:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Matrix4x4 VRDisplayInfo::GetSittingToStandingTransform() const {
|
|
|
|
Matrix4x4 m;
|
|
|
|
// If we could replace Matrix4x4 with a pod type, we could
|
|
|
|
// use it directly from the VRDisplayInfo struct.
|
2019-01-10 00:57:36 +03:00
|
|
|
memcpy(m.components, mDisplayState.sittingToStandingTransform,
|
2018-03-14 03:09:54 +03:00
|
|
|
sizeof(float) * 16);
|
|
|
|
return m;
|
|
|
|
}
|