Jared DiCarlo
/
manworm_tv_gpu
asdf
Fork of manworm_ticker_tv by
Diff: gfx.cpp
- Revision:
- 10:1163fb31b0a7
- Parent:
- 9:2a47b9ff8911
- Child:
- 11:537cde55b27f
diff -r 2a47b9ff8911 -r 1163fb31b0a7 gfx.cpp --- a/gfx.cpp Sat Mar 10 05:09:55 2018 +0000 +++ b/gfx.cpp Sat Mar 10 06:26:01 2018 +0000 @@ -29,11 +29,15 @@ float c2j[3] = {-.1, .1, .1}; float c3j[3] = {.1, -.1, .1}; float x_rotmat[3][3] = {{1, 0, 0}, {0, cos(.02), -sin(.02)}, {0, sin(.02), cos(.02)}}; -float y_rotmat[3][3] = {{cos(.02), 0, sin(.02)}, {0, 1, 0}, { -sin(.02), 0, cos(.02)}}; +float y_rotmat[3][3] = {{cos(.03), 0, sin(.03)}, {0, 1, 0}, { -sin(.03), 0, cos(.03)}}; float z_rotmat[3][3] = {{cos(.02), -sin(.02), 0}, {sin(.02), cos(.02), 0}, {0, 0, 1}}; float temp[3] = {0, 0, 0}; float temp2[3] = {0, 0, 0}; +float x_off = 0.f; +float y_off = 0.f; +float pitch = 0.f; + unsigned int m_z=12434,m_w=33254; void draw_lines(); @@ -96,40 +100,19 @@ void rotate_cube(uint8_t x, uint8_t y, uint8_t z,uint8_t inv); - +void update_x_rot(); void new_frame(char c) { + 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(); - if(c == 'w') - rotate_cube(1,0,0,0); - if(c == 's') - rotate_cube(1,0,0,1); - if(c == 'a') - rotate_cube(0,1,0,0); - if(c == 'd') - rotate_cube(0,1,0,1); - if(c == 'q') - rotate_cube(0,0,1,0); - if(c == 'e') - rotate_cube(0,0,1,1); - else - rotate_cube(1,0,0,1); - draw_gfx_line(c_i[0],c_i[1],c1i[0],c1i[1]); - draw_gfx_line(c_i[0],c_i[1],c2i[0],c2i[1]); - draw_gfx_line(c_i[0],c_i[1],c3i[0],c3i[1]); - - draw_gfx_line(c_j[0],c_j[1],c1j[0],c1j[1]); - draw_gfx_line(c_j[0],c_j[1],c2j[0],c2j[1]); - draw_gfx_line(c_j[0],c_j[1],c3j[0],c3j[1]); - - draw_gfx_line(c3i[0],c3i[1],c3j[0],c3j[1]); - draw_gfx_line(c3i[0],c3i[1],c2j[0],c2j[1]); - - draw_gfx_line(c1i[0],c1i[1],c1j[0],c1j[1]); - draw_gfx_line(c1i[0],c1i[1],c3j[0],c3j[1]); - - draw_gfx_line(c2i[0],c2i[1],c2j[0],c2j[1]); - draw_gfx_line(c2i[0],c2i[1],c1j[0],c1j[1]); + } void rotate_cube(uint8_t x, uint8_t y, uint8_t z, uint8_t inv) @@ -262,26 +245,55 @@ } } +void bring_in_range() +{ + while(x_off > .5f) x_off = x_off - .25f; + while(x_off < -.5f) x_off = x_off + .25f; + while(y_off > .5f) y_off = y_off - .25f; + while(y_off < -.5f) y_off = y_off + .25f; + +} + +void update_x_rot() +{ + x_rotmat[1][1] = cos(pitch); + x_rotmat[1][2] = -sin(pitch); + x_rotmat[2][1] = sin(pitch); + x_rotmat[2][2] = cos(pitch); + //float x_rotmat[3][3] = {{1, 0, 0}, {0, cos(.02), -sin(.02)}, {0, sin(.02), cos(.02)}}; +} + void draw_lines() { - for(int i = 0; i < n_pts; i++) - { - point_mult(x_rotmat,pts + i,temp,0); - pts[i].x = temp[0]; - pts[i].y = temp[1]; - pts[i].z = temp[2]; - point_mult(y_rotmat,pts + i,temp,0); - pts[i].x = temp[0]; - pts[i].y = temp[1]; - pts[i].z = temp[2]; - } +// for(int i = 0; i < n_pts; i++) +// { +// point_mult(x_rotmat,pts + i,temp,0); +// pts[i].x = temp[0]; +// pts[i].y = temp[1]; +// pts[i].z = temp[2]; +// point_mult(y_rotmat,pts + i,temp,0); +// pts[i].x = temp[0]; +// pts[i].y = temp[1]; +// pts[i].z = temp[2]; +// } for(int i = 0; i < n_lns; i++) { 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); + bring_in_range(); + 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); //printf("%.3f, %.3f, %.3f, %.3f\n",l->a->x,l->a->y,l->b->x,l->b->y); - draw_gfx_line(l->a->x,l->a->y,l->b->x,l->b->y); + //draw_gfx_line(l->a->x,l->a->y,l->b->x,l->b->y); } } \ No newline at end of file