Fix formatting

This commit is contained in:
amwatson 2024-02-15 16:52:55 -06:00
parent e3caeec765
commit e01de61155
6 changed files with 189 additions and 186 deletions

View file

@ -43,15 +43,15 @@ public:
XrViewConfigurationProperties mViewportConfig = {}; XrViewConfigurationProperties mViewportConfig = {};
static constexpr XrViewConfigurationType VIEW_CONFIG_TYPE = static constexpr XrViewConfigurationType VIEW_CONFIG_TYPE =
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO; XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
XrSpace mHeadSpace = XR_NULL_HANDLE; XrSpace mHeadSpace = XR_NULL_HANDLE;
XrSpace mViewSpace = XR_NULL_HANDLE; XrSpace mViewSpace = XR_NULL_HANDLE;
XrSpace mForwardDirectionSpace = XR_NULL_HANDLE; XrSpace mForwardDirectionSpace = XR_NULL_HANDLE;
XrSpaceLocation headLocation = {}; XrSpaceLocation headLocation = {};
XrSpace mLocalSpace = XR_NULL_HANDLE; XrSpace mLocalSpace = XR_NULL_HANDLE;
XrSpace mStageSpace = XR_NULL_HANDLE; XrSpace mStageSpace = XR_NULL_HANDLE;
size_t mMaxLayerCount = 0; size_t mMaxLayerCount = 0;
// EGL context // EGL context
std::unique_ptr<EglContext> mEglContext; std::unique_ptr<EglContext> mEglContext;

View file

