panning
authorJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 14 Aug 2018 23:56:19 +0000 (02:56 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 14 Aug 2018 23:56:19 +0000 (02:56 +0300)
src/gamescr.cc

index 06b0429..3eec738 100644 (file)
@@ -89,6 +89,8 @@ static void remove_particle(Particle *p);
 static Particle *alloc_particle();
 void free_particle(Particle *p);
 
+static bool pause;
+
 static float grid[GRID_SIZE * GRID_SIZE];
 static Particle *grid_part[GRID_SIZE * GRID_SIZE];
 static Texture *grid_tex;
@@ -107,9 +109,10 @@ static QuadMesh field_mesh;
 static Mesh *pmesh;
 static unsigned int particle_sdr;
 
+static Vec2 cam_pos;
 static float cam_theta;
 static float cam_dist = 100.0f;
-static Vec2 *targ_pos;
+static Vec2 *targ_pos = &cam_pos;
 static Mat4 view_matrix, proj_matrix;
 
 static bool wireframe;
@@ -177,6 +180,8 @@ void GameScreen::destroy()
 
 static void simstep()
 {
+       if(pause) return;
+
        // move existing particles
        Particle *p = plist;
        while(p) {
@@ -452,6 +457,10 @@ void GameScreen::keyboard(int key, bool pressed)
                        wireframe = !wireframe;
                        break;
 
+               case ' ':
+                       pause = !pause;
+                       break;
+
                default:
                        break;
                }
@@ -473,6 +482,13 @@ void GameScreen::mmotion(int x, int y)
        prev_x = x;
        prev_y = y;
 
+       if(game_bnstate(0)) {
+               float pan_speed = pow(cam_dist, 1.5) * 0.00035; // magic
+               Vec2 dir = rotate(Vec2(dx, dy) * pan_speed, deg_to_rad(cam_theta));
+               cam_pos.x -= dir.x;
+               cam_pos.y -= dir.y;
+       }
+
        if(game_bnstate(2)) {
                cam_theta += dx * 0.5;
        }