mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
HMD fixes.
This commit is contained in:
parent
d3b49ffc68
commit
c400562d61
3 changed files with 97 additions and 21 deletions
|
@ -165,9 +165,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
|
|
||||||
while (!entry::processEvents(width, height, debug, reset) )
|
while (!entry::processEvents(width, height, debug, reset) )
|
||||||
{
|
{
|
||||||
// Set view 0 default viewport.
|
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
|
||||||
|
|
||||||
// This dummy draw call is here to make sure that view 0 is cleared
|
// This dummy draw call is here to make sure that view 0 is cleared
|
||||||
// if no other draw calls are submitted to view 0.
|
// if no other draw calls are submitted to view 0.
|
||||||
bgfx::submit(0);
|
bgfx::submit(0);
|
||||||
|
@ -199,15 +196,38 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
float eye[3] = {0, 0, -1.0f };
|
float eye[3] = {0, 0, -1.0f };
|
||||||
|
|
||||||
float view[16];
|
float view[16];
|
||||||
float proj[16];
|
|
||||||
bx::mtxLookAt(view, eye, at);
|
bx::mtxLookAt(view, eye, at);
|
||||||
|
|
||||||
// Setup a top-left ortho matrix for screen space drawing.
|
const float centering = 0.5f;
|
||||||
float centering = 0.5f;
|
|
||||||
bx::mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f);
|
|
||||||
|
|
||||||
// Set view and projection matrix for view 0.
|
// Setup a top-left ortho matrix for screen space drawing.
|
||||||
bgfx::setViewTransform(0, view, proj);
|
const bgfx::HMD* hmd = bgfx::getHMD();
|
||||||
|
if (NULL != hmd)
|
||||||
|
{
|
||||||
|
float proj[16];
|
||||||
|
bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f);
|
||||||
|
|
||||||
|
static float time = 0.0f;
|
||||||
|
time += 0.05f;
|
||||||
|
|
||||||
|
const float dist = 10.0f;
|
||||||
|
const float offset0 = -proj[8] + (hmd->eye[0].adjust[0] / dist * proj[0]);
|
||||||
|
const float offset1 = -proj[8] + (hmd->eye[1].adjust[0] / dist * proj[0]);
|
||||||
|
|
||||||
|
float ortho[2][16];
|
||||||
|
const float offsetx = width/2.0f;
|
||||||
|
bx::mtxOrtho(ortho[0], centering, offsetx + centering, height + centering, centering, -1.0f, 1.0f, offset0);
|
||||||
|
bx::mtxOrtho(ortho[1], centering, offsetx + centering, height + centering, centering, -1.0f, 1.0f, offset1);
|
||||||
|
bgfx::setViewTransform(0, view, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
|
||||||
|
bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float ortho[16];
|
||||||
|
bx::mtxOrtho(ortho, centering, width + centering, height + centering, centering, -1.0f, 1.0f);
|
||||||
|
bgfx::setViewTransform(0, view, ortho);
|
||||||
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
// Submit the debug text.
|
// Submit the debug text.
|
||||||
textBufferManager->submitTextBuffer(transientText, 0);
|
textBufferManager->submitTextBuffer(transientText, 0);
|
||||||
|
|
|
@ -144,7 +144,13 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
, height
|
, height
|
||||||
);
|
);
|
||||||
|
|
||||||
imguiBeginScrollArea("Text Area", width - guiPanelWidth - 10, 10, guiPanelWidth, guiPanelHeight, &scrollArea);
|
imguiBeginScrollArea("Text Area"
|
||||||
|
, width - guiPanelWidth - 10
|
||||||
|
, 10
|
||||||
|
, guiPanelWidth
|
||||||
|
, guiPanelHeight
|
||||||
|
, &scrollArea
|
||||||
|
);
|
||||||
imguiSeparatorLine();
|
imguiSeparatorLine();
|
||||||
|
|
||||||
bool recomputeVisibleText = false;
|
bool recomputeVisibleText = false;
|
||||||
|
@ -196,15 +202,39 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
float eye[3] = {0, 0, -1.0f };
|
float eye[3] = {0, 0, -1.0f };
|
||||||
|
|
||||||
float view[16];
|
float view[16];
|
||||||
float proj[16];
|
|
||||||
bx::mtxLookAt(view, eye, at);
|
bx::mtxLookAt(view, eye, at);
|
||||||
float centering = 0.5f;
|
|
||||||
|
const float centering = 0.5f;
|
||||||
|
|
||||||
// Setup a top-left ortho matrix for screen space drawing.
|
// Setup a top-left ortho matrix for screen space drawing.
|
||||||
bx::mtxOrtho(proj, centering, width + centering, height + centering, centering, -1.0f, 1.0f);
|
const bgfx::HMD* hmd = bgfx::getHMD();
|
||||||
|
if (NULL != hmd)
|
||||||
|
{
|
||||||
|
float proj[16];
|
||||||
|
bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f);
|
||||||
|
|
||||||
// Set view and projection matrix for view 0.
|
static float time = 0.0f;
|
||||||
bgfx::setViewTransform(0, view, proj);
|
time += 0.05f;
|
||||||
|
|
||||||
|
const float dist = 10.0f;
|
||||||
|
const float offset0 = -proj[8] + (hmd->eye[0].adjust[0] / dist * proj[0]);
|
||||||
|
const float offset1 = -proj[8] + (hmd->eye[1].adjust[0] / dist * proj[0]);
|
||||||
|
|
||||||
|
float ortho[2][16];
|
||||||
|
const float viewOffset = width/4.0f;
|
||||||
|
const float viewWidth = width/2.0f;
|
||||||
|
bx::mtxOrtho(ortho[0], centering + viewOffset, centering + viewOffset + viewWidth, height + centering, centering, -1.0f, 1.0f, offset0);
|
||||||
|
bx::mtxOrtho(ortho[1], centering + viewOffset, centering + viewOffset + viewWidth, height + centering, centering, -1.0f, 1.0f, offset1);
|
||||||
|
bgfx::setViewTransform(0, view, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
|
||||||
|
bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float ortho[16];
|
||||||
|
bx::mtxOrtho(ortho, centering, width + centering, height + centering, centering, -1.0f, 1.0f);
|
||||||
|
bgfx::setViewTransform(0, view, ortho);
|
||||||
|
bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
//very crude approximation :(
|
//very crude approximation :(
|
||||||
float textAreaWidth = 0.5f * 66.0f * fontManager->getFontInfo(fontScaled).maxAdvanceWidth;
|
float textAreaWidth = 0.5f * 66.0f * fontManager->getFontInfo(fontScaled).maxAdvanceWidth;
|
||||||
|
|
|
@ -775,11 +775,37 @@ struct Imgui
|
||||||
m_viewHeight = _height;
|
m_viewHeight = _height;
|
||||||
bgfx::setViewName(_view, "IMGUI");
|
bgfx::setViewName(_view, "IMGUI");
|
||||||
bgfx::setViewSeq(_view, true);
|
bgfx::setViewSeq(_view, true);
|
||||||
bgfx::setViewRect(_view, 0, 0, _width, _height);
|
|
||||||
|
const bgfx::HMD* hmd = bgfx::getHMD();
|
||||||
|
if (NULL != hmd)
|
||||||
|
{
|
||||||
|
m_viewWidth = _width / 2;
|
||||||
|
|
||||||
float proj[16];
|
float proj[16];
|
||||||
bx::mtxOrtho(proj, 0.0f, (float)_width, (float)_height, 0.0f, 0.0f, 1000.0f);
|
bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f);
|
||||||
bgfx::setViewTransform(_view, NULL, proj);
|
|
||||||
|
static float time = 0.0f;
|
||||||
|
time += 0.05f;
|
||||||
|
|
||||||
|
const float dist = 10.0f;
|
||||||
|
const float offset0 = -proj[8] + (hmd->eye[0].adjust[0] / dist * proj[0]);
|
||||||
|
const float offset1 = -proj[8] + (hmd->eye[1].adjust[0] / dist * proj[0]);
|
||||||
|
|
||||||
|
float ortho[2][16];
|
||||||
|
const float viewOffset = _width/4.0f;
|
||||||
|
const float viewWidth = _width/2.0f;
|
||||||
|
bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f, offset0);
|
||||||
|
bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f, offset1);
|
||||||
|
bgfx::setViewTransform(_view, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
|
||||||
|
bgfx::setViewRect(_view, 0, 0, hmd->width, hmd->height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float ortho[16];
|
||||||
|
bx::mtxOrtho(ortho, 0.0f, (float)m_viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f);
|
||||||
|
bgfx::setViewTransform(_view, NULL, ortho);
|
||||||
|
bgfx::setViewRect(_view, 0, 0, _width, _height);
|
||||||
|
}
|
||||||
|
|
||||||
updateInput(_mx, _my, _button, _scroll, _inputChar);
|
updateInput(_mx, _my, _button, _scroll, _inputChar);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue