From ebbb52cd0de8e27817a0770bd7bdb48a58348a02 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 13 Jan 2018 09:33:21 +0200 Subject: [PATCH] pick ray calculation (moved to gph-math and used here) --- src/app.cc | 35 +++++++++++------------------------ src/exhibit.cc | 2 -- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/app.cc b/src/app.cc index 615366a..25c59b3 100644 --- a/src/app.cc +++ b/src/app.cc @@ -26,7 +26,7 @@ static void draw_scene(); static void toggle_flight(); static void calc_framerate(); -static Ray calc_pick_ray(int x, int y, const Mat4 &view_mat, const Mat4 &proj_mat); +static Ray calc_pick_ray(int x, int y); long time_msec; int win_width, win_height; @@ -76,6 +76,8 @@ static ExSelection ex_sel; static Renderer *rend; +static Ray last_pick_ray; + bool app_init(int argc, char **argv) { @@ -128,7 +130,6 @@ bool app_init(int argc, char **argv) glEnable(GL_MULTISAMPLE); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); if(!init_debug_gui()) { @@ -348,18 +349,6 @@ static void update(float dt) } } -static void set_light(int idx, const Vec3 &pos, const Vec3 &color) -{ - unsigned int lt = GL_LIGHT0 + idx; - float posv[] = { pos.x, pos.y, pos.z, 1 }; - float colv[] = { color.x, color.y, color.z, 1 }; - - glEnable(lt); - glLightfv(lt, GL_POSITION, posv); - glLightfv(lt, GL_DIFFUSE, colv); - glLightfv(lt, GL_SPECULAR, colv); -} - void app_display() { float dt = (float)(time_msec - prev_msec) / 1000.0f; @@ -439,11 +428,6 @@ void app_display() static void draw_scene() { - static const Vec3 lpos[] = { Vec3(-50, 75, 100), Vec3(100, 0, 30), Vec3(-10, -10, 60) }; - set_light(0, lpos[0], Vec3(1.0, 0.8, 0.7) * 0.8); - set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6); - set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3); - rend->draw(); exman->draw(); @@ -483,7 +467,6 @@ static void draw_scene() glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); - glDisable(GL_LIGHTING); glEnable(GL_POLYGON_OFFSET_FILL); glUseProgram(0); @@ -625,7 +608,7 @@ void app_mouse_button(int bn, bool pressed, int x, int y) if(ex_sel.ex) { ex_sel.ex = 0; } else { - Ray ray = calc_pick_ray(x, y, view_matrix, proj_matrix); + Ray ray = calc_pick_ray(x, y); ex_sel = exman->select(ray); } } @@ -753,7 +736,7 @@ static void toggle_flight() static void calc_framerate() { - static int ncalc; + //static int ncalc; static int nframes; static long prev_upd; @@ -772,7 +755,11 @@ static void calc_framerate() } } -static Ray calc_pick_ray(int x, int y, const Mat4 &view_mat, const Mat4 &proj_mat) +static Ray calc_pick_ray(int x, int y) { - return Ray(); // TODO + float nx = (float)x / (float)win_width; + float ny = (float)(win_height - y) / (float)win_height; + + last_pick_ray = mouse_pick_ray(nx, ny, view_matrix, proj_matrix); + return last_pick_ray; } diff --git a/src/exhibit.cc b/src/exhibit.cc index c525f77..b8d44cc 100644 --- a/src/exhibit.cc +++ b/src/exhibit.cc @@ -95,8 +95,6 @@ void Exhibit::post_draw() const glPopMatrix(); const AABox &bvol = get_aabox(); - debug_log("bvol (%g %g %g) -> (%g %g %g)\n", bvol.min.x, bvol.min.y, bvol.min.z, - bvol.max.x, bvol.max.y, bvol.max.z); draw_geom_object(&bvol); } } -- 1.7.10.4