aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDEC05EBA <dec05eba@protonmail.com>2020-01-05 17:35:09 +0100
committerDEC05EBA <dec05eba@protonmail.com>2020-01-05 17:35:09 +0100
commit07643327ae81657953e158fc6390a91420ddad1f (patch)
tree0104fa6bc62bac0e18ab81ddca5cb3fc9066f65c
parent42e9415ef61017a2589c5f2fc96645b233a51be1 (diff)
make it work
-rw-r--r--LICENSE30
-rw-r--r--README.md9
-rw-r--r--project.conf2
-rw-r--r--src/main.cpp310
4 files changed, 78 insertions, 273 deletions
diff --git a/LICENSE b/LICENSE
index c6b1dc1..81da884 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,33 +1,3 @@
-Original license, from openvr samples (https://github.com/ValveSoftware/openvr/tree/master/samples):
-Copyright (c) 2015, Valve Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
-list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation and/or
-other materials provided with the distribution.
-
-3. Neither the name of the copyright holder nor the names of its contributors
-may be used to endorse or promote products derived from this software without
-specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-License of modified code:
Copyright (c) 2019, DEC05EBA
All rights reserved.
diff --git a/README.md b/README.md
index 8e4c1f1..066c1de 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
-A virtual reality window manager for Linux running X11, based on Valve's openvr `hellovr_opengl` sample code: https://github.com/ValveSoftware/openvr/tree/master/samples\
-Still early in development, not ready to be used yet.
-
+A virtual reality video player for Linux running X11, based on Valve's openvr `hellovr_opengl` sample code: https://github.com/ValveSoftware/openvr/tree/master/samples\
+Still early in development, not very user friendly.\
+Currently only works with stereo video.\
+# How to use
+Start a video in your video player of choice (tested with mpv) and then get the x11 window id (this can be done with xwininfo) and then fullscreen the video (for best quality).
+Then launch `vr_video_player` with the x11 window id.
diff --git a/project.conf b/project.conf
index b0d7c9c..7353844 100644
--- a/project.conf
+++ b/project.conf
@@ -1,5 +1,5 @@
[package]
-name = "vr_window_manager"
+name = "vr_video_player"
type = "executable"
version = "0.1.0"
platforms = ["linux"]
diff --git a/src/main.cpp b/src/main.cpp
index f140c41..fed89cd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -193,15 +193,12 @@ private: // OpenGL bookkeeping
float m_fFarClip;
GLuint m_iTexture;
- GLuint m_arrow_texture_id;
unsigned int m_uiVertcount;
unsigned int m_arrow_vert_count;
GLuint m_glSceneVertBuffer;
- GLuint m_arrow_vert_buffer;
GLuint m_unSceneVAO;
- GLuint m_arrow_vao;
GLuint m_unCompanionWindowVAO;
GLuint m_glCompanionWindowIDVertBuffer;
GLuint m_glCompanionWindowIDIndexBuffer;
@@ -215,14 +212,11 @@ private: // OpenGL bookkeeping
glm::mat4 m_mat4eyePosLeft;
glm::mat4 m_mat4eyePosRight;
- glm::mat4 m_resetPos;
-
glm::mat4 m_mat4ProjectionCenter;
glm::mat4 m_mat4ProjectionLeft;
glm::mat4 m_mat4ProjectionRight;
glm::vec3 hmd_pos = glm::vec3(0.0f, 0.0f, 0.0f);
- glm::vec3 hmd_reset_pos = glm::vec3(0.0f, 0.0f, 0.0f);
struct VertexDataScene
{
@@ -244,6 +238,8 @@ private: // OpenGL bookkeeping
GLuint m_unRenderModelProgramID;
GLint m_nSceneMatrixLocation;
+ GLint m_nSceneTextureOffsetXLocation;
+ GLint m_nScenePositionOffsetLocation;
GLint m_nControllerMatrixLocation;
GLint m_nRenderModelMatrixLocation;
@@ -278,10 +274,6 @@ private: // X compositor
Pixmap src_window_pixmap;
GLXFBConfig *configs;
GLXPixmap glxpixmap;
-
- // Additional resources for the window manager
- SDL_Surface *arrow_surface = nullptr;
- glm::vec3 cursor_pos = glm::vec3(0.0f, 0.0f, 0.0f);
};
@@ -392,6 +384,8 @@ CMainApplication::CMainApplication( int argc, char *argv[] )
, m_unControllerVAO( 0 )
, m_unSceneVAO( 0 )
, m_nSceneMatrixLocation( -1 )
+ , m_nSceneTextureOffsetXLocation( -1 )
+ , m_nScenePositionOffsetLocation( -1 )
, m_nControllerMatrixLocation( -1 )
, m_nRenderModelMatrixLocation( -1 )
, m_iTrackedControllerCount( 0 )
@@ -573,9 +567,6 @@ bool CMainApplication::BInit()
return false;
}
- // Capture mouse inside window
- SDL_SetRelativeMouseMode(SDL_TRUE);
-
m_strDriver = "No Driver";
m_strDisplay = "No Display";
@@ -597,7 +588,6 @@ bool CMainApplication::BInit()
m_fFarClip = 30.0f;
m_iTexture = 0;
- m_arrow_texture_id = 0;
m_uiVertcount = 0;
// m_MillisecondsTimer.start(1, this);
@@ -780,8 +770,6 @@ void CMainApplication::Shutdown()
SDL_Quit();
if (x_display) {
- if(arrow_surface)
- SDL_FreeSurface(arrow_surface);
glXReleaseTexImageEXT(x_display, glxpixmap, GLX_FRONT_EXT);
glXDestroyPixmap(x_display, glxpixmap);
XFree(configs);
@@ -815,36 +803,6 @@ bool CMainApplication::HandleInput()
{
m_bShowCubes = !m_bShowCubes;
}
- } else if (sdlEvent.type == SDL_MOUSEMOTION) {
- //printf("event x: %d\n", sdlEvent.motion.xrel);
- float cursor_speed = 0.001f;
- cursor_pos.x -= ((float)sdlEvent.motion.xrel * cursor_speed);
- cursor_pos.y -= ((float)sdlEvent.motion.yrel * cursor_speed);
- cursor_pos = glm::clamp(cursor_pos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 0.0f));
- } else if(sdlEvent.type == SDL_MOUSEBUTTONDOWN) {
- printf("send fake event!\n");
- XEvent fake_event;
- memset(&fake_event, 0, sizeof(fake_event));
- fake_event.type = ButtonPress;
- fake_event.xbutton.button = Button1;
- fake_event.xbutton.root = DefaultRootWindow(x_display);
- fake_event.xbutton.window = src_window_id;
- fake_event.xbutton.x_root = 0;
- fake_event.xbutton.y_root = 0;
- fake_event.xbutton.x = cursor_pos.x * 1920;
- fake_event.xbutton.y = cursor_pos.y * 1080;
- fake_event.xbutton.state = Button1Mask;
- fake_event.xbutton.subwindow = src_window_id;
- // TODO: Find subwindow at cursor position with XQueryPoitner
- if(XSendEvent(x_display, src_window_id, True, 0xfff, &fake_event) == 0)
- printf("failed to send fake event button down!\n");
- XFlush(x_display);
-
- fake_event.type = ButtonRelease;
- fake_event.xbutton.state = Button1Mask;
- if(XSendEvent(x_display, src_window_id, True, 0xfff, &fake_event) == 0)
- printf("failed to send fake event button up!\n");
- XFlush(x_display);
}
}
@@ -874,7 +832,6 @@ bool CMainApplication::HandleInput()
m_bShowCubes = !GetDigitalActionState( m_actionHideCubes );
if(GetDigitalActionState( m_actionHideCubes )) {
//printf("reset position!\n");
- hmd_reset_pos = hmd_pos;
//printf("pos, %f, %f, %f\n", m_mat4HMDPose[0][2], m_mat4HMDPose[1][2], m_mat4HMDPose[2][2]);
//m_resetPos = m_mat4HMDPose;
}
@@ -1116,14 +1073,16 @@ bool CMainApplication::CreateAllShaders()
// Vertex Shader
"#version 410\n"
"uniform mat4 matrix;\n"
+ "uniform float texture_offset_x;\n"
+ "uniform vec3 position_offset;\n"
"layout(location = 0) in vec4 position;\n"
"layout(location = 1) in vec2 v2UVcoordsIn;\n"
"layout(location = 2) in vec3 v3NormalIn;\n"
"out vec2 v2UVcoords;\n"
"void main()\n"
"{\n"
- " v2UVcoords = v2UVcoordsIn;\n"
- " gl_Position = matrix * position;\n"
+ " v2UVcoords = v2UVcoordsIn * vec2(0.5, 1.0) + vec2(texture_offset_x, 0.0);\n"
+ " gl_Position = matrix * (position + vec4(position_offset, 0.0));\n"
"}\n",
// Fragment Shader
@@ -1143,6 +1102,18 @@ bool CMainApplication::CreateAllShaders()
dprintf( "Unable to find matrix uniform in scene shader\n" );
return false;
}
+ m_nSceneTextureOffsetXLocation = glGetUniformLocation( m_unSceneProgramID, "texture_offset_x" );
+ if( m_nSceneTextureOffsetXLocation == -1 )
+ {
+ dprintf( "Unable to find texture_offset_x uniform in scene shader\n" );
+ return false;
+ }
+ m_nScenePositionOffsetLocation = glGetUniformLocation( m_unSceneProgramID, "position_offset" );
+ if( m_nScenePositionOffsetLocation == -1 )
+ {
+ dprintf( "Unable to find position_offset uniform in scene shader\n" );
+ return false;
+ }
m_unControllerTransformProgramID = CompileGLShader(
"Controller",
@@ -1249,37 +1220,6 @@ bool CMainApplication::SetupTexturemaps()
{
GLfloat fLargest;
- //m_arrow_texture_id = SOIL_load_OGL_texture("images/arrow.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);
- int width;
- int height;
- unsigned char *image_data = SOIL_load_image("images/arrow.png", &width, &height, nullptr, SOIL_LOAD_RGBA);
- if(!image_data) {
- printf("Failed to load images/arrow.png, error: %s\n", SOIL_last_result());
- return false;
- }
-
- glGenTextures(1, &m_arrow_texture_id );
- glBindTexture( GL_TEXTURE_2D, m_arrow_texture_id );
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
- SOIL_free_image_data(image_data);
-
- glGenerateMipmap(GL_TEXTURE_2D);
-
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
-
- glBindTexture( GL_TEXTURE_2D, 0 );
-
const int pixmap_config[] = {
GLX_BIND_TO_TEXTURE_RGBA_EXT, True,
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
@@ -1342,7 +1282,7 @@ bool CMainApplication::SetupTexturemaps()
glBindTexture( GL_TEXTURE_2D, 0 );
- return ( m_iTexture != 0 && m_arrow_texture_id != 0 );
+ return ( m_iTexture != 0 );
}
@@ -1384,9 +1324,11 @@ void CMainApplication::SetupScene()
glm::mat4 matScale = glm::identity<glm::mat4>();
matScale = glm::scale(matScale, glm::vec3(m_fScale, m_fScale, m_fScale));
glm::mat4 matTransform = glm::identity<glm::mat4>();
+ /*
matTransform = glm::translate(glm::identity<glm::mat4>(),
- hmd_reset_pos + glm::vec3(-m_fScale*0.5f, -m_fScale*0.5f, 0.5f)
+ glm::vec3(-m_fScale*0.5f, -m_fScale*0.5f, 0.5f)
);
+ */
glm::mat4 mat = matScale * matTransform;
AddCubeToScene( mat, vertdataarray );
@@ -1413,58 +1355,6 @@ void CMainApplication::SetupScene()
glBindVertexArray( 0 );
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
-
-
-
- // Arrow
- glm::mat4 matScaleArrow = glm::identity<glm::mat4>();
- matScaleArrow = glm::scale(matScaleArrow, glm::vec3(m_fScale, m_fScale, m_fScale));
- glm::mat4 matTransformArrow = glm::identity<glm::mat4>();
- matTransformArrow = glm::translate(glm::identity<glm::mat4>(),
- hmd_reset_pos + glm::vec3(-m_fScale*0.5f, -m_fScale*0.5f, 0.499f)
- );
-
- glm::mat4 matArrow = matScaleArrow * matTransformArrow;
- std::vector<float> arrow_data;
- float arrow_scale = 0.02f;
- glm::vec4 v1 = matArrow * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
- glm::vec4 v2 = matArrow * glm::vec4(arrow_scale, 0.0f, 0.0f, 1.0f);
- glm::vec4 v3 = matArrow * glm::vec4(0.0f, arrow_scale, 0.0f, 1.0f);
- glm::vec4 v4 = matArrow * glm::vec4(0.0f, arrow_scale, 0.0f, 1.0f);
- glm::vec4 v5 = matArrow * glm::vec4(arrow_scale, arrow_scale, 0.0f, 1.0f);
- glm::vec4 v6 = matArrow * glm::vec4(arrow_scale, 0.0f, 0.0f, 1.0f);
- AddCubeVertex(v1.x, v1.y, v1.z, 1.0f, 1.0f, arrow_data);
- AddCubeVertex(v2.x, v2.y, v2.z, 0.0f, 1.0f, arrow_data);
- AddCubeVertex(v3.x, v3.y, v3.z, 1.0f, 0.0f, arrow_data);
-
- AddCubeVertex(v4.x, v4.y, v4.z, 1.0f, 0.0f, arrow_data);
- AddCubeVertex(v5.x, v5.y, v5.z, 0.0f, 0.0f, arrow_data);
- AddCubeVertex(v6.x, v6.y, v6.z, 0.0f, 1.0f, arrow_data);
-
- m_arrow_vert_count = arrow_data.size()/5;
-
-
- glGenVertexArrays( 1, &m_arrow_vao );
- glBindVertexArray( m_arrow_vao );
-
- glGenBuffers( 1, &m_arrow_vert_buffer );
- glBindBuffer( GL_ARRAY_BUFFER, m_arrow_vert_buffer );
- glBufferData( GL_ARRAY_BUFFER, sizeof(float) * arrow_data.size(), &arrow_data[0], GL_STATIC_DRAW);
-
- GLsizei stride_arrow = sizeof(VertexDataScene);
- uintptr_t offset_arrow = 0;
-
- glEnableVertexAttribArray( 0 );
- glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, stride_arrow , (const void *)offset_arrow);
-
- offset_arrow += sizeof(glm::vec3);
- glEnableVertexAttribArray( 1 );
- glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, stride_arrow, (const void *)offset_arrow);
-
- glBindVertexArray( 0 );
- glDisableVertexAttribArray(0);
- glDisableVertexAttribArray(1);
-
}
@@ -1497,32 +1387,22 @@ void CMainApplication::AddCubeToScene( const glm::mat4 &mat, std::vector<float>
glm::vec4 G = mat * glm::vec4( 1, 1, 1, 1 );
glm::vec4 H = mat * glm::vec4( 0, 1, 1, 1 );
- // //triangles instead of quads
- // AddCubeVertex( E.x, E.y, E.z, 0, 1, vertdata ); //Front
- // AddCubeVertex( F.x, F.y, F.z, 1, 1, vertdata );
- // AddCubeVertex( G.x, G.y, G.z, 1, 0, vertdata );
- // AddCubeVertex( G.x, G.y, G.z, 1, 0, vertdata );
- // AddCubeVertex( H.x, H.y, H.z, 0, 0, vertdata );
- // AddCubeVertex( E.x, E.y, E.z, 0, 1, vertdata );
-
- // AddCubeVertex( B.x, B.y, B.z, 0, 1, vertdata ); //Back
- // AddCubeVertex( A.x, A.y, A.z, 1, 1, vertdata );
- // AddCubeVertex( D.x, D.y, D.z, 1, 0, vertdata );
- // AddCubeVertex( D.x, D.y, D.z, 1, 0, vertdata );
- // AddCubeVertex( C.x, C.y, C.z, 0, 0, vertdata );
- // AddCubeVertex( B.x, B.y, B.z, 0, 1, vertdata );
-#if 0
+
long columns = 32;
long rows = 32;
- double angle_x = 1.0;
+ double angle_x = 3.14;
double angle_y = 3.14;
- double radius = 1.0;
double radius_depth = 1.0;
- double radius_height = 1.0;
+ double zoom = 0.5;
+ double radius_height = zoom;
+ double radius = zoom * 1.0;
for(long row = 0; row < rows-1; ++row) {
for(long column = 0; column < columns-1; ++column) {
- double offset_angle = angle_x*0.5;
+ double offset_angle = 0.0;//angle_x*0.5;
+
+ double y_sin1 = sin((double)row / (double)rows * 3.14);
+ double y_sin2 = sin((double)(row + 1) / (double)rows * 3.14);
double z1 = sin(offset_angle + (double)column / (double)columns * angle_x) * radius;
double z2 = sin(offset_angle + (double)(column + 1) / (double)columns * angle_x) * radius;
@@ -1532,6 +1412,13 @@ void CMainApplication::AddCubeToScene( const glm::mat4 &mat, std::vector<float>
double z5 = z2;
double z6 = z2;
+ z1 *= y_sin1;
+ z2 *= y_sin1;
+ z3 *= y_sin2;
+ z4 *= y_sin2;
+ z5 *= y_sin2;
+ z6 *= y_sin1;
+
double x1 = -cos(offset_angle + (double)column / (double)columns * angle_x) * radius;
double x2 = -cos(offset_angle + (double)(column + 1) / (double)columns * angle_x) * radius;
double x3 = x1;
@@ -1539,6 +1426,13 @@ void CMainApplication::AddCubeToScene( const glm::mat4 &mat, std::vector<float>
double x4 = x3;
double x5 = x2;
double x6 = x2;
+
+ x1 *= y_sin1;
+ x2 *= y_sin1;
+ x3 *= y_sin2;
+ x4 *= y_sin2;
+ x5 *= y_sin2;
+ x6 *= y_sin1;
#if 0
double y1 = cos((double)row / (double)rows * angle_y) * radius;
double y2 = y1;
@@ -1562,9 +1456,9 @@ void CMainApplication::AddCubeToScene( const glm::mat4 &mat, std::vector<float>
x5 *= sin((double)(row + 1) / (double)rows * angle_y) * radius_depth;
x6 *= sin((double)row / (double)rows * angle_y) * radius_depth;
#else
- double y1 = ((double)row / (double)rows) * radius_height;
+ double y1 = cos((double)row / (double)rows * 3.14) * radius_height;
double y2 = y1;
- double y3 = ((double)(row + 1) / (double)rows) * radius_height;
+ double y3 = cos((double)(row + 1) / (double)rows * 3.14) * radius_height;
double y4 = y3;
double y5 = y3;
@@ -1578,82 +1472,15 @@ void CMainApplication::AddCubeToScene( const glm::mat4 &mat, std::vector<float>
glm::vec4 v5 = mat * glm::vec4(x5, y5, z5, 1.0);
glm::vec4 v6 = mat * glm::vec4(x6, y6, z6, 1.0);
- AddCubeVertex(v1.x, v1.y, v1.z, 1.0 - (double)column / (double)columns, 1.0 - (double)row / (double)rows, vertdata);
- AddCubeVertex(v2.x, v2.y, v2.z, 1.0 - (double)(column + 1) / (double)columns, 1.0 - (double)row / (double)rows, vertdata);
- AddCubeVertex(v3.x, v3.y, v3.z, 1.0 - (double)column / (double)columns, 1.0 - (double)(row + 1) / (double)rows, vertdata);
-
- AddCubeVertex(v4.x, v4.y, v4.z, 1.0 - (double)column / (double)columns, 1.0 - (double)(row + 1) / (double)rows, vertdata);
- AddCubeVertex(v5.x, v5.y, v5.z, 1.0 - (double)(column + 1) / (double)columns, 1.0 - (double)(row + 1) / (double)rows, vertdata);
- AddCubeVertex(v6.x, v6.y, v6.z, 1.0 - (double)(column + 1) / (double)columns, 1.0 - (double)row / (double)rows, vertdata);
- }
- }
-#endif
+ AddCubeVertex(v1.x, v1.y, v1.z, 1.0 - (double)column / (double)columns, (double)row / (double)rows, vertdata);
+ AddCubeVertex(v2.x, v2.y, v2.z, 1.0 - (double)(column + 1) / (double)columns, (double)row / (double)rows, vertdata);
+ AddCubeVertex(v3.x, v3.y, v3.z, 1.0 - (double)column / (double)columns, (double)(row + 1) / (double)rows, vertdata);
- int columns = 32;
- int rows = 32;
- float scale_x = 1.0f;
- float scale_y = 1.0f;
-
- for(int row = 0; row < rows - 1; ++row) {
- for(int column = 0; column < columns - 1; ++column) {
- float x1 = ((float)column / (float)columns) * scale_x;
- float x2 = ((float)(column + 1) / (float)columns) * scale_x;
- float x3 = x1;
- float x4 = x3;
- float x5 = x2;
- float x6 = x2;
-
- float y1 = ((float)row / (float)rows) * scale_y;
- float y2 = y1;
- float y3 = ((float)(row + 1) / (float)rows) * scale_y;
- float y4 = y3;
- float y5 = y3;
- float y6 = y1;
-
- glm::vec4 v1 = mat * glm::vec4(x1, y1, 0.0f, 1.0);
- glm::vec4 v2 = mat * glm::vec4(x2, y2, 0.0f, 1.0);
- glm::vec4 v3 = mat * glm::vec4(x3, y3, 0.0f, 1.0);
- glm::vec4 v4 = mat * glm::vec4(x4, y4, 0.0f, 1.0);
- glm::vec4 v5 = mat * glm::vec4(x5, y5, 0.0f, 1.0);
- glm::vec4 v6 = mat * glm::vec4(x6, y6, 0.0f, 1.0);
-
- AddCubeVertex(v1.x, v1.y, v1.z, 1.0 - (float)column / (float)columns, 1.0 - (float)row / (float)rows, vertdata);
- AddCubeVertex(v2.x, v2.y, v2.z, 1.0 - (float)(column + 1) / (float)columns, 1.0 - (float)row / (float)rows, vertdata);
- AddCubeVertex(v3.x, v3.y, v3.z, 1.0 - (float)column / (float)columns, 1.0 - (float)(row + 1) / (float)rows, vertdata);
-
- AddCubeVertex(v4.x, v4.y, v4.z, 1.0 - (float)column / (float)columns, 1.0 - (float)(row + 1) / (float)rows, vertdata);
- AddCubeVertex(v5.x, v5.y, v5.z, 1.0 - (float)(column + 1) / (float)columns, 1.0 - (float)(row + 1) / (float)rows, vertdata);
- AddCubeVertex(v6.x, v6.y, v6.z, 1.0 - (float)(column + 1) / (float)columns, 1.0 - (float)row / (float)rows, vertdata);
+ AddCubeVertex(v4.x, v4.y, v4.z, 1.0 - (double)column / (double)columns, (double)(row + 1) / (double)rows, vertdata);
+ AddCubeVertex(v5.x, v5.y, v5.z, 1.0 - (double)(column + 1) / (double)columns, (double)(row + 1) / (double)rows, vertdata);
+ AddCubeVertex(v6.x, v6.y, v6.z, 1.0 - (double)(column + 1) / (double)columns, (double)row / (double)rows, vertdata);
}
}
-
- // AddCubeVertex( H.x, H.y, H.z, 0, 1, vertdata ); //Top
- // AddCubeVertex( G.x, G.y, G.z, 1, 1, vertdata );
- // AddCubeVertex( C.x, C.y, C.z, 1, 0, vertdata );
- // AddCubeVertex( C.x, C.y, C.z, 1, 0, vertdata );
- // AddCubeVertex( D.x, D.y, D.z, 0, 0, vertdata );
- // AddCubeVertex( H.x, H.y, H.z, 0, 1, vertdata );
-
- // AddCubeVertex( A.x, A.y, A.z, 0, 1, vertdata ); //Bottom
- // AddCubeVertex( B.x, B.y, B.z, 1, 1, vertdata );
- // AddCubeVertex( F.x, F.y, F.z, 1, 0, vertdata );
- // AddCubeVertex( F.x, F.y, F.z, 1, 0, vertdata );
- // AddCubeVertex( E.x, E.y, E.z, 0, 0, vertdata );
- // AddCubeVertex( A.x, A.y, A.z, 0, 1, vertdata );
-
- // AddCubeVertex( A.x, A.y, A.z, 0, 1, vertdata ); //Left
- // AddCubeVertex( E.x, E.y, E.z, 1, 1, vertdata );
- // AddCubeVertex( H.x, H.y, H.z, 1, 0, vertdata );
- // AddCubeVertex( H.x, H.y, H.z, 1, 0, vertdata );
- // AddCubeVertex( D.x, D.y, D.z, 0, 0, vertdata );
- // AddCubeVertex( A.x, A.y, A.z, 0, 1, vertdata );
-
- // AddCubeVertex( F.x, F.y, F.z, 0, 1, vertdata ); //Right
- // AddCubeVertex( B.x, B.y, B.z, 1, 1, vertdata );
- // AddCubeVertex( C.x, C.y, C.z, 1, 0, vertdata );
- // AddCubeVertex( C.x, C.y, C.z, 1, 0, vertdata );
- // AddCubeVertex( G.x, G.y, G.z, 0, 0, vertdata );
- // AddCubeVertex( F.x, F.y, F.z, 0, 1, vertdata );
}
@@ -1953,21 +1780,26 @@ void CMainApplication::RenderScene( vr::Hmd_Eye nEye )
{
glUseProgram( m_unSceneProgramID );
glUniformMatrix4fv( m_nSceneMatrixLocation, 1, GL_FALSE, glm::value_ptr(GetCurrentViewProjectionMatrix( nEye )));
+
+ if( nEye == vr::Eye_Left )
+ {
+ float offset = 0.0f;
+ glUniform1fv(m_nSceneTextureOffsetXLocation, 1, &offset);
+ }
+ else if( nEye == vr::Eye_Right )
+ {
+ float offset = 0.5f;
+ glUniform1fv(m_nSceneTextureOffsetXLocation, 1, &offset);
+ }
+
+ glUniform3fv(m_nScenePositionOffsetLocation, 1, &hmd_pos[0]);
+
glBindVertexArray( m_unSceneVAO );
glBindTexture( GL_TEXTURE_2D, m_iTexture );
glDrawArrays( GL_TRIANGLES, 0, m_uiVertcount );
glBindVertexArray( 0 );
}
- glUseProgram( m_unSceneProgramID );
- glm::mat4 arrow_mat = GetCurrentViewProjectionMatrix( nEye );
- arrow_mat = glm::translate(arrow_mat, cursor_pos);
- glUniformMatrix4fv( m_nSceneMatrixLocation, 1, GL_FALSE, glm::value_ptr(arrow_mat));
- glBindVertexArray( m_arrow_vao );
- glBindTexture( GL_TEXTURE_2D, m_arrow_texture_id );
- glDrawArrays( GL_TRIANGLES, 0, m_arrow_vert_count );
- glBindVertexArray( 0 );
-
bool bIsInputAvailable = m_pHMD->IsInputAvailable();
if( bIsInputAvailable )
@@ -2082,11 +1914,11 @@ glm::mat4 CMainApplication::GetCurrentViewProjectionMatrix( vr::Hmd_Eye nEye )
//memcpy(&m_mat4HMDPose[0], &pp[0], sizeof(pp));
if( nEye == vr::Eye_Left )
{
- matMVP = m_mat4ProjectionLeft * m_mat4eyePosLeft * glm::translate(m_mat4HMDPose, hmd_reset_pos);
+ matMVP = m_mat4ProjectionLeft * m_mat4eyePosLeft * m_mat4HMDPose;
}
else if( nEye == vr::Eye_Right )
{
- matMVP = m_mat4ProjectionRight * m_mat4eyePosRight * glm::translate(m_mat4HMDPose, hmd_reset_pos);
+ matMVP = m_mat4ProjectionRight * m_mat4eyePosRight * m_mat4HMDPose;
}
return matMVP;