asdf

Dependencies:   mbed

Fork of manworm_ticker_tv by Bayley Wang

Revision:
11:537cde55b27f
Parent:
10:1163fb31b0a7
Child:
12:e99cc1e9d928
--- a/gfx.cpp	Sat Mar 10 06:26:01 2018 +0000
+++ b/gfx.cpp	Thu May 03 23:38:46 2018 +0000
@@ -1,7 +1,7 @@
 #define N_PTS 500
 #define N_LNS 2000
-#define N_HEIGHTS 100
-#define N_SIDE 10
+#define N_HEIGHTS 64
+#define N_SIDE 8
 
 #include "gfx.h"
 #include "mbed.h"
@@ -17,6 +17,7 @@
 point_t* pts;
 line_t* lns;
 cube_t* cubes;
+point_t temp_point;
 
 float heights[N_HEIGHTS];
 
@@ -37,6 +38,7 @@
 float x_off = 0.f;
 float y_off = 0.f;
 float pitch = 0.f;
+float yaw = 0.f;
 
 unsigned int m_z=12434,m_w=33254;
 void draw_lines();
@@ -82,7 +84,8 @@
 char* get_gfx_stat()
 {
     n_frame++;
-    sprintf(gfx_stat,"%d/%d, %d/%d, %d",n_lns,N_LNS,n_pts,N_PTS,n_frame%1000);
+    //sprintf(gfx_stat,"%d/%d, %d/%d, %d",n_lns,N_LNS,n_pts,N_PTS,n_frame%1000);
+    sprintf(gfx_stat,"%.3f/%.3f",pitch,yaw);
     return gfx_stat;
 }
 
@@ -100,15 +103,33 @@
 
 void rotate_cube(uint8_t x, uint8_t y, uint8_t z,uint8_t inv);
 
-void update_x_rot();
-void new_frame(char c)
+unsigned int PRNG()
 {
-    if(c == 'w') y_off += .01f;
-    if(c == 's') y_off -= .01f;
-    if(c == 'a') x_off += .01f;
-    if(c == 'd') x_off -= .01f;
-    if(c == 'q') pitch += .01f;
-    if(c == 'e') pitch -= .01f;
+    // our initial starting seed is 5323
+    static unsigned int nSeed = 5323;
+
+    // Take the current seed and generate a new value from it
+    // Due to our use of large constants and overflow, it would be
+    // very hard for someone to predict what the next number is
+    // going to be from the previous one.
+    nSeed = (8253729 * nSeed + 2396403); 
+
+    // Take the seed and return a value between 0 and 32767
+    return nSeed  % 32767;
+}
+
+void update_x_rot();
+void new_frame(float pitch_rate, float yaw_rate)
+{
+    pitch += pitch_rate * .05f;
+    yaw += yaw_rate * .05f;
+    //printf("yaw: %.3f \r\n",yaw);
+//    if(c == 'w') y_off += .01f;
+//    if(c == 's') y_off -= .01f;
+//    if(c == 'a') x_off += .01f;
+//    if(c == 'd') x_off -= .01f;
+//    if(c == 'q') pitch += .01f;
+//    if(c == 'e') pitch -= .01f;
     
     update_x_rot();
     draw_lines();
@@ -203,8 +224,8 @@
         {
             // base
             int pti = xi + N_SIDE*yi;
-            pts[pti].x = -.5f + ( (float) (xi) )/( (float) (N_SIDE) );
-            pts[pti].y = -.5f + ( (float) (yi) )/( (float) (N_SIDE) );
+            pts[pti].x = -.5f + .7f*( (float) (xi) )/( (float) (N_SIDE) ) + .15f;
+            pts[pti].y = -.5f + .7f*( (float) (yi) )/( (float) (N_SIDE) ) + .15f;
             // go x+?
             if(  (xi < (N_SIDE - 1)))
             {
@@ -260,6 +281,14 @@
  x_rotmat[1][2] = -sin(pitch);
  x_rotmat[2][1] = sin(pitch);
  x_rotmat[2][2] = cos(pitch);
+ 
+ y_rotmat[0][0] = cos(yaw);
+ y_rotmat[0][2] = sin(yaw);
+ y_rotmat[2][0] -sin(yaw);
+ y_rotmat[2][2] = cos(yaw);
+ //float y_rotmat[3][3] = {{cos(.03), 0, sin(.03)}, {0, 1, 0}, { -sin(.03), 0, cos(.03)}};
+ 
+ 
  //float x_rotmat[3][3] = {{1, 0, 0}, {0, cos(.02), -sin(.02)}, {0, sin(.02), cos(.02)}};
 }
  
@@ -282,13 +311,31 @@
         line_t* l = lns + i;
         point_t* a = l->a;
         point_t* b = l->b;
-        point_mult(x_rotmat,a,temp,0);
-        point_mult(x_rotmat,b,temp2,0);
+        //point_mult(x_rotmat,a,temp,0);
+        //point_mult(x_rotmat,b,temp2,0);
         bring_in_range();
-        float x1 = temp[0] + x_off;
+        
+        point_mult(x_rotmat,a,temp,0);
+        temp_point.x = temp[0];
+        temp_point.y = temp[1];
+        temp_point.z = temp[2];
+        point_mult(y_rotmat,&temp_point,temp2,0);
+        float x1 = temp2[0] + x_off;
+        float y1 = temp2[1] + y_off;
+        
+        point_mult(x_rotmat,b,temp,0);
+        temp_point.x = temp[0];
+        temp_point.y = temp[1];
+        temp_point.z = temp[2];
+        point_mult(y_rotmat,&temp_point,temp2,0);
         float x2 = temp2[0] + x_off;
-        float y1 = temp[1] + y_off;
         float y2 = temp2[1] + y_off;
+        
+        
+//        float x1 = temp[0] + x_off;
+//        float x2 = temp2[0] + x_off;
+//        float y1 = temp[1] + y_off;
+//        float y2 = temp2[1] + y_off;
 
         draw_gfx_line(x1,y1,x2,y2);
         //printf("i: %d, a: %d, b: %d\n",i,l->a,l->b);