From 326b09773ae658e0848f4171172bbae4c600e5ca Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 25 Oct 2018 06:56:08 +0000 Subject: Added mouse look to road demo. --- xd.c | 58 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/xd.c b/xd.c index 703ca4f..29419fb 100644 --- a/xd.c +++ b/xd.c @@ -281,7 +281,7 @@ static DemoInfo demotbl[NO_DEMOS]= UsesPixmap }, { - "Road Demo (LMB toggle culling)", + "Road Demo (LMB toggle culling, RMB toggle mouselook)", RoadDemo, UsesPixmap }, @@ -4333,6 +4333,7 @@ static void RoadDemo(void) static double dxi, dyi; static int dcount; static int cull = TRUE; + static int mouselook = FALSE; int f,r; double x, y, z; @@ -4415,6 +4416,17 @@ static void RoadDemo(void) } } + if (mouse_b&Button3Mask) + { + static time_t bounce=0; + + if (bounce!=time(NULL)) + { + mouselook = !mouselook; + bounce=time(NULL); + } + } + Cls(); x = -ROAD_WIDTH / 2; @@ -4422,35 +4434,43 @@ static void RoadDemo(void) z = 10.0; max_y = height; - ang_x = atan(fabs(road[0].dy) / ROAD_Z_INC); - - if (isnan(ang_x)) + if (mouselook) { - ang_x = 0; + ang_y = -(mouse_x - centre_x); + ang_x = mouse_y - centre_y; } else { - ang_x = DEG(ang_x) * 10.0; + ang_x = atan(fabs(road[0].dy) / ROAD_Z_INC); - if (road[0].dy > 0) + if (isnan(ang_x)) { - ang_x = -ang_x; + ang_x = 0; } - } + else + { + ang_x = DEG(ang_x) * 10.0; - ang_y = atan(fabs(road[0].dx) / ROAD_Z_INC); + if (road[0].dy > 0) + { + ang_x = -ang_x; + } + } - if (isnan(ang_y)) - { - ang_y = 0; - } - else - { - ang_y = DEG(ang_y) * 10.0; + ang_y = atan(fabs(road[0].dx) / ROAD_Z_INC); - if (road[0].dx > 0) + if (isnan(ang_y)) { - ang_y = -ang_y; + ang_y = 0; + } + else + { + ang_y = DEG(ang_y) * 10.0; + + if (road[0].dx > 0) + { + ang_y = -ang_y; + } } } -- cgit v1.2.3