Browse Source

Resolution independence for some examples

James Bowman 5 years ago
parent
commit
576bdd3da7
4 changed files with 21 additions and 24 deletions
  1. 11 10
      examples/cobra.ino
  2. 4 4
      examples/logo.ino
  3. 6 6
      examples/nightstrike.ino
  4. 0 4
      examples/walk.ino

+ 11 - 10
examples/cobra.ino

@@ -140,6 +140,7 @@ void project(float distance)
   const PROGMEM int8_t *pm_e = pm + sizeof(COBRA_vertices);
   xyz *dst = projected;
   int8_t x, y, z;
+  int hw = GD.w / 2;
 
   while (pm < pm_e) {
     x = pgm_read_byte_near(pm++);
@@ -148,9 +149,9 @@ void project(float distance)
     float xx = x * model_mat[0] + y * model_mat[3] + z * model_mat[6];
     float yy = x * model_mat[1] + y * model_mat[4] + z * model_mat[7];
     float zz = x * model_mat[2] + y * model_mat[5] + z * model_mat[8] + distance;
-    float q = 240 / (100 + zz);
-    dst->x = 16 * (240 + xx * q);
-    dst->y = 16 * (136 + yy * q);
+    float q = hw / (100 + zz);
+    dst->x = 16 * (hw       + xx * q);
+    dst->y = 16 * (GD.h / 2 + yy * q);
     dst->z = zz;
     dst++;
   }
@@ -357,11 +358,11 @@ void setup()
   GD.begin();
   LOAD_ASSETS();
   GD.BitmapHandle(BACKGROUND_HANDLE);
-  GD.BitmapSize(BILINEAR, REPEAT, REPEAT, 480, 272);
-#ifdef DUMPDEV    // JCB{
-  // startMotion(240, 136);
-  // trackMotion(240, 138);
-#endif          // }JCB
+  GD.BitmapSize(BILINEAR, REPEAT, REPEAT, GD.w, GD.h);
+// #ifdef DUMPDEV    // JCB{
+  startMotion(240, 136);
+  trackMotion(243, 138);
+// #endif          // }JCB
 }
 
 static byte prev_touching;
@@ -428,9 +429,9 @@ void loop()
   draw_navlight(0);
   GD.RestoreContext();
 #ifndef DUMPDEV // JCB{
-  GD.cmd_number(240, 7, 26, OPT_CENTER, micros() - t0);
+  GD.cmd_number(GD.w / 2, 7, 26, OPT_CENTER, micros() - t0);
 #else
-  GD.cmd_number(240, 7, 26, OPT_CENTER, t);
+  GD.cmd_number(GD.w / 2, 7, 26, OPT_CENTER, t);
 #endif        // }JCB
 
   GD.swap();

+ 4 - 4
examples/logo.ino

@@ -30,7 +30,7 @@ void loop()
     stars[i].set(GD.random(PIXELS(GD.w)), GD.random(PIXELS(GD.h)));
 
   for (int t = 0; t < 464; t++) {
-    GD.cmd_gradient(0, 0, 0x120000, 0, 272, 0x480000);
+    GD.cmd_gradient(0, 0, 0x120000, 0, GD.h, 0x480000);
     GD.BlendFunc(SRC_ALPHA, ONE);
     GD.Begin(POINTS);
     for (int i = 0; i < NSTARS; i++) {
@@ -85,9 +85,9 @@ void loop()
     // Fade to white at the end by drawing a white rectangle on top
     fade = clamp255(5 * (t - 400));
     GD.ColorA(fade);
-    GD.Begin(RECTS);
-    GD.Vertex2ii(0, 0, 0, 0);
-    GD.Vertex2ii(480, 272, 0, 0);
+    GD.Begin(EDGE_STRIP_R);
+    GD.Vertex2f(0, 0);
+    GD.Vertex2f(0, PIXELS(GD.h));
 
     GD.swap();
   }

+ 6 - 6
examples/nightstrike.ino

@@ -861,14 +861,14 @@ static void draw_fade(byte fade)
 
 static void welcome()
 {
-  Streamer stream;
+  // Streamer stream;
 
   GD.safeload("nightw.gd2");
   byte fade = 0;
   int t;
 
   const char song[] = "mesmeriz.ima";
-  stream.begin(song);
+  // stream.begin(song);
   byte playing = 1;
   do {
     GD.get_inputs();
@@ -890,10 +890,10 @@ static void welcome()
     draw_fade(fade);
     GD.swap();
     GD.random();
-    if (!stream.feed()) {
-      playing = 0;
-      GD.sample(0, 0, 0, 0);
-    }
+    // if (!stream.feed()) {
+    //   playing = 0;
+    //   GD.sample(0, 0, 0, 0);
+    // }
   } while (fade != 255);
   GD.sample(0, 0, 0, 0);
   // GD.play(MUTE); GD.play(UNMUTE);

+ 0 - 4
examples/walk.ino

@@ -27,7 +27,3 @@ void loop()
   }
   GD.swap();
 } //' }A
-
-/*
-    GD.Vertex2ii(x, y, WALK_HANDLE);   //' asset{ }asset
-*/