@ -31,7 +31,7 @@ License : Licensed under GPLv3 or any later version.
namespace { namespace {
constexpr float defaultLowerPanelScaleFactor = 0.75f; constexpr float defaultLowerPanelScaleFactor = 0.75f;
constexpr float superImmersiveRadius = 0.5f; constexpr float superImmersiveRadius = 0.5f;
/** Used to translate texture coordinates into the corresponding coordinates /** Used to translate texture coordinates into the corresponding coordinates
* on the Android Activity Window. * on the Android Activity Window.
@ -234,7 +234,7 @@ GameSurfaceLayer::GameSurfaceLayer(const XrVector3f&& position, JNIEnv* env, job
{ {
if (mImmersiveMode > 0) { if (mImmersiveMode > 0) {
ALOGI("Using VR immersive mode {}", mImmersiveMode); ALOGI("Using VR immersive mode {}", mImmersiveMode);
mTopPanelFromWorld.position.z = mLowerPanelFromWorld.position.z; mTopPanelFromWorld.position.z = mLowerPanelFromWorld.position.z;
mLowerPanelFromWorld.position.y = -1.0f; mLowerPanelFromWorld.position.y = -1.0f;
} }
const int32_t initializationStatus = Init(activityObject, position, session); const int32_t initializationStatus = Init(activityObject, position, session);
@ -255,10 +255,9 @@ void GameSurfaceLayer::SetSurface() const {
mEnv->CallStaticVoidMethod(mVrGameSurfaceClass, setSurfaceMethodID, mActivityObject, mSurface); mEnv->CallStaticVoidMethod(mVrGameSurfaceClass, setSurfaceMethodID, mActivityObject, mSurface);
} }
void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers, 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 panelWidth = mSwapchain.mWidth / 2;
const uint32_t panelHeight = mSwapchain.mHeight / 2; const uint32_t panelHeight = mSwapchain.mHeight / 2;
const double aspectRatio = const double aspectRatio =
@ -271,8 +270,7 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
// Create the Top Display Panel (Curved display) // Create the Top Display Panel (Curved display)
for (uint32_t eye = 0; eye < NUM_EYES; eye++) { for (uint32_t eye = 0; eye < NUM_EYES; eye++) {
XrPosef topPanelFromWorld = mTopPanelFromWorld; XrPosef topPanelFromWorld = mTopPanelFromWorld;
if (mImmersiveMode > 1 && !showLowerPanel) if (mImmersiveMode > 1 && !showLowerPanel) {
{
topPanelFromWorld = GetTopPanelFromHeadPose(eye, headPose); 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 // Central angle controls how much of the cylinder is
// covered by the texture. Together, they control the // covered by the texture. Together, they control the
// scale of the texture. // 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; layer.eyeVisibility = eye == 0 ? XR_EYE_VISIBILITY_LEFT : XR_EYE_VISIBILITY_RIGHT;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage)); 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.offset.y = 0;
layer.subImage.imageRect.extent.width = panelWidth; layer.subImage.imageRect.extent.width = panelWidth;
layer.subImage.imageRect.extent.height = panelHeight - verticalBorderTex; layer.subImage.imageRect.extent.height = panelHeight - verticalBorderTex;
layer.subImage.imageArrayIndex = 0; layer.subImage.imageArrayIndex = 0;
layer.pose = topPanelFromWorld; layer.pose = topPanelFromWorld;
layer.pose.position.z += (mImmersiveMode < 2) ? radius : 0.0f; layer.pose.position.z += (mImmersiveMode < 2) ? radius : 0.0f;
layer.radius = radius; layer.radius = radius;
layer.centralAngle = (!mImmersiveMode ? GetCentralAngleSysprop() layer.centralAngle =
: GameSurfaceLayer::DEFAULT_CYLINDER_CENTRAL_ANGLE_DEGREES * immersiveModeFactor) * (!mImmersiveMode ? GetCentralAngleSysprop()
MATH_FLOAT_PI / 180.0f; : GameSurfaceLayer::DEFAULT_CYLINDER_CENTRAL_ANGLE_DEGREES *
immersiveModeFactor) *
MATH_FLOAT_PI / 180.0f;
layer.aspectRatio = -aspectRatio; layer.aspectRatio = -aspectRatio;
layers[layerCount++].mCylinder = layer; layers[layerCount++].mCylinder = layer;
} }
@ -343,7 +344,6 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
} }
} }
// Create the Lower Display Panel (flat touchscreen) // Create the Lower Display Panel (flat touchscreen)
// When citra is in stereo mode, this panel is also rendered in stereo (i.e. // 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 // 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 // FIXME we waste rendering time rendering both displays. That said, We also
// waste rendering time copying the buffer between runtimes. No time for // waste rendering time copying the buffer between runtimes. No time for
// that now! // that now!
if (showLowerPanel) if (showLowerPanel) {
{
const uint32_t cropHoriz = 90 * mResolutionFactor; const uint32_t cropHoriz = 90 * mResolutionFactor;
XrCompositionLayerQuad layer = {}; XrCompositionLayerQuad layer = {};
@ -366,22 +365,19 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH; layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage)); memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.subImage.swapchain = mSwapchain.mHandle; layer.subImage.swapchain = mSwapchain.mHandle;
layer.subImage.imageRect.offset.x = layer.subImage.imageRect.offset.x = (cropHoriz / 2) / immersiveModeFactor +
(cropHoriz / 2) / immersiveModeFactor + panelWidth * (0.5f - (0.5f / immersiveModeFactor));
panelWidth * (0.5f - (0.5f / immersiveModeFactor));
layer.subImage.imageRect.offset.y = layer.subImage.imageRect.offset.y =
panelHeight + verticalBorderTex + panelHeight + verticalBorderTex + panelHeight * (0.5f - (0.5f / immersiveModeFactor));
panelHeight * (0.5f - (0.5f / immersiveModeFactor)); layer.subImage.imageRect.extent.width = (panelWidth - cropHoriz) / immersiveModeFactor;
layer.subImage.imageRect.extent.width =
(panelWidth - cropHoriz) / immersiveModeFactor;
layer.subImage.imageRect.extent.height = panelHeight / immersiveModeFactor; layer.subImage.imageRect.extent.height = panelHeight / immersiveModeFactor;
layer.subImage.imageArrayIndex = 0; layer.subImage.imageArrayIndex = 0;
layer.pose = mLowerPanelFromWorld; layer.pose = mLowerPanelFromWorld;
const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight, const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight,
defaultLowerPanelScaleFactor, mResolutionFactor); defaultLowerPanelScaleFactor, mResolutionFactor);
layer.size.width = scale.x * defaultLowerPanelScaleFactor; layer.size.width = scale.x * defaultLowerPanelScaleFactor;
layer.size.height = scale.y * defaultLowerPanelScaleFactor; layer.size.height = scale.y * defaultLowerPanelScaleFactor;
layers[layerCount++].mQuad = layer; layers[layerCount++].mQuad = layer;
} }
} }
@ -405,8 +401,8 @@ bool GameSurfaceLayer::GetRayIntersectionWithPanel(const XrVector3f& start,
XrPosef& result3d) const { XrPosef& result3d) const {
const uint32_t panelWidth = mSwapchain.mWidth / 2; const uint32_t panelWidth = mSwapchain.mWidth / 2;
const uint32_t panelHeight = mSwapchain.mHeight / 2; const uint32_t panelHeight = mSwapchain.mHeight / 2;
const XrVector2f scale = const XrVector2f scale = GetDensityScaleForSize(
GetDensityScaleForSize(panelWidth, panelHeight, defaultLowerPanelScaleFactor, mResolutionFactor); panelWidth, panelHeight, defaultLowerPanelScaleFactor, mResolutionFactor);
return ::GetRayIntersectionWithPanel(mLowerPanelFromWorld, panelWidth, panelHeight, scale, return ::GetRayIntersectionWithPanel(mLowerPanelFromWorld, panelWidth, panelHeight, scale,
start, end, result2d, result3d); start, end, result2d, result3d);
} }

View file

@ -101,9 +101,9 @@ public:
* @param layerCount the number of layers in the array * @param layerCount the number of layers in the array
* @param visibleLowerPanel whether the lower panel is shown/visible * @param visibleLowerPanel whether the lower panel is shown/visible
*/ */
void Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers, void Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers, uint32_t& layerCount,
uint32_t& layerCount, const XrPosef& headPose, const XrPosef& headPose, const float& immersiveModeFactor,
const float& immersiveModeFactor, const bool visibleLowerPanel); const bool visibleLowerPanel);
/** Given an origin, direction of a ray, /** Given an origin, direction of a ray,
* returns the coordinates of where the ray will intersects * returns the coordinates of where the ray will intersects
@ -124,15 +124,15 @@ public:
* *
* Note: assumes viewer is looking down the -Z axis. * Note: assumes viewer is looking down the -Z axis.
*/ */
bool GetRayIntersectionWithPanel(const XrVector3f& start, bool GetRayIntersectionWithPanel(const XrVector3f& start,
const XrVector3f& end, const XrVector3f& end,
XrVector2f& result2d, XrVector2f& result2d,
XrPosef& result3d) const; XrPosef& result3d) const;
bool GetRayIntersectionWithPanelTopPanel(const XrVector3f& start, bool GetRayIntersectionWithPanelTopPanel(const XrVector3f& start,
const XrVector3f& end, const XrVector3f& end,
XrVector2f& result2d, XrVector2f& result2d,
XrPosef& result3d) const; XrPosef& result3d) const;
void SetTopPanelFromController(const XrVector3f& controllerPosition); void SetTopPanelFromController(const XrVector3f& controllerPosition);
XrPosef GetTopPanelFromHeadPose(uint32_t eye, const XrPosef& headPose); XrPosef GetTopPanelFromHeadPose(uint32_t eye, const XrPosef& headPose);
void SetTopPanelFromThumbstick(const float thumbstickY); void SetTopPanelFromThumbstick(const float thumbstickY);

