mirror of
https://github.com/amwatson/CitraVR.git
synced 2024-09-20 03:11:40 +02:00
Fix formatting
This commit is contained in:
parent
e3caeec765
commit
e01de61155
6 changed files with 189 additions and 186 deletions
|
@ -43,15 +43,15 @@ public:
|
|||
XrViewConfigurationProperties mViewportConfig = {};
|
||||
static constexpr XrViewConfigurationType VIEW_CONFIG_TYPE =
|
||||
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
|
||||
XrSpace mHeadSpace = XR_NULL_HANDLE;
|
||||
XrSpace mViewSpace = XR_NULL_HANDLE;
|
||||
XrSpace mHeadSpace = XR_NULL_HANDLE;
|
||||
XrSpace mViewSpace = XR_NULL_HANDLE;
|
||||
XrSpace mForwardDirectionSpace = XR_NULL_HANDLE;
|
||||
|
||||
XrSpaceLocation headLocation = {};
|
||||
|
||||
XrSpace mLocalSpace = XR_NULL_HANDLE;
|
||||
XrSpace mStageSpace = XR_NULL_HANDLE;
|
||||
size_t mMaxLayerCount = 0;
|
||||
XrSpace mLocalSpace = XR_NULL_HANDLE;
|
||||
XrSpace mStageSpace = XR_NULL_HANDLE;
|
||||
size_t mMaxLayerCount = 0;
|
||||
|
||||
// EGL context
|
||||
std::unique_ptr<EglContext> mEglContext;
|
||||
|
|
|
@ -31,7 +31,7 @@ License : Licensed under GPLv3 or any later version.
|
|||
namespace {
|
||||
|
||||
constexpr float defaultLowerPanelScaleFactor = 0.75f;
|
||||
constexpr float superImmersiveRadius = 0.5f;
|
||||
constexpr float superImmersiveRadius = 0.5f;
|
||||
|
||||
/** Used to translate texture coordinates into the corresponding coordinates
|
||||
* on the Android Activity Window.
|
||||
|
@ -234,7 +234,7 @@ GameSurfaceLayer::GameSurfaceLayer(const XrVector3f&& position, JNIEnv* env, job
|
|||
{
|
||||
if (mImmersiveMode > 0) {
|
||||
ALOGI("Using VR immersive mode {}", mImmersiveMode);
|
||||
mTopPanelFromWorld.position.z = mLowerPanelFromWorld.position.z;
|
||||
mTopPanelFromWorld.position.z = mLowerPanelFromWorld.position.z;
|
||||
mLowerPanelFromWorld.position.y = -1.0f;
|
||||
}
|
||||
const int32_t initializationStatus = Init(activityObject, position, session);
|
||||
|
@ -255,10 +255,9 @@ void GameSurfaceLayer::SetSurface() const {
|
|||
mEnv->CallStaticVoidMethod(mVrGameSurfaceClass, setSurfaceMethodID, mActivityObject, mSurface);
|
||||
}
|
||||
|
||||
|
||||
void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers,
|
||||
uint32_t& layerCount, const XrPosef& headPose, const float& immersiveModeFactor, const bool showLowerPanel)
|
||||
{
|
||||
uint32_t& layerCount, const XrPosef& headPose,
|
||||
const float& immersiveModeFactor, const bool showLowerPanel) {
|
||||
const uint32_t panelWidth = mSwapchain.mWidth / 2;
|
||||
const uint32_t panelHeight = mSwapchain.mHeight / 2;
|
||||
const double aspectRatio =
|
||||
|
@ -271,8 +270,7 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
// Create the Top Display Panel (Curved display)
|
||||
for (uint32_t eye = 0; eye < NUM_EYES; eye++) {
|
||||
XrPosef topPanelFromWorld = mTopPanelFromWorld;
|
||||
if (mImmersiveMode > 1 && !showLowerPanel)
|
||||
{
|
||||
if (mImmersiveMode > 1 && !showLowerPanel) {
|
||||
topPanelFromWorld = GetTopPanelFromHeadPose(eye, headPose);
|
||||
}
|
||||
|
||||
|
@ -290,7 +288,8 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
// Central angle controls how much of the cylinder is
|
||||
// covered by the texture. Together, they control the
|
||||
// scale of the texture.
|
||||
const float radius = (mImmersiveMode < 2 || showLowerPanel) ? GetRadiusSysprop() : superImmersiveRadius;
|
||||
const float radius =
|
||||
(mImmersiveMode < 2 || showLowerPanel) ? GetRadiusSysprop() : superImmersiveRadius;
|
||||
|
||||
layer.eyeVisibility = eye == 0 ? XR_EYE_VISIBILITY_LEFT : XR_EYE_VISIBILITY_RIGHT;
|
||||
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
|
||||
|
@ -299,13 +298,15 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
layer.subImage.imageRect.offset.y = 0;
|
||||
layer.subImage.imageRect.extent.width = panelWidth;
|
||||
layer.subImage.imageRect.extent.height = panelHeight - verticalBorderTex;
|
||||
layer.subImage.imageArrayIndex = 0;
|
||||
layer.pose = topPanelFromWorld;
|
||||
layer.subImage.imageArrayIndex = 0;
|
||||
layer.pose = topPanelFromWorld;
|
||||
layer.pose.position.z += (mImmersiveMode < 2) ? radius : 0.0f;
|
||||
layer.radius = radius;
|
||||
layer.centralAngle = (!mImmersiveMode ? GetCentralAngleSysprop()
|
||||
: GameSurfaceLayer::DEFAULT_CYLINDER_CENTRAL_ANGLE_DEGREES * immersiveModeFactor) *
|
||||
MATH_FLOAT_PI / 180.0f;
|
||||
layer.centralAngle =
|
||||
(!mImmersiveMode ? GetCentralAngleSysprop()
|
||||
: GameSurfaceLayer::DEFAULT_CYLINDER_CENTRAL_ANGLE_DEGREES *
|
||||
immersiveModeFactor) *
|
||||
MATH_FLOAT_PI / 180.0f;
|
||||
layer.aspectRatio = -aspectRatio;
|
||||
layers[layerCount++].mCylinder = layer;
|
||||
}
|
||||
|
@ -343,7 +344,6 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Create the Lower Display Panel (flat touchscreen)
|
||||
// When citra is in stereo mode, this panel is also rendered in stereo (i.e.
|
||||
// twice), but the image is mono. Therefore, take the right half of the
|
||||
|
@ -351,8 +351,7 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
// FIXME we waste rendering time rendering both displays. That said, We also
|
||||
// waste rendering time copying the buffer between runtimes. No time for
|
||||
// that now!
|
||||
if (showLowerPanel)
|
||||
{
|
||||
if (showLowerPanel) {
|
||||
const uint32_t cropHoriz = 90 * mResolutionFactor;
|
||||
XrCompositionLayerQuad layer = {};
|
||||
|
||||
|
@ -366,22 +365,19 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
|
|||
|
||||
layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
|
||||
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
|
||||
layer.subImage.swapchain = mSwapchain.mHandle;
|
||||
layer.subImage.imageRect.offset.x =
|
||||
(cropHoriz / 2) / immersiveModeFactor +
|
||||
panelWidth * (0.5f - (0.5f / immersiveModeFactor));
|
||||
layer.subImage.swapchain = mSwapchain.mHandle;
|
||||
layer.subImage.imageRect.offset.x = (cropHoriz / 2) / immersiveModeFactor +
|
||||
panelWidth * (0.5f - (0.5f / immersiveModeFactor));
|
||||
layer.subImage.imageRect.offset.y =
|
||||
panelHeight + verticalBorderTex +
|
||||
panelHeight * (0.5f - (0.5f / immersiveModeFactor));
|
||||
layer.subImage.imageRect.extent.width =
|
||||
(panelWidth - cropHoriz) / immersiveModeFactor;
|
||||
panelHeight + verticalBorderTex + panelHeight * (0.5f - (0.5f / immersiveModeFactor));
|
||||
layer.subImage.imageRect.extent.width = (panelWidth - cropHoriz) / immersiveModeFactor;
|
||||
layer.subImage.imageRect.extent.height = panelHeight / immersiveModeFactor;
|
||||
layer.subImage.imageArrayIndex = 0;
|
||||
layer.pose = mLowerPanelFromWorld;
|
||||
const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight,
|
||||
defaultLowerPanelScaleFactor, mResolutionFactor);
|
||||
layer.size.width = scale.x * defaultLowerPanelScaleFactor;
|
||||
layer.size.height = scale.y * defaultLowerPanelScaleFactor;
|
||||
layer.subImage.imageArrayIndex = 0;
|
||||
layer.pose = mLowerPanelFromWorld;
|
||||
const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight,
|
||||
defaultLowerPanelScaleFactor, mResolutionFactor);
|
||||
layer.size.width = scale.x * defaultLowerPanelScaleFactor;
|
||||
layer.size.height = scale.y * defaultLowerPanelScaleFactor;
|
||||
layers[layerCount++].mQuad = layer;
|
||||
}
|
||||
}
|
||||
|
@ -405,8 +401,8 @@ bool GameSurfaceLayer::GetRayIntersectionWithPanel(const XrVector3f& start,
|
|||
XrPosef& result3d) const {
|
||||
const uint32_t panelWidth = mSwapchain.mWidth / 2;
|
||||
const uint32_t panelHeight = mSwapchain.mHeight / 2;
|
||||
const XrVector2f scale =
|
||||
GetDensityScaleForSize(panelWidth, panelHeight, defaultLowerPanelScaleFactor, mResolutionFactor);
|
||||
const XrVector2f scale = GetDensityScaleForSize(
|
||||
panelWidth, panelHeight, defaultLowerPanelScaleFactor, mResolutionFactor);
|
||||
return ::GetRayIntersectionWithPanel(mLowerPanelFromWorld, panelWidth, panelHeight, scale,
|
||||
start, end, result2d, result3d);
|
||||
}
|
||||
|
|
|
@ -101,9 +101,9 @@ public:
|
|||
* @param layerCount the number of layers in the array
|
||||
* @param visibleLowerPanel whether the lower panel is shown/visible
|
||||
*/
|
||||
void Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers,
|
||||
uint32_t& layerCount, const XrPosef& headPose,
|
||||
const float& immersiveModeFactor, const bool visibleLowerPanel);
|
||||
void Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers, uint32_t& layerCount,
|
||||
const XrPosef& headPose, const float& immersiveModeFactor,
|
||||
const bool visibleLowerPanel);
|
||||
|
||||
/** Given an origin, direction of a ray,
|
||||
* returns the coordinates of where the ray will intersects
|
||||
|
@ -124,15 +124,15 @@ public:
|
|||
*
|
||||
* Note: assumes viewer is looking down the -Z axis.
|
||||
*/
|
||||
bool GetRayIntersectionWithPanel(const XrVector3f& start,
|
||||
const XrVector3f& end,
|
||||
XrVector2f& result2d,
|
||||
XrPosef& result3d) const;
|
||||
bool GetRayIntersectionWithPanelTopPanel(const XrVector3f& start,
|
||||
const XrVector3f& end,
|
||||
XrVector2f& result2d,
|
||||
XrPosef& result3d) const;
|
||||
void SetTopPanelFromController(const XrVector3f& controllerPosition);
|
||||
bool GetRayIntersectionWithPanel(const XrVector3f& start,
|
||||
const XrVector3f& end,
|
||||
XrVector2f& result2d,
|
||||
XrPosef& result3d) const;
|
||||
bool GetRayIntersectionWithPanelTopPanel(const XrVector3f& start,
|
||||
const XrVector3f& end,
|
||||
XrVector2f& result2d,
|
||||
XrPosef& result3d) const;
|
||||
void SetTopPanelFromController(const XrVector3f& controllerPosition);
|
||||
XrPosef GetTopPanelFromHeadPose(uint32_t eye, const XrPosef& headPose);
|
||||
|
||||
void SetTopPanelFromThumbstick(const float thumbstickY);
|
||||
|
|
|
@ -84,8 +84,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class Matrixf
|
||||
{
|
||||
class Matrixf {
|
||||
public:
|
||||
static void Identity(XrVector4f mat[4]) {
|
||||
mat[0] = {1.f, 0.f, 0.f, 0.f};
|
||||
|
@ -94,8 +93,7 @@ public:
|
|||
mat[3] = {0.f, 0.f, 0.f, 1.f};
|
||||
}
|
||||
|
||||
static XrVector4f XrVector4f_Multiply(const XrVector4f mat[4], const XrVector4f &v)
|
||||
{
|
||||
static XrVector4f XrVector4f_Multiply(const XrVector4f mat[4], const XrVector4f& v) {
|
||||
XrVector4f out;
|
||||
out.x = mat[0].x * v.x + mat[0].y * v.y + mat[0].z * v.z + mat[0].w * v.w;
|
||||
out.y = mat[1].x * v.x + mat[1].y * v.y + mat[1].z * v.z + mat[1].w * v.w;
|
||||
|
@ -104,8 +102,7 @@ public:
|
|||
return out;
|
||||
}
|
||||
|
||||
static XrVector3f XrVector3f_Multiply(const XrVector3f mat[3], const XrVector3f &v)
|
||||
{
|
||||
static XrVector3f XrVector3f_Multiply(const XrVector3f mat[3], const XrVector3f& v) {
|
||||
XrVector3f out;
|
||||
out.x = mat[0].x * v.x + mat[0].y * v.y + mat[0].z * v.z;
|
||||
out.y = mat[1].x * v.x + mat[1].y * v.y + mat[1].z * v.z;
|
||||
|
@ -114,34 +111,33 @@ public:
|
|||
}
|
||||
|
||||
// Returns a 3x3 minor of a 4x4 matrix.
|
||||
static float ToMinor(const float *matrix, int r0, int r1, int r2, int c0, int c1, int c2) {
|
||||
return matrix[4 * r0 + c0] *
|
||||
(matrix[4 * r1 + c1] * matrix[4 * r2 + c2] - matrix[4 * r2 + c1] * matrix[4 * r1 + c2]) -
|
||||
matrix[4 * r0 + c1] *
|
||||
(matrix[4 * r1 + c0] * matrix[4 * r2 + c2] - matrix[4 * r2 + c0] * matrix[4 * r1 + c2]) +
|
||||
matrix[4 * r0 + c2] *
|
||||
(matrix[4 * r1 + c0] * matrix[4 * r2 + c1] - matrix[4 * r2 + c0] * matrix[4 * r1 + c1]);
|
||||
static float ToMinor(const float* matrix, int r0, int r1, int r2, int c0, int c1, int c2) {
|
||||
return matrix[4 * r0 + c0] * (matrix[4 * r1 + c1] * matrix[4 * r2 + c2] -
|
||||
matrix[4 * r2 + c1] * matrix[4 * r1 + c2]) -
|
||||
matrix[4 * r0 + c1] * (matrix[4 * r1 + c0] * matrix[4 * r2 + c2] -
|
||||
matrix[4 * r2 + c0] * matrix[4 * r1 + c2]) +
|
||||
matrix[4 * r0 + c2] * (matrix[4 * r1 + c0] * matrix[4 * r2 + c1] -
|
||||
matrix[4 * r2 + c0] * matrix[4 * r1 + c1]);
|
||||
}
|
||||
|
||||
static void ToInverse(const XrVector4f in[4], XrVector4f out[4]) {
|
||||
float *matrix = (float*)in;
|
||||
float *inv_mat = (float*)out;
|
||||
const float rcpDet =
|
||||
1.0f / (matrix[0] * ToMinor(matrix, 1, 2, 3, 1, 2, 3) -
|
||||
matrix[1] * ToMinor(matrix, 1, 2, 3, 0, 2, 3) +
|
||||
matrix[2] * ToMinor(matrix, 1, 2, 3, 0, 1, 3) -
|
||||
matrix[3] * ToMinor(matrix, 1, 2, 3, 0, 1, 2));
|
||||
float* matrix = (float*)in;
|
||||
float* inv_mat = (float*)out;
|
||||
const float rcpDet = 1.0f / (matrix[0] * ToMinor(matrix, 1, 2, 3, 1, 2, 3) -
|
||||
matrix[1] * ToMinor(matrix, 1, 2, 3, 0, 2, 3) +
|
||||
matrix[2] * ToMinor(matrix, 1, 2, 3, 0, 1, 3) -
|
||||
matrix[3] * ToMinor(matrix, 1, 2, 3, 0, 1, 2));
|
||||
|
||||
inv_mat[0] = ToMinor(matrix, 1, 2, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[1] = -ToMinor(matrix, 0, 2, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[2] = ToMinor(matrix, 0, 1, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[3] = -ToMinor(matrix, 0, 1, 2, 1, 2, 3) * rcpDet;
|
||||
inv_mat[4] = -ToMinor(matrix, 1, 2, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[5] = ToMinor(matrix, 0, 2, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[6] = -ToMinor(matrix, 0, 1, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[7] = ToMinor(matrix, 0, 1, 2, 0, 2, 3) * rcpDet;
|
||||
inv_mat[8] = ToMinor(matrix, 1, 2, 3, 0, 1, 3) * rcpDet;
|
||||
inv_mat[9] = -ToMinor(matrix, 0, 2, 3, 0, 1, 3) * rcpDet;
|
||||
inv_mat[0] = ToMinor(matrix, 1, 2, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[1] = -ToMinor(matrix, 0, 2, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[2] = ToMinor(matrix, 0, 1, 3, 1, 2, 3) * rcpDet;
|
||||
inv_mat[3] = -ToMinor(matrix, 0, 1, 2, 1, 2, 3) * rcpDet;
|
||||
inv_mat[4] = -ToMinor(matrix, 1, 2, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[5] = ToMinor(matrix, 0, 2, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[6] = -ToMinor(matrix, 0, 1, 3, 0, 2, 3) * rcpDet;
|
||||
inv_mat[7] = ToMinor(matrix, 0, 1, 2, 0, 2, 3) * rcpDet;
|
||||
inv_mat[8] = ToMinor(matrix, 1, 2, 3, 0, 1, 3) * rcpDet;
|
||||
inv_mat[9] = -ToMinor(matrix, 0, 2, 3, 0, 1, 3) * rcpDet;
|
||||
inv_mat[10] = ToMinor(matrix, 0, 1, 3, 0, 1, 3) * rcpDet;
|
||||
inv_mat[11] = -ToMinor(matrix, 0, 1, 2, 0, 1, 3) * rcpDet;
|
||||
inv_mat[12] = -ToMinor(matrix, 1, 2, 3, 0, 1, 2) * rcpDet;
|
||||
|
@ -151,40 +147,39 @@ public:
|
|||
}
|
||||
|
||||
static void Projection(XrVector4f result[4], const float fov_x, const float fov_y,
|
||||
const float nearZ, const float farZ) {
|
||||
float *projectionMatrix = (float*)result;
|
||||
const float nearZ, const float farZ) {
|
||||
float* projectionMatrix = (float*)result;
|
||||
|
||||
float xmin, xmax, ymin, ymax;
|
||||
float width, height, depth;
|
||||
float xmin, xmax, ymin, ymax;
|
||||
float width, height, depth;
|
||||
|
||||
|
||||
ymax = nearZ * tan( fov_y );
|
||||
ymax = nearZ * tan(fov_y);
|
||||
ymin = -ymax;
|
||||
|
||||
xmax = nearZ * tan( fov_x );
|
||||
xmax = nearZ * tan(fov_x);
|
||||
xmin = -xmax;
|
||||
|
||||
width = xmax - xmin;
|
||||
width = xmax - xmin;
|
||||
height = ymax - ymin;
|
||||
depth = farZ - nearZ;
|
||||
depth = farZ - nearZ;
|
||||
|
||||
projectionMatrix[0] = 2 * nearZ / width;
|
||||
projectionMatrix[4] = 0;
|
||||
projectionMatrix[8] = ( xmax + xmin ) / width;
|
||||
projectionMatrix[0] = 2 * nearZ / width;
|
||||
projectionMatrix[4] = 0;
|
||||
projectionMatrix[8] = (xmax + xmin) / width;
|
||||
projectionMatrix[12] = 0;
|
||||
|
||||
projectionMatrix[1] = 0;
|
||||
projectionMatrix[5] = 2 * nearZ / height;
|
||||
projectionMatrix[9] = ( ymax + ymin ) / height;
|
||||
projectionMatrix[1] = 0;
|
||||
projectionMatrix[5] = 2 * nearZ / height;
|
||||
projectionMatrix[9] = (ymax + ymin) / height;
|
||||
projectionMatrix[13] = 0;
|
||||
|
||||
projectionMatrix[2] = 0;
|
||||
projectionMatrix[6] = 0;
|
||||
projectionMatrix[10] = -( farZ + nearZ ) / depth;
|
||||
projectionMatrix[2] = 0;
|
||||
projectionMatrix[6] = 0;
|
||||
projectionMatrix[10] = -(farZ + nearZ) / depth;
|
||||
projectionMatrix[14] = -2 * farZ * nearZ / depth;
|
||||
|
||||
projectionMatrix[3] = 0;
|
||||
projectionMatrix[7] = 0;
|
||||
projectionMatrix[3] = 0;
|
||||
projectionMatrix[7] = 0;
|
||||
projectionMatrix[11] = -1;
|
||||
projectionMatrix[15] = 0;
|
||||
}
|
||||
|
@ -196,8 +191,8 @@ public:
|
|||
|
||||
// Given a yaw (Y-axis), pitch (X-axis) and roll (Z-axis) in radians, create
|
||||
// a quaternion representing the same rotation
|
||||
static XrQuaternionf
|
||||
FromEuler(const float yawInRadians, const float pitchInRadians, const float rollInRadians) {
|
||||
static XrQuaternionf FromEuler(const float yawInRadians, const float pitchInRadians,
|
||||
const float rollInRadians) {
|
||||
// Calculate half angles
|
||||
const float halfPitch = pitchInRadians * 0.5f;
|
||||
const float halfYaw = yawInRadians * 0.5f;
|
||||
|
@ -265,8 +260,8 @@ public:
|
|||
// Compute a quaternion representing a rotation between three orthogonal
|
||||
// basis vectors. These vectors correspond to the forward, up, and right
|
||||
// directions of a rotation matrix.
|
||||
static XrQuaternionf
|
||||
FromThreeVectors(const XrVector3f& forward, const XrVector3f& up, const XrVector3f& right) {
|
||||
static XrQuaternionf FromThreeVectors(const XrVector3f& forward, const XrVector3f& up,
|
||||
const XrVector3f& right) {
|
||||
const float trace = right.x + up.y + forward.z;
|
||||
if (trace > 0.0f) {
|
||||
const float s = 0.5f / sqrtf(trace + 1.0f);
|
||||
|
@ -303,48 +298,49 @@ public:
|
|||
float sy2 = q.w * y2;
|
||||
float sz2 = q.w * z2;
|
||||
|
||||
float r[16] = {1 - (yy2 + zz2), xy2 + sz2, xz2 - sy2, 0.f, // column 0
|
||||
xy2 - sz2, 1 - (xx2 + zz2), yz2 + sx2, 0.f, // column 1
|
||||
xz2 + sy2, yz2 - sx2, 1 - (xx2 + yy2), 0.f, // column 2
|
||||
0.f, 0.f, 0.f, 1};// column 3
|
||||
float r[16] = {1 - (yy2 + zz2),
|
||||
xy2 + sz2,
|
||||
xz2 - sy2,
|
||||
0.f, // column 0
|
||||
xy2 - sz2,
|
||||
1 - (xx2 + zz2),
|
||||
yz2 + sx2,
|
||||
0.f, // column 1
|
||||
xz2 + sy2,
|
||||
yz2 - sx2,
|
||||
1 - (xx2 + yy2),
|
||||
0.f, // column 2
|
||||
0.f,
|
||||
0.f,
|
||||
0.f,
|
||||
1}; // column 3
|
||||
|
||||
std::memcpy(rotation, r, sizeof(float ) * 16);
|
||||
std::memcpy(rotation, r, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
static void ToVectors(const XrQuaternionf& q, XrVector3f& forward,
|
||||
XrVector3f& right, XrVector3f& up) {
|
||||
XrVector3f mat[3];
|
||||
static void ToVectors(const XrQuaternionf& q, XrVector3f& forward, XrVector3f& right,
|
||||
XrVector3f& up) {
|
||||
XrVector3f mat[3];
|
||||
const float ww = q.w * q.w;
|
||||
const float xx = q.x * q.x;
|
||||
const float yy = q.y * q.y;
|
||||
const float zz = q.z * q.z;
|
||||
|
||||
mat[0] = {
|
||||
ww + xx - yy - zz,
|
||||
2 * (q.x * q.y - q.w * q.z),
|
||||
2 * (q.x * q.z + q.w * q.y)};
|
||||
mat[0] = {ww + xx - yy - zz, 2 * (q.x * q.y - q.w * q.z), 2 * (q.x * q.z + q.w * q.y)};
|
||||
|
||||
mat[1] = {
|
||||
2 * (q.x * q.y + q.w * q.z),
|
||||
ww - xx + yy - zz,
|
||||
2 * (q.y * q.z - q.w * q.x)};
|
||||
mat[1] = {2 * (q.x * q.y + q.w * q.z), ww - xx + yy - zz, 2 * (q.y * q.z - q.w * q.x)};
|
||||
|
||||
mat[2] = {
|
||||
2 * (q.x * q.z - q.w * q.y),
|
||||
2 * (q.y * q.z + q.w * q.x),
|
||||
ww - xx - yy + zz};
|
||||
mat[2] = {2 * (q.x * q.z - q.w * q.y), 2 * (q.y * q.z + q.w * q.x), ww - xx - yy + zz};
|
||||
|
||||
XrVector3f glFlip[3] = {{0, 0, -1},
|
||||
{1, 0, 0},
|
||||
{0, 1, 0}};
|
||||
XrVector3f glFlip[3] = {{0, 0, -1}, {1, 0, 0}, {0, 1, 0}};
|
||||
|
||||
XrVector3f f = Matrixf::XrVector3f_Multiply(mat, glFlip[0]);
|
||||
XrVector3f r = Matrixf::XrVector3f_Multiply(mat, glFlip[1]);
|
||||
XrVector3f u = Matrixf::XrVector3f_Multiply(mat, glFlip[2]);
|
||||
|
||||
forward = {-f.z, -f.x, f.y};
|
||||
right = {-r.z, -r.x, r.y};
|
||||
up = {-u.z, -u.x, u.y};
|
||||
right = {-r.z, -r.x, r.y};
|
||||
up = {-u.z, -u.x, u.y};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ License : Licensed under GPLv3 or any later version.
|
|||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "video_core/renderer_base.h"
|
||||
#include "video_core/gpu.h"
|
||||
#include "core/core.h"
|
||||
#include "video_core/gpu.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
|
||||
#if defined(DEBUG_INPUT_VERBOSE)
|
||||
#define ALOG_INPUT_VERBOSE(...) ALOGI(__VA_ARGS__)
|
||||
|
@ -353,8 +353,7 @@ private:
|
|||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
|
||||
nullptr, XR_REFERENCE_SPACE_TYPE_VIEW,
|
||||
XrMath::Posef::Identity()};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci,
|
||||
&gOpenXr->mViewSpace));
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mViewSpace));
|
||||
}
|
||||
|
||||
// Get the pose of the local space.
|
||||
|
@ -374,90 +373,102 @@ private:
|
|||
}
|
||||
|
||||
gOpenXr->headLocation = {XR_TYPE_SPACE_LOCATION};
|
||||
OXR(xrLocateSpace(gOpenXr->mViewSpace, gOpenXr->mHeadSpace, frameState.predictedDisplayTime, &gOpenXr->headLocation));
|
||||
OXR(xrLocateSpace(gOpenXr->mViewSpace, gOpenXr->mHeadSpace, frameState.predictedDisplayTime,
|
||||
&gOpenXr->headLocation));
|
||||
|
||||
mInputStateFrame.SyncHandPoses(gOpenXr->mSession, mInputStateStatic, gOpenXr->mLocalSpace,
|
||||
frameState.predictedDisplayTime);
|
||||
|
||||
//XrMath::Vector3f::
|
||||
// XrMath::Vector3f::
|
||||
XrVector3f leftVec = {
|
||||
gOpenXr->headLocation.pose.position.x - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.x,
|
||||
gOpenXr->headLocation.pose.position.y - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.y,
|
||||
gOpenXr->headLocation.pose.position.z - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.z,
|
||||
gOpenXr->headLocation.pose.position.x -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.x,
|
||||
gOpenXr->headLocation.pose.position.y -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.y,
|
||||
gOpenXr->headLocation.pose.position.z -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.z,
|
||||
};
|
||||
const float lengthLeft = XrMath::Vector3f::Length(leftVec);
|
||||
XrVector3f rightVec = {
|
||||
gOpenXr->headLocation.pose.position.x - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.x,
|
||||
gOpenXr->headLocation.pose.position.y - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.y,
|
||||
gOpenXr->headLocation.pose.position.z - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.z,
|
||||
XrVector3f rightVec = {
|
||||
gOpenXr->headLocation.pose.position.x -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.x,
|
||||
gOpenXr->headLocation.pose.position.y -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.y,
|
||||
gOpenXr->headLocation.pose.position.z -
|
||||
mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.z,
|
||||
};
|
||||
const float lengthRight = XrMath::Vector3f::Length(rightVec);
|
||||
const float length = std::min(lengthLeft, lengthRight);
|
||||
const float length = std::min(lengthLeft, lengthRight);
|
||||
|
||||
// This block is for testing which uinform offset is needed
|
||||
// for a given game to implement new super-immersive profiles if needed
|
||||
static bool increase = false;
|
||||
static int uoffset = -1;
|
||||
static int uoffset = -1;
|
||||
{
|
||||
if (VRSettings::values.vr_immersive_mode > 90)
|
||||
{
|
||||
if (mInputStateFrame.mThumbrestTouchState[InputStateFrame::RIGHT_CONTROLLER].currentState)
|
||||
{
|
||||
if (increase)
|
||||
{
|
||||
if (VRSettings::values.vr_immersive_mode > 90) {
|
||||
if (mInputStateFrame.mThumbrestTouchState[InputStateFrame::RIGHT_CONTROLLER]
|
||||
.currentState) {
|
||||
if (increase) {
|
||||
++uoffset;
|
||||
increase = false;
|
||||
}
|
||||
|
||||
//There are 96 Vec4f; since we are applying 4 of them at a time we need to loop
|
||||
// after 92
|
||||
if (uoffset > 92)
|
||||
{
|
||||
uoffset = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// There are 96 Vec4f; since we are applying 4 of them at a time we need to loop
|
||||
// after 92
|
||||
if (uoffset > 92) { uoffset = 0; }
|
||||
} else {
|
||||
increase = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool showLowerPanel = true;
|
||||
float immersiveModeFactor = (VRSettings::values.vr_immersive_mode < 2) ? immersiveScaleFactor[VRSettings::values.vr_immersive_mode] : immersiveScaleFactor[2];
|
||||
bool showLowerPanel = true;
|
||||
float immersiveModeFactor = (VRSettings::values.vr_immersive_mode < 2)
|
||||
? immersiveScaleFactor[VRSettings::values.vr_immersive_mode]
|
||||
: immersiveScaleFactor[2];
|
||||
// Push the HMD position through to the Rasterizer to pass on to the VS Uniform
|
||||
if (Core::System::GetInstance().IsPoweredOn() &&
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer())
|
||||
{
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer()) {
|
||||
if (VRSettings::values.vr_immersive_mode == 0 ||
|
||||
//If in normal immersive mode then look down for the lower panel to reveal itself (for some reason the Roll function returns pitch)
|
||||
(VRSettings::values.vr_immersive_mode == 1 && XrMath::Quatf::GetRollInRadians(gOpenXr->headLocation.pose.orientation) < -MATH_FLOAT_PI / 8.0f) ||
|
||||
//If in "super immersive" mode then put controller next to head in order to disable the mode temporarily
|
||||
(VRSettings::values.vr_immersive_mode > 2 && length < 0.2))
|
||||
{
|
||||
// If in normal immersive mode then look down for the lower panel to reveal itself
|
||||
// (for some reason the Roll function returns pitch)
|
||||
(VRSettings::values.vr_immersive_mode == 1 &&
|
||||
XrMath::Quatf::GetRollInRadians(gOpenXr->headLocation.pose.orientation) <
|
||||
-MATH_FLOAT_PI / 8.0f) ||
|
||||
// If in "super immersive" mode then put controller next to head in order to disable
|
||||
// the mode temporarily
|
||||
(VRSettings::values.vr_immersive_mode > 2 && length < 0.2)) {
|
||||
XrVector4f identity[4] = {};
|
||||
XrMath::Matrixf::Identity(identity);
|
||||
immersiveModeFactor = 1.0f;
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(1, immersiveModeFactor, -1, (float*)identity);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(
|
||||
1, immersiveModeFactor, -1, (float*)identity);
|
||||
} else {
|
||||
XrVector4f transform[4] = {};
|
||||
XrMath::Quatf::ToRotationMatrix(gOpenXr->headLocation.pose.orientation, (float*)transform);
|
||||
XrMath::Quatf::ToRotationMatrix(gOpenXr->headLocation.pose.orientation,
|
||||
(float*)transform);
|
||||
|
||||
//Calculate the inverse
|
||||
// Calculate the inverse
|
||||
XrVector4f inv_transform[4];
|
||||
XrMath::Matrixf::ToInverse(transform, inv_transform);
|
||||
|
||||
XrQuaternionf invertedOrientation = XrMath::Quatf::Inverted(gOpenXr->headLocation.pose.orientation);
|
||||
XrVector3f position = XrMath::Quatf::Rotate(invertedOrientation, gOpenXr->headLocation.pose.position);
|
||||
XrQuaternionf invertedOrientation =
|
||||
XrMath::Quatf::Inverted(gOpenXr->headLocation.pose.orientation);
|
||||
XrVector3f position =
|
||||
XrMath::Quatf::Rotate(invertedOrientation, gOpenXr->headLocation.pose.position);
|
||||
|
||||
float gamePosScaler = powf(10.f, VRSettings::values.vr_immersive_positional_game_scaler);
|
||||
inv_transform[3].x = -position.x * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
inv_transform[3].y = -position.y * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
inv_transform[3].z = -position.z * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
float gamePosScaler =
|
||||
powf(10.f, VRSettings::values.vr_immersive_positional_game_scaler);
|
||||
inv_transform[3].x =
|
||||
-position.x * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
inv_transform[3].y =
|
||||
-position.y * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
inv_transform[3].z =
|
||||
-position.z * VRSettings::values.vr_immersive_positional_factor * gamePosScaler;
|
||||
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(VRSettings::values.vr_immersive_mode, immersiveModeFactor, uoffset, (float*)inv_transform);
|
||||
Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(
|
||||
VRSettings::values.vr_immersive_mode, immersiveModeFactor, uoffset,
|
||||
(float*)inv_transform);
|
||||
showLowerPanel = false;
|
||||
}
|
||||
}
|
||||
|
@ -477,8 +488,8 @@ private:
|
|||
layers[layerCount++].Passthrough = passthroughLayer;
|
||||
}
|
||||
|
||||
mGameSurfaceLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount, gOpenXr->headLocation.pose,
|
||||
immersiveModeFactor, showLowerPanel);
|
||||
mGameSurfaceLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount,
|
||||
gOpenXr->headLocation.pose, immersiveModeFactor, showLowerPanel);
|
||||
|
||||
if (mShouldShowErrorMessage) {
|
||||
mErrorMessageLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount);
|
||||
|
|
|
@ -43,10 +43,10 @@ struct Values {
|
|||
uint32_t resolution_factor = 0;
|
||||
int32_t vr_environment = 0;
|
||||
int32_t vr_immersive_mode = 0;
|
||||
bool extra_performance_mode_enabled = false;
|
||||
int32_t vr_si_mode_register_offset = -1;
|
||||
int32_t vr_immersive_positional_factor = 0;
|
||||
int32_t vr_immersive_positional_game_scaler = 0;
|
||||
bool extra_performance_mode_enabled = false;
|
||||
int32_t vr_si_mode_register_offset = -1;
|
||||
int32_t vr_immersive_positional_factor = 0;
|
||||
int32_t vr_immersive_positional_game_scaler = 0;
|
||||
} extern values;
|
||||
|
||||
} // namespace VRSettings
|
||||
|
|
Loading…
Reference in a new issue