2014-07-09 19:24:49 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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 20:02:20 +00:00
|
|
|
#include "gfxVR.h"
|
2015-07-02 15:58:24 +00:00
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
# define M_PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
|
2015-04-07 17:26:44 +00:00
|
|
|
using namespace mozilla;
|
2014-07-09 19:24:49 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
Atomic<uint32_t> VRDisplayManager::sDisplayBase(0);
|
2015-04-07 17:26:44 +00:00
|
|
|
|
|
|
|
/* static */ uint32_t
|
2016-02-24 23:54:50 +00:00
|
|
|
VRDisplayManager::AllocateDisplayID()
|
2015-07-02 15:58:24 +00:00
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
return ++sDisplayBase;
|
2015-07-02 15:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Matrix4x4
|
|
|
|
VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar, bool rightHanded)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|