View file

@ -84,8 +84,7 @@ public:
} }
}; };
class Matrixf class Matrixf {
{
public: public:
static void Identity(XrVector4f mat[4]) { static void Identity(XrVector4f mat[4]) {
mat[0] = {1.f, 0.f, 0.f, 0.f}; 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}; 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; 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.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; 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; 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; XrVector3f out;
out.x = mat[0].x * v.x + mat[0].y * v.y + mat[0].z * v.z; 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; 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. // 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) { static float ToMinor(const float* matrix, int r0, int r1, int r2, int c0, int c1, int c2) {
return matrix[4 * r0 + c0] * return matrix[4 * r0 + c0] * (matrix[4 * r1 + c1] * matrix[4 * r2 + c2] -
(matrix[4 * r1 + c1] * matrix[4 * r2 + c2] - matrix[4 * r2 + c1] * matrix[4 * r1 + c2]) - matrix[4 * r2 + c1] * matrix[4 * r1 + c2]) -
matrix[4 * r0 + c1] * matrix[4 * r0 + c1] * (matrix[4 * r1 + c0] * matrix[4 * r2 + c2] -
(matrix[4 * r1 + c0] * matrix[4 * r2 + c2] - matrix[4 * r2 + c0] * matrix[4 * r1 + c2]) + matrix[4 * r2 + c0] * matrix[4 * r1 + c2]) +
matrix[4 * r0 + c2] * matrix[4 * r0 + c2] * (matrix[4 * r1 + c0] * matrix[4 * r2 + c1] -
(matrix[4 * r1 + c0] * matrix[4 * r2 + c1] - matrix[4 * r2 + c0] * matrix[4 * r1 + c1]); matrix[4 * r2 + c0] * matrix[4 * r1 + c1]);
} }
static void ToInverse(const XrVector4f in[4], XrVector4f out[4]) { static void ToInverse(const XrVector4f in[4], XrVector4f out[4]) {
float *matrix = (float*)in; float* matrix = (float*)in;
float *inv_mat = (float*)out; float* inv_mat = (float*)out;
const float rcpDet = const float rcpDet = 1.0f / (matrix[0] * ToMinor(matrix, 1, 2, 3, 1, 2, 3) -
1.0f / (matrix[0] * ToMinor(matrix, 1, 2, 3, 1, 2, 3) - matrix[1] * ToMinor(matrix, 1, 2, 3, 0, 2, 3) +
matrix[1] * ToMinor(matrix, 1, 2, 3, 0, 2, 3) + matrix[2] * ToMinor(matrix, 1, 2, 3, 0, 1, 3) -
matrix[2] * ToMinor(matrix, 1, 2, 3, 0, 1, 3) - matrix[3] * ToMinor(matrix, 1, 2, 3, 0, 1, 2));
matrix[3] * ToMinor(matrix, 1, 2, 3, 0, 1, 2));
inv_mat[0] = ToMinor(matrix, 1, 2, 3, 1, 2, 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[1] = -ToMinor(matrix, 0, 2, 3, 1, 2, 3) * rcpDet;
inv_mat[2] = ToMinor(matrix, 0, 1, 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[3] = -ToMinor(matrix, 0, 1, 2, 1, 2, 3) * rcpDet;
inv_mat[4] = -ToMinor(matrix, 1, 2, 3, 0, 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[5] = ToMinor(matrix, 0, 2, 3, 0, 2, 3) * rcpDet;
inv_mat[6] = -ToMinor(matrix, 0, 1, 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[7] = ToMinor(matrix, 0, 1, 2, 0, 2, 3) * rcpDet;
inv_mat[8] = ToMinor(matrix, 1, 2, 3, 0, 1, 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[9] = -ToMinor(matrix, 0, 2, 3, 0, 1, 3) * rcpDet;
inv_mat[10] = ToMinor(matrix, 0, 1, 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[11] = -ToMinor(matrix, 0, 1, 2, 0, 1, 3) * rcpDet;
inv_mat[12] = -ToMinor(matrix, 1, 2, 3, 0, 1, 2) * 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, static void Projection(XrVector4f result[4], const float fov_x, const float fov_y,
const float nearZ, const float farZ) { const float nearZ, const float farZ) {
float *projectionMatrix = (float*)result; float* projectionMatrix = (float*)result;
float xmin, xmax, ymin, ymax; float xmin, xmax, ymin, ymax;
float width, height, depth; float width, height, depth;
ymax = nearZ * tan(fov_y);
ymax = nearZ * tan( fov_y );
ymin = -ymax; ymin = -ymax;
xmax = nearZ * tan( fov_x ); xmax = nearZ * tan(fov_x);
xmin = -xmax; xmin = -xmax;
width = xmax - xmin; width = xmax - xmin;
height = ymax - ymin; height = ymax - ymin;
depth = farZ - nearZ; depth = farZ - nearZ;
projectionMatrix[0] = 2 * nearZ / width; projectionMatrix[0] = 2 * nearZ / width;
projectionMatrix[4] = 0; projectionMatrix[4] = 0;
projectionMatrix[8] = ( xmax + xmin ) / width; projectionMatrix[8] = (xmax + xmin) / width;
projectionMatrix[12] = 0; projectionMatrix[12] = 0;
projectionMatrix[1] = 0; projectionMatrix[1] = 0;
projectionMatrix[5] = 2 * nearZ / height; projectionMatrix[5] = 2 * nearZ / height;
projectionMatrix[9] = ( ymax + ymin ) / height; projectionMatrix[9] = (ymax + ymin) / height;
projectionMatrix[13] = 0; projectionMatrix[13] = 0;
projectionMatrix[2] = 0; projectionMatrix[2] = 0;
projectionMatrix[6] = 0; projectionMatrix[6] = 0;
projectionMatrix[10] = -( farZ + nearZ ) / depth; projectionMatrix[10] = -(farZ + nearZ) / depth;
projectionMatrix[14] = -2 * farZ * nearZ / depth; projectionMatrix[14] = -2 * farZ * nearZ / depth;
projectionMatrix[3] = 0; projectionMatrix[3] = 0;
projectionMatrix[7] = 0; projectionMatrix[7] = 0;
projectionMatrix[11] = -1; projectionMatrix[11] = -1;
projectionMatrix[15] = 0; projectionMatrix[15] = 0;
} }
@ -196,8 +191,8 @@ public:
// Given a yaw (Y-axis), pitch (X-axis) and roll (Z-axis) in radians, create // Given a yaw (Y-axis), pitch (X-axis) and roll (Z-axis) in radians, create
// a quaternion representing the same rotation // a quaternion representing the same rotation
static XrQuaternionf static XrQuaternionf FromEuler(const float yawInRadians, const float pitchInRadians,
FromEuler(const float yawInRadians, const float pitchInRadians, const float rollInRadians) { const float rollInRadians) {
// Calculate half angles // Calculate half angles
const float halfPitch = pitchInRadians * 0.5f; const float halfPitch = pitchInRadians * 0.5f;
const float halfYaw = yawInRadians * 0.5f; const float halfYaw = yawInRadians * 0.5f;
@ -265,8 +260,8 @@ public:
// Compute a quaternion representing a rotation between three orthogonal // Compute a quaternion representing a rotation between three orthogonal
// basis vectors. These vectors correspond to the forward, up, and right // basis vectors. These vectors correspond to the forward, up, and right
// directions of a rotation matrix. // directions of a rotation matrix.
static XrQuaternionf static XrQuaternionf FromThreeVectors(const XrVector3f& forward, const XrVector3f& up,
FromThreeVectors(const XrVector3f& forward, const XrVector3f& up, const XrVector3f& right) { const XrVector3f& right) {
const float trace = right.x + up.y + forward.z; const float trace = right.x + up.y + forward.z;
if (trace > 0.0f) { if (trace > 0.0f) {
const float s = 0.5f / sqrtf(trace + 1.0f); const float s = 0.5f / sqrtf(trace + 1.0f);
@ -303,48 +298,49 @@ public:
float sy2 = q.w * y2; float sy2 = q.w * y2;
float sz2 = q.w * z2; float sz2 = q.w * z2;
float r[16] = {1 - (yy2 + zz2), xy2 + sz2, xz2 - sy2, 0.f, // column 0 float r[16] = {1 - (yy2 + zz2),
xy2 - sz2, 1 - (xx2 + zz2), yz2 + sx2, 0.f, // column 1 xy2 + sz2,
xz2 + sy2, yz2 - sx2, 1 - (xx2 + yy2), 0.f, // column 2 xz2 - sy2,
0.f, 0.f, 0.f, 1};// column 3 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, static void ToVectors(const XrQuaternionf& q, XrVector3f& forward, XrVector3f& right,
XrVector3f& right, XrVector3f& up) { XrVector3f& up) {
XrVector3f mat[3]; XrVector3f mat[3];
const float ww = q.w * q.w; const float ww = q.w * q.w;
const float xx = q.x * q.x; const float xx = q.x * q.x;
const float yy = q.y * q.y; const float yy = q.y * q.y;
const float zz = q.z * q.z; const float zz = q.z * q.z;
mat[0] = { mat[0] = {ww + xx - yy - zz, 2 * (q.x * q.y - q.w * q.z), 2 * (q.x * q.z + q.w * q.y)};
ww + xx - yy - zz,
2 * (q.x * q.y - q.w * q.z),
2 * (q.x * q.z + q.w * q.y)};
mat[1] = { mat[1] = {2 * (q.x * q.y + q.w * q.z), ww - xx + yy - zz, 2 * (q.y * q.z - q.w * q.x)};
2 * (q.x * q.y + q.w * q.z),
ww - xx + yy - zz,
2 * (q.y * q.z - q.w * q.x)};
mat[2] = { mat[2] = {2 * (q.x * q.z - q.w * q.y), 2 * (q.y * q.z + q.w * q.x), ww - xx - yy + zz};
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}, XrVector3f glFlip[3] = {{0, 0, -1}, {1, 0, 0}, {0, 1, 0}};
{1, 0, 0},
{0, 1, 0}};
XrVector3f f = Matrixf::XrVector3f_Multiply(mat, glFlip[0]); XrVector3f f = Matrixf::XrVector3f_Multiply(mat, glFlip[0]);
XrVector3f r = Matrixf::XrVector3f_Multiply(mat, glFlip[1]); XrVector3f r = Matrixf::XrVector3f_Multiply(mat, glFlip[1]);
XrVector3f u = Matrixf::XrVector3f_Multiply(mat, glFlip[2]); XrVector3f u = Matrixf::XrVector3f_Multiply(mat, glFlip[2]);
forward = {-f.z, -f.x, f.y}; forward = {-f.z, -f.x, f.y};
right = {-r.z, -r.x, r.y}; right = {-r.z, -r.x, r.y};
up = {-u.z, -u.x, u.y}; up = {-u.z, -u.x, u.y};
} }
}; };

View file

@ -37,9 +37,9 @@ License : Licensed under GPLv3 or any later version.
#include <sys/prctl.h> #include <sys/prctl.h>
#include <unistd.h> #include <unistd.h>
#include "video_core/renderer_base.h"
#include "video_core/gpu.h"
#include "core/core.h" #include "core/core.h"
#include "video_core/gpu.h"
#include "video_core/renderer_base.h"
#if defined(DEBUG_INPUT_VERBOSE) #if defined(DEBUG_INPUT_VERBOSE)
#define ALOG_INPUT_VERBOSE(...) ALOGI(__VA_ARGS__) #define ALOG_INPUT_VERBOSE(...) ALOGI(__VA_ARGS__)
@ -353,8 +353,7 @@ private:
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO, const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
nullptr, XR_REFERENCE_SPACE_TYPE_VIEW, nullptr, XR_REFERENCE_SPACE_TYPE_VIEW,
XrMath::Posef::Identity()}; XrMath::Posef::Identity()};
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mViewSpace));
&gOpenXr->mViewSpace));
} }
// Get the pose of the local space. // Get the pose of the local space.
@ -374,90 +373,102 @@ private:
} }
gOpenXr->headLocation = {XR_TYPE_SPACE_LOCATION}; 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, mInputStateFrame.SyncHandPoses(gOpenXr->mSession, mInputStateStatic, gOpenXr->mLocalSpace,
frameState.predictedDisplayTime); frameState.predictedDisplayTime);
//XrMath::Vector3f:: // XrMath::Vector3f::
XrVector3f leftVec = { XrVector3f leftVec = {
gOpenXr->headLocation.pose.position.x - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.x, gOpenXr->headLocation.pose.position.x -
gOpenXr->headLocation.pose.position.y - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.y, mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.x,
gOpenXr->headLocation.pose.position.z - mInputStateFrame.mHandPositions[InputStateFrame::LEFT_CONTROLLER].pose.position.z, 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); const float lengthLeft = XrMath::Vector3f::Length(leftVec);
XrVector3f rightVec = { XrVector3f rightVec = {
gOpenXr->headLocation.pose.position.x - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.x, gOpenXr->headLocation.pose.position.x -
gOpenXr->headLocation.pose.position.y - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.y, mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.x,
gOpenXr->headLocation.pose.position.z - mInputStateFrame.mHandPositions[InputStateFrame::RIGHT_CONTROLLER].pose.position.z, 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 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 // This block is for testing which uinform offset is needed
// for a given game to implement new super-immersive profiles if needed // for a given game to implement new super-immersive profiles if needed
static bool increase = false; static bool increase = false;
static int uoffset = -1; static int uoffset = -1;
{ {
if (VRSettings::values.vr_immersive_mode > 90) if (VRSettings::values.vr_immersive_mode > 90) {
{ if (mInputStateFrame.mThumbrestTouchState[InputStateFrame::RIGHT_CONTROLLER]
if (mInputStateFrame.mThumbrestTouchState[InputStateFrame::RIGHT_CONTROLLER].currentState) .currentState) {
{ if (increase) {
if (increase)
{
++uoffset; ++uoffset;
increase = false; increase = false;
} }
//There are 96 Vec4f; since we are applying 4 of them at a time we need to loop // There are 96 Vec4f; since we are applying 4 of them at a time we need to loop
// after 92 // after 92
if (uoffset > 92) if (uoffset > 92) { uoffset = 0; }
{ } else {
uoffset = 0;
}
}
else
{
increase = true; increase = true;
} }
} }
} }
bool showLowerPanel = true; bool showLowerPanel = true;
float immersiveModeFactor = (VRSettings::values.vr_immersive_mode < 2) ? immersiveScaleFactor[VRSettings::values.vr_immersive_mode] : immersiveScaleFactor[2]; 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 // Push the HMD position through to the Rasterizer to pass on to the VS Uniform
if (Core::System::GetInstance().IsPoweredOn() && 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 (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) // If in normal immersive mode then look down for the lower panel to reveal itself
(VRSettings::values.vr_immersive_mode == 1 && XrMath::Quatf::GetRollInRadians(gOpenXr->headLocation.pose.orientation) < -MATH_FLOAT_PI / 8.0f) || // (for some reason the Roll function returns pitch)
//If in "super immersive" mode then put controller next to head in order to disable the mode temporarily (VRSettings::values.vr_immersive_mode == 1 &&
(VRSettings::values.vr_immersive_mode > 2 && length < 0.2)) 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] = {}; XrVector4f identity[4] = {};
XrMath::Matrixf::Identity(identity); XrMath::Matrixf::Identity(identity);
immersiveModeFactor = 1.0f; immersiveModeFactor = 1.0f;
Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(1, immersiveModeFactor, -1, (float*)identity); Core::System::GetInstance().GPU().Renderer().Rasterizer()->SetVRData(
} 1, immersiveModeFactor, -1, (float*)identity);
else } else {
{
XrVector4f transform[4] = {}; 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]; XrVector4f inv_transform[4];
XrMath::Matrixf::ToInverse(transform, inv_transform); XrMath::Matrixf::ToInverse(transform, inv_transform);
XrQuaternionf invertedOrientation = XrMath::Quatf::Inverted(gOpenXr->headLocation.pose.orientation); XrQuaternionf invertedOrientation =
XrVector3f position = XrMath::Quatf::Rotate(invertedOrientation, gOpenXr->headLocation.pose.position); 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); float gamePosScaler =
inv_transform[3].x = -position.x * VRSettings::values.vr_immersive_positional_factor * gamePosScaler; powf(10.f, VRSettings::values.vr_immersive_positional_game_scaler);
inv_transform[3].y = -position.y * VRSettings::values.vr_immersive_positional_factor * gamePosScaler; inv_transform[3].x =
inv_transform[3].z = -position.z * VRSettings::values.vr_immersive_positional_factor * gamePosScaler; -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; showLowerPanel = false;
} }
} }
@ -477,8 +488,8 @@ private:
layers[layerCount++].Passthrough = passthroughLayer; layers[layerCount++].Passthrough = passthroughLayer;
} }
mGameSurfaceLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount, gOpenXr->headLocation.pose, mGameSurfaceLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount,
immersiveModeFactor, showLowerPanel); gOpenXr->headLocation.pose, immersiveModeFactor, showLowerPanel);
if (mShouldShowErrorMessage) { if (mShouldShowErrorMessage) {
mErrorMessageLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount); mErrorMessageLayer->Frame(gOpenXr->mLocalSpace, layers, layerCount);

View file

@ -43,10 +43,10 @@ struct Values {
uint32_t resolution_factor = 0; uint32_t resolution_factor = 0;
int32_t vr_environment = 0; int32_t vr_environment = 0;
int32_t vr_immersive_mode = 0; int32_t vr_immersive_mode = 0;
bool extra_performance_mode_enabled = false; bool extra_performance_mode_enabled = false;
int32_t vr_si_mode_register_offset = -1; int32_t vr_si_mode_register_offset = -1;
int32_t vr_immersive_positional_factor = 0; int32_t vr_immersive_positional_factor = 0;
int32_t vr_immersive_positional_game_scaler = 0; int32_t vr_immersive_positional_game_scaler = 0;
} extern values; } extern values;
} // namespace VRSettings } // namespace VRSettings