1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 # define M_PI 3.14159265358979323846
15 using namespace mozilla
;
16 using namespace mozilla::gfx
;
18 Matrix4x4
VRFieldOfView::ConstructProjectionMatrix(float zNear
, float zFar
,
19 bool rightHanded
) const {
20 float upTan
= tan(upDegrees
* M_PI
/ 180.0);
21 float downTan
= tan(downDegrees
* M_PI
/ 180.0);
22 float leftTan
= tan(leftDegrees
* M_PI
/ 180.0);
23 float rightTan
= tan(rightDegrees
* M_PI
/ 180.0);
25 float handednessScale
= rightHanded
? -1.0 : 1.0;
27 float pxscale
= 2.0f
/ (leftTan
+ rightTan
);
28 float pxoffset
= (leftTan
- rightTan
) * pxscale
* 0.5;
29 float pyscale
= 2.0f
/ (upTan
+ downTan
);
30 float pyoffset
= (upTan
- downTan
) * pyscale
* 0.5;
35 m
[0 * 4 + 0] = pxscale
;
36 m
[2 * 4 + 0] = pxoffset
* handednessScale
;
38 m
[1 * 4 + 1] = pyscale
;
39 m
[2 * 4 + 1] = -pyoffset
* handednessScale
;
41 m
[2 * 4 + 2] = zFar
/ (zNear
- zFar
) * -handednessScale
;
42 m
[3 * 4 + 2] = (zFar
* zNear
) / (zNear
- zFar
);
44 m
[2 * 4 + 3] = handednessScale
;
50 void VRHMDSensorState::CalcViewMatrices(
51 const gfx::Matrix4x4
* aHeadToEyeTransforms
) {
52 gfx::Matrix4x4 matHead
;
53 if (flags
& VRDisplayCapabilityFlags::Cap_Orientation
) {
54 matHead
.SetRotationFromQuaternion(
55 gfx::Quaternion(-pose
.orientation
[0], -pose
.orientation
[1],
56 -pose
.orientation
[2], pose
.orientation
[3]));
58 matHead
.PreTranslate(-pose
.position
[0], -pose
.position
[1], -pose
.position
[2]);
60 gfx::Matrix4x4 matView
=
61 matHead
* aHeadToEyeTransforms
[VRDisplayState::Eye_Left
];
63 memcpy(leftViewMatrix
, matView
.components
, sizeof(matView
.components
));
64 matView
= matHead
* aHeadToEyeTransforms
[VRDisplayState::Eye_Right
];
66 memcpy(rightViewMatrix
, matView
.components
, sizeof(matView
.components
));
69 const IntSize
VRDisplayInfo::SuggestedEyeResolution() const {
70 return IntSize(mDisplayState
.eyeResolution
.width
,
71 mDisplayState
.eyeResolution
.height
);
74 const Point3D
VRDisplayInfo::GetEyeTranslation(uint32_t whichEye
) const {
75 return Point3D(mDisplayState
.eyeTranslation
[whichEye
].x
,
76 mDisplayState
.eyeTranslation
[whichEye
].y
,
77 mDisplayState
.eyeTranslation
[whichEye
].z
);
80 const Size
VRDisplayInfo::GetStageSize() const {
81 return Size(mDisplayState
.stageSize
.width
, mDisplayState
.stageSize
.height
);
84 const Matrix4x4
VRDisplayInfo::GetSittingToStandingTransform() const {
86 // If we could replace Matrix4x4 with a pod type, we could
87 // use it directly from the VRDisplayInfo struct.
88 memcpy(m
.components
, mDisplayState
.sittingToStandingTransform
,