# HG changeset patch # User John Tsiombikas # Date 1379723753 -10800 # Node ID cceffea995a46c445bb5aa66e27ad1026b65b506 # Parent 464e1d135d6815cfd5c30cf18583131da569e1a3 implemented wasd controls and clamping of the texcoords to [0, 1] diff -r 464e1d135d68 -r cceffea995a4 sdr.glsl --- a/sdr.glsl Sat Sep 21 03:00:47 2013 +0300 +++ b/sdr.glsl Sat Sep 21 03:35:53 2013 +0300 @@ -3,20 +3,20 @@ uniform float lens_center_offset; uniform vec4 dist_factors; -vec2 distort_texcoords(in vec2 tc, out float dbgrad); +vec2 distort_texcoords(in vec2 tc); float barrel_scale(float x, in vec4 k); void main() { - float dbgrad; - vec2 tc = distort_texcoords(gl_TexCoord[0].xy, dbgrad); + vec2 tc = distort_texcoords(gl_TexCoord[0].xy); - gl_FragColor.rgb = texture2D(tex, tc).rgb; - gl_FragColor.rgb += mix(vec3(1.0, 1.0, 0.0), vec3(0.0), smoothstep(0.01, 0.05, dbgrad)); + float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0; + + gl_FragColor.rgb = texture2D(tex, tc).rgb * vis; gl_FragColor.a = 1.0; } -vec2 distort_texcoords(in vec2 tc, out float dbgrad) +vec2 distort_texcoords(in vec2 tc) { // map tc [0, 1] -> [-1, 1] vec2 pt = tc * 2.0 - 1.0; @@ -27,8 +27,7 @@ float rad = barrel_scale(dot(pt, pt), dist_factors); pt *= rad; // scale the point by the computer distortion radius - dbgrad = length(pt) * rad; - + pt /= scale; pt.y *= aspect; pt.x -= lens_center_offset * 2.0; diff -r 464e1d135d68 -r cceffea995a4 src/main.cc --- a/src/main.cc Sat Sep 21 03:00:47 2013 +0300 +++ b/src/main.cc Sat Sep 21 03:35:53 2013 +0300 @@ -138,10 +138,35 @@ vr_shutdown(); } +static void handle_input(float dt) +{ + Vector3 inpv; + float offs = dt * 2.0; + + if(keystate['w'] || keystate['W']) { + inpv.z -= offs; + } + if(keystate['s'] || keystate['S']) { + inpv.z += offs; + } + if(keystate['d'] || keystate['D']) { + inpv.x += offs; + } + if(keystate['a'] || keystate['A']) { + inpv.x -= offs; + } + + cam.input_move(inpv.x, inpv.y, inpv.z); +} + static void disp() { - unsigned int msec = glutGet(GLUT_ELAPSED_TIME); + static long prev_msec; + long msec = glutGet(GLUT_ELAPSED_TIME); + float dt = (msec - prev_msec) / 1000.0; + prev_msec = msec; + handle_input(dt); cam.track_vr(); /*glMatrixMode(GL_PROJECTION); @@ -211,7 +236,7 @@ float lpos[] = {0, 60, 0, 1}; glLightfv(GL_LIGHT0, GL_POSITION, lpos); - draw_grid(100.0, 2.5); + draw_grid(50.0, 2.5); static Vector2 teapos[] = { Vector2(-8, 8), Vector2(8, 8), Vector2(8, -8), Vector2(-8, -8) @@ -245,7 +270,7 @@ static void draw_squares() { - static const int num_sq = 4; + static const int num_sq = 8; glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); glDisable(GL_LIGHTING); @@ -255,7 +280,7 @@ glTranslatef(0, 1, 0); - glLineWidth(3.0); + glLineWidth(2.0); glColor3f(1.0, 0.7, 0.2); float zdist = 2.0; @@ -267,7 +292,7 @@ glVertex3f(-1, 1, -zdist); glEnd(); - zdist += 1.0; + zdist += 2.0; } glPopMatrix(); diff -r 464e1d135d68 -r cceffea995a4 src/vr.cc --- a/src/vr.cc Sat Sep 21 03:00:47 2013 +0300 +++ b/src/vr.cc Sat Sep 21 03:35:53 2013 +0300 @@ -107,7 +107,13 @@ vr_ctx.info.distort[i] = info.DistortionK[i]; } - vr_ctx.info.scale = 1.0; + Util::Render::StereoConfig stereohelp; + stereohelp.SetFullViewport(Util::Render::Viewport(0, 0, vr_ctx.info.width, vr_ctx.info.height)); + stereohelp.SetStereoMode(Util::Render::Stereo_LeftRight_Multipass); + stereohelp.SetHMDInfo(info); + stereohelp.SetDistortionFitPointVP(-1.0, 0.0); + + vr_ctx.info.scale = stereohelp.GetDistortionScale(); float vhalfsz = vr_ctx.info.scale * info.VScreenSize * 0.5; vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance); @@ -173,6 +179,16 @@ glGetShaderiv(sdr, GL_COMPILE_STATUS, &status); if(!status) { fprintf(stderr, "failed to compile distortion shader\n"); + + int loglen; + glGetShaderiv(sdr, GL_INFO_LOG_LENGTH, &loglen); + + if(loglen > 0) { + char *log = (char*)alloca(loglen); + glGetShaderInfoLog(sdr, loglen, &loglen, log); + fprintf(stderr, "%s\n", log); + } + return false; }