Jared DiCarlo
/
manworm_tv_gpu
asdf
Fork of manworm_ticker_tv by
gfx.cpp@9:2a47b9ff8911, 2018-03-10 (annotated)
- Committer:
- dicarloj
- Date:
- Sat Mar 10 05:09:55 2018 +0000
- Revision:
- 9:2a47b9ff8911
- Child:
- 10:1163fb31b0a7
before buffer switch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dicarloj | 9:2a47b9ff8911 | 1 | #define N_PTS 500 |
dicarloj | 9:2a47b9ff8911 | 2 | #define N_LNS 2000 |
dicarloj | 9:2a47b9ff8911 | 3 | #define N_HEIGHTS 100 |
dicarloj | 9:2a47b9ff8911 | 4 | #define N_SIDE 10 |
dicarloj | 9:2a47b9ff8911 | 5 | |
dicarloj | 9:2a47b9ff8911 | 6 | #include "gfx.h" |
dicarloj | 9:2a47b9ff8911 | 7 | #include "mbed.h" |
dicarloj | 9:2a47b9ff8911 | 8 | #include "main.h" |
dicarloj | 9:2a47b9ff8911 | 9 | |
dicarloj | 9:2a47b9ff8911 | 10 | int n_pts = 0; |
dicarloj | 9:2a47b9ff8911 | 11 | int n_lns = 0; |
dicarloj | 9:2a47b9ff8911 | 12 | int n_frame = 0; |
dicarloj | 9:2a47b9ff8911 | 13 | int n_cubes = 0; |
dicarloj | 9:2a47b9ff8911 | 14 | |
dicarloj | 9:2a47b9ff8911 | 15 | char gfx_stat[40]; |
dicarloj | 9:2a47b9ff8911 | 16 | |
dicarloj | 9:2a47b9ff8911 | 17 | point_t* pts; |
dicarloj | 9:2a47b9ff8911 | 18 | line_t* lns; |
dicarloj | 9:2a47b9ff8911 | 19 | cube_t* cubes; |
dicarloj | 9:2a47b9ff8911 | 20 | |
dicarloj | 9:2a47b9ff8911 | 21 | float heights[N_HEIGHTS]; |
dicarloj | 9:2a47b9ff8911 | 22 | |
dicarloj | 9:2a47b9ff8911 | 23 | float c_i[3] = {-.1, -.1, -.1}; |
dicarloj | 9:2a47b9ff8911 | 24 | float c1i[3] = {.1, -.1, -.1}; |
dicarloj | 9:2a47b9ff8911 | 25 | float c2i[3] = {-.1, .1, -.1}; |
dicarloj | 9:2a47b9ff8911 | 26 | float c3i[3] = {-.1, -.1, .1}; |
dicarloj | 9:2a47b9ff8911 | 27 | float c_j[3] = {.1, .1, .1}; |
dicarloj | 9:2a47b9ff8911 | 28 | float c1j[3] = {.1, .1, -.1}; |
dicarloj | 9:2a47b9ff8911 | 29 | float c2j[3] = {-.1, .1, .1}; |
dicarloj | 9:2a47b9ff8911 | 30 | float c3j[3] = {.1, -.1, .1}; |
dicarloj | 9:2a47b9ff8911 | 31 | float x_rotmat[3][3] = {{1, 0, 0}, {0, cos(.02), -sin(.02)}, {0, sin(.02), cos(.02)}}; |
dicarloj | 9:2a47b9ff8911 | 32 | float y_rotmat[3][3] = {{cos(.02), 0, sin(.02)}, {0, 1, 0}, { -sin(.02), 0, cos(.02)}}; |
dicarloj | 9:2a47b9ff8911 | 33 | float z_rotmat[3][3] = {{cos(.02), -sin(.02), 0}, {sin(.02), cos(.02), 0}, {0, 0, 1}}; |
dicarloj | 9:2a47b9ff8911 | 34 | float temp[3] = {0, 0, 0}; |
dicarloj | 9:2a47b9ff8911 | 35 | float temp2[3] = {0, 0, 0}; |
dicarloj | 9:2a47b9ff8911 | 36 | |
dicarloj | 9:2a47b9ff8911 | 37 | unsigned int m_z=12434,m_w=33254; |
dicarloj | 9:2a47b9ff8911 | 38 | void draw_lines(); |
dicarloj | 9:2a47b9ff8911 | 39 | |
dicarloj | 9:2a47b9ff8911 | 40 | unsigned int rnd() { |
dicarloj | 9:2a47b9ff8911 | 41 | m_z = 36969 * (m_z & 65535) + (m_z >>16); |
dicarloj | 9:2a47b9ff8911 | 42 | m_w = 18000 * (m_w & 65535) + (m_w >>16); |
dicarloj | 9:2a47b9ff8911 | 43 | return ((m_z <<16) + m_w); |
dicarloj | 9:2a47b9ff8911 | 44 | } |
dicarloj | 9:2a47b9ff8911 | 45 | |
dicarloj | 9:2a47b9ff8911 | 46 | |
dicarloj | 9:2a47b9ff8911 | 47 | |
dicarloj | 9:2a47b9ff8911 | 48 | void mat_vec_mult(float a[][3], float *b, float *c, uint8_t inv) { |
dicarloj | 9:2a47b9ff8911 | 49 | for (int i = 0; i < 3; i++) { |
dicarloj | 9:2a47b9ff8911 | 50 | if(inv) |
dicarloj | 9:2a47b9ff8911 | 51 | c[i] = (a[0][i] * b[0] + a[1][i] * b[1] + a[2][i] * b[2]); |
dicarloj | 9:2a47b9ff8911 | 52 | else |
dicarloj | 9:2a47b9ff8911 | 53 | c[i] = (a[i][0] * b[0] + a[i][1] * b[1] + a[i][2] * b[2]); |
dicarloj | 9:2a47b9ff8911 | 54 | } |
dicarloj | 9:2a47b9ff8911 | 55 | } |
dicarloj | 9:2a47b9ff8911 | 56 | |
dicarloj | 9:2a47b9ff8911 | 57 | void point_mult(float a[][3], point_t* b, float* c, uint8_t inv) |
dicarloj | 9:2a47b9ff8911 | 58 | { |
dicarloj | 9:2a47b9ff8911 | 59 | for (int i = 0; i < 3; i++) { |
dicarloj | 9:2a47b9ff8911 | 60 | if(inv) |
dicarloj | 9:2a47b9ff8911 | 61 | { |
dicarloj | 9:2a47b9ff8911 | 62 | c[i] = (a[0][i] * b->x + a[1][i] * b->y + a[2][i] * b->z); |
dicarloj | 9:2a47b9ff8911 | 63 | } |
dicarloj | 9:2a47b9ff8911 | 64 | else |
dicarloj | 9:2a47b9ff8911 | 65 | { |
dicarloj | 9:2a47b9ff8911 | 66 | c[i] = (a[i][0] * b->x + a[i][1] * b->y + a[i][2] * b->z); |
dicarloj | 9:2a47b9ff8911 | 67 | } |
dicarloj | 9:2a47b9ff8911 | 68 | } |
dicarloj | 9:2a47b9ff8911 | 69 | } |
dicarloj | 9:2a47b9ff8911 | 70 | |
dicarloj | 9:2a47b9ff8911 | 71 | |
dicarloj | 9:2a47b9ff8911 | 72 | |
dicarloj | 9:2a47b9ff8911 | 73 | void add_cube() |
dicarloj | 9:2a47b9ff8911 | 74 | { |
dicarloj | 9:2a47b9ff8911 | 75 | |
dicarloj | 9:2a47b9ff8911 | 76 | } |
dicarloj | 9:2a47b9ff8911 | 77 | |
dicarloj | 9:2a47b9ff8911 | 78 | char* get_gfx_stat() |
dicarloj | 9:2a47b9ff8911 | 79 | { |
dicarloj | 9:2a47b9ff8911 | 80 | n_frame++; |
dicarloj | 9:2a47b9ff8911 | 81 | sprintf(gfx_stat,"%d/%d, %d/%d, %d",n_lns,N_LNS,n_pts,N_PTS,n_frame%1000); |
dicarloj | 9:2a47b9ff8911 | 82 | return gfx_stat; |
dicarloj | 9:2a47b9ff8911 | 83 | } |
dicarloj | 9:2a47b9ff8911 | 84 | |
dicarloj | 9:2a47b9ff8911 | 85 | point_t* new_point() |
dicarloj | 9:2a47b9ff8911 | 86 | { |
dicarloj | 9:2a47b9ff8911 | 87 | if(n_pts >= N_PTS - 1) return NULL; |
dicarloj | 9:2a47b9ff8911 | 88 | return &pts[n_pts++]; |
dicarloj | 9:2a47b9ff8911 | 89 | } |
dicarloj | 9:2a47b9ff8911 | 90 | |
dicarloj | 9:2a47b9ff8911 | 91 | line_t* new_linet() |
dicarloj | 9:2a47b9ff8911 | 92 | { |
dicarloj | 9:2a47b9ff8911 | 93 | if(n_lns >= N_LNS - 1) return NULL; |
dicarloj | 9:2a47b9ff8911 | 94 | return &lns[n_lns++]; |
dicarloj | 9:2a47b9ff8911 | 95 | } |
dicarloj | 9:2a47b9ff8911 | 96 | |
dicarloj | 9:2a47b9ff8911 | 97 | void rotate_cube(uint8_t x, uint8_t y, uint8_t z,uint8_t inv); |
dicarloj | 9:2a47b9ff8911 | 98 | |
dicarloj | 9:2a47b9ff8911 | 99 | |
dicarloj | 9:2a47b9ff8911 | 100 | void new_frame(char c) |
dicarloj | 9:2a47b9ff8911 | 101 | { |
dicarloj | 9:2a47b9ff8911 | 102 | draw_lines(); |
dicarloj | 9:2a47b9ff8911 | 103 | if(c == 'w') |
dicarloj | 9:2a47b9ff8911 | 104 | rotate_cube(1,0,0,0); |
dicarloj | 9:2a47b9ff8911 | 105 | if(c == 's') |
dicarloj | 9:2a47b9ff8911 | 106 | rotate_cube(1,0,0,1); |
dicarloj | 9:2a47b9ff8911 | 107 | if(c == 'a') |
dicarloj | 9:2a47b9ff8911 | 108 | rotate_cube(0,1,0,0); |
dicarloj | 9:2a47b9ff8911 | 109 | if(c == 'd') |
dicarloj | 9:2a47b9ff8911 | 110 | rotate_cube(0,1,0,1); |
dicarloj | 9:2a47b9ff8911 | 111 | if(c == 'q') |
dicarloj | 9:2a47b9ff8911 | 112 | rotate_cube(0,0,1,0); |
dicarloj | 9:2a47b9ff8911 | 113 | if(c == 'e') |
dicarloj | 9:2a47b9ff8911 | 114 | rotate_cube(0,0,1,1); |
dicarloj | 9:2a47b9ff8911 | 115 | else |
dicarloj | 9:2a47b9ff8911 | 116 | rotate_cube(1,0,0,1); |
dicarloj | 9:2a47b9ff8911 | 117 | draw_gfx_line(c_i[0],c_i[1],c1i[0],c1i[1]); |
dicarloj | 9:2a47b9ff8911 | 118 | draw_gfx_line(c_i[0],c_i[1],c2i[0],c2i[1]); |
dicarloj | 9:2a47b9ff8911 | 119 | draw_gfx_line(c_i[0],c_i[1],c3i[0],c3i[1]); |
dicarloj | 9:2a47b9ff8911 | 120 | |
dicarloj | 9:2a47b9ff8911 | 121 | draw_gfx_line(c_j[0],c_j[1],c1j[0],c1j[1]); |
dicarloj | 9:2a47b9ff8911 | 122 | draw_gfx_line(c_j[0],c_j[1],c2j[0],c2j[1]); |
dicarloj | 9:2a47b9ff8911 | 123 | draw_gfx_line(c_j[0],c_j[1],c3j[0],c3j[1]); |
dicarloj | 9:2a47b9ff8911 | 124 | |
dicarloj | 9:2a47b9ff8911 | 125 | draw_gfx_line(c3i[0],c3i[1],c3j[0],c3j[1]); |
dicarloj | 9:2a47b9ff8911 | 126 | draw_gfx_line(c3i[0],c3i[1],c2j[0],c2j[1]); |
dicarloj | 9:2a47b9ff8911 | 127 | |
dicarloj | 9:2a47b9ff8911 | 128 | draw_gfx_line(c1i[0],c1i[1],c1j[0],c1j[1]); |
dicarloj | 9:2a47b9ff8911 | 129 | draw_gfx_line(c1i[0],c1i[1],c3j[0],c3j[1]); |
dicarloj | 9:2a47b9ff8911 | 130 | |
dicarloj | 9:2a47b9ff8911 | 131 | draw_gfx_line(c2i[0],c2i[1],c2j[0],c2j[1]); |
dicarloj | 9:2a47b9ff8911 | 132 | draw_gfx_line(c2i[0],c2i[1],c1j[0],c1j[1]); |
dicarloj | 9:2a47b9ff8911 | 133 | } |
dicarloj | 9:2a47b9ff8911 | 134 | |
dicarloj | 9:2a47b9ff8911 | 135 | void rotate_cube(uint8_t x, uint8_t y, uint8_t z, uint8_t inv) |
dicarloj | 9:2a47b9ff8911 | 136 | { |
dicarloj | 9:2a47b9ff8911 | 137 | if (x) { |
dicarloj | 9:2a47b9ff8911 | 138 | //multiply the cube point by the rotation matrix and store the array in temp |
dicarloj | 9:2a47b9ff8911 | 139 | mat_vec_mult(x_rotmat, c_i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 140 | //copy temp vector into point vector, updating it. |
dicarloj | 9:2a47b9ff8911 | 141 | memcpy(c_i, temp, sizeof(c_i)); |
dicarloj | 9:2a47b9ff8911 | 142 | mat_vec_mult(x_rotmat, c1i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 143 | memcpy(c1i, temp, sizeof(c1i)); |
dicarloj | 9:2a47b9ff8911 | 144 | mat_vec_mult(x_rotmat, c2i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 145 | memcpy(c2i, temp, sizeof(c2i)); |
dicarloj | 9:2a47b9ff8911 | 146 | mat_vec_mult(x_rotmat, c3i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 147 | memcpy(c3i, temp, sizeof(c3i)); |
dicarloj | 9:2a47b9ff8911 | 148 | mat_vec_mult(x_rotmat, c_j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 149 | memcpy(c_j, temp, sizeof(c_j)); |
dicarloj | 9:2a47b9ff8911 | 150 | mat_vec_mult(x_rotmat, c1j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 151 | memcpy(c1j, temp, sizeof(c1j)); |
dicarloj | 9:2a47b9ff8911 | 152 | mat_vec_mult(x_rotmat, c2j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 153 | memcpy(c2j, temp, sizeof(c2j)); |
dicarloj | 9:2a47b9ff8911 | 154 | mat_vec_mult(x_rotmat, c3j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 155 | memcpy(c3j, temp, sizeof(c3j)); |
dicarloj | 9:2a47b9ff8911 | 156 | } |
dicarloj | 9:2a47b9ff8911 | 157 | if (y) { |
dicarloj | 9:2a47b9ff8911 | 158 | |
dicarloj | 9:2a47b9ff8911 | 159 | mat_vec_mult(y_rotmat, c_i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 160 | memcpy(c_i, temp, sizeof(c_i)); |
dicarloj | 9:2a47b9ff8911 | 161 | mat_vec_mult(y_rotmat, c1i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 162 | memcpy(c1i, temp, sizeof(c1i)); |
dicarloj | 9:2a47b9ff8911 | 163 | mat_vec_mult(y_rotmat, c2i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 164 | memcpy(c2i, temp, sizeof(c2i)); |
dicarloj | 9:2a47b9ff8911 | 165 | mat_vec_mult(y_rotmat, c3i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 166 | memcpy(c3i, temp, sizeof(c3i)); |
dicarloj | 9:2a47b9ff8911 | 167 | mat_vec_mult(y_rotmat, c_j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 168 | memcpy(c_j, temp, sizeof(c_j)); |
dicarloj | 9:2a47b9ff8911 | 169 | mat_vec_mult(y_rotmat, c1j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 170 | memcpy(c1j, temp, sizeof(c1j)); |
dicarloj | 9:2a47b9ff8911 | 171 | mat_vec_mult(y_rotmat, c2j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 172 | memcpy(c2j, temp, sizeof(c2j)); |
dicarloj | 9:2a47b9ff8911 | 173 | mat_vec_mult(y_rotmat, c3j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 174 | memcpy(c3j, temp, sizeof(c3j)); |
dicarloj | 9:2a47b9ff8911 | 175 | } |
dicarloj | 9:2a47b9ff8911 | 176 | // |
dicarloj | 9:2a47b9ff8911 | 177 | if (z) { |
dicarloj | 9:2a47b9ff8911 | 178 | mat_vec_mult(z_rotmat, c_i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 179 | memcpy(c_i, temp, sizeof(c_i)); |
dicarloj | 9:2a47b9ff8911 | 180 | mat_vec_mult(z_rotmat, c1i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 181 | memcpy(c1i, temp, sizeof(c1i)); |
dicarloj | 9:2a47b9ff8911 | 182 | mat_vec_mult(z_rotmat, c2i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 183 | memcpy(c2i, temp, sizeof(c2i)); |
dicarloj | 9:2a47b9ff8911 | 184 | mat_vec_mult(z_rotmat, c3i, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 185 | memcpy(c3i, temp, sizeof(c3i)); |
dicarloj | 9:2a47b9ff8911 | 186 | mat_vec_mult(z_rotmat, c_j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 187 | memcpy(c_j, temp, sizeof(c_j)); |
dicarloj | 9:2a47b9ff8911 | 188 | mat_vec_mult(z_rotmat, c1j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 189 | memcpy(c1j, temp, sizeof(c1j)); |
dicarloj | 9:2a47b9ff8911 | 190 | mat_vec_mult(z_rotmat, c2j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 191 | memcpy(c2j, temp, sizeof(c2j)); |
dicarloj | 9:2a47b9ff8911 | 192 | mat_vec_mult(z_rotmat, c3j, temp,inv); |
dicarloj | 9:2a47b9ff8911 | 193 | memcpy(c3j, temp, sizeof(c3j)); |
dicarloj | 9:2a47b9ff8911 | 194 | } |
dicarloj | 9:2a47b9ff8911 | 195 | } |
dicarloj | 9:2a47b9ff8911 | 196 | |
dicarloj | 9:2a47b9ff8911 | 197 | void init_gfx() |
dicarloj | 9:2a47b9ff8911 | 198 | { |
dicarloj | 9:2a47b9ff8911 | 199 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 200 | draw_vincent_string("GFX START!"); |
dicarloj | 9:2a47b9ff8911 | 201 | pts = (point_t*)malloc(N_PTS * sizeof(point_t)); |
dicarloj | 9:2a47b9ff8911 | 202 | lns = (line_t*)malloc(N_LNS * sizeof(line_t)); |
dicarloj | 9:2a47b9ff8911 | 203 | cubes = (cube_t*)malloc(10 * sizeof(cube_t)); |
dicarloj | 9:2a47b9ff8911 | 204 | |
dicarloj | 9:2a47b9ff8911 | 205 | for(int i = 0; i < N_HEIGHTS; i++) |
dicarloj | 9:2a47b9ff8911 | 206 | { |
dicarloj | 9:2a47b9ff8911 | 207 | uint32_t a = rnd(); |
dicarloj | 9:2a47b9ff8911 | 208 | heights[i] = .2f * (float)a / (float)INT_MAX; |
dicarloj | 9:2a47b9ff8911 | 209 | new_point(); |
dicarloj | 9:2a47b9ff8911 | 210 | pts[i].z = heights[i]; |
dicarloj | 9:2a47b9ff8911 | 211 | pts[i].y = 0.001f; |
dicarloj | 9:2a47b9ff8911 | 212 | pts[i].x = 0.001f; |
dicarloj | 9:2a47b9ff8911 | 213 | //sprintf("%f\n",heights[i]); |
dicarloj | 9:2a47b9ff8911 | 214 | } |
dicarloj | 9:2a47b9ff8911 | 215 | |
dicarloj | 9:2a47b9ff8911 | 216 | |
dicarloj | 9:2a47b9ff8911 | 217 | for(int xi = 0; xi < N_SIDE; xi++) |
dicarloj | 9:2a47b9ff8911 | 218 | { |
dicarloj | 9:2a47b9ff8911 | 219 | for(int yi = 0; yi < N_SIDE; yi++) |
dicarloj | 9:2a47b9ff8911 | 220 | { |
dicarloj | 9:2a47b9ff8911 | 221 | // base |
dicarloj | 9:2a47b9ff8911 | 222 | int pti = xi + N_SIDE*yi; |
dicarloj | 9:2a47b9ff8911 | 223 | pts[pti].x = -.5f + ( (float) (xi) )/( (float) (N_SIDE) ); |
dicarloj | 9:2a47b9ff8911 | 224 | pts[pti].y = -.5f + ( (float) (yi) )/( (float) (N_SIDE) ); |
dicarloj | 9:2a47b9ff8911 | 225 | // go x+? |
dicarloj | 9:2a47b9ff8911 | 226 | if( (xi < (N_SIDE - 1))) |
dicarloj | 9:2a47b9ff8911 | 227 | { |
dicarloj | 9:2a47b9ff8911 | 228 | int ptn = (xi+1) + N_SIDE*yi; |
dicarloj | 9:2a47b9ff8911 | 229 | line_t* lin = new_linet(); |
dicarloj | 9:2a47b9ff8911 | 230 | lin->a = pts + pti; |
dicarloj | 9:2a47b9ff8911 | 231 | lin->b = pts + ptn; |
dicarloj | 9:2a47b9ff8911 | 232 | } |
dicarloj | 9:2a47b9ff8911 | 233 | // go x-? |
dicarloj | 9:2a47b9ff8911 | 234 | if( (xi > 0)) |
dicarloj | 9:2a47b9ff8911 | 235 | { |
dicarloj | 9:2a47b9ff8911 | 236 | int ptn = (xi-1) + N_SIDE*yi; |
dicarloj | 9:2a47b9ff8911 | 237 | line_t* lin = new_linet(); |
dicarloj | 9:2a47b9ff8911 | 238 | lin->a = pts + pti; |
dicarloj | 9:2a47b9ff8911 | 239 | lin->b = pts + ptn; |
dicarloj | 9:2a47b9ff8911 | 240 | } |
dicarloj | 9:2a47b9ff8911 | 241 | |
dicarloj | 9:2a47b9ff8911 | 242 | // go y+ |
dicarloj | 9:2a47b9ff8911 | 243 | if( (yi < (N_SIDE - 1))) |
dicarloj | 9:2a47b9ff8911 | 244 | { |
dicarloj | 9:2a47b9ff8911 | 245 | int ptn = (xi) + N_SIDE*(1+yi); |
dicarloj | 9:2a47b9ff8911 | 246 | line_t* lin = new_linet(); |
dicarloj | 9:2a47b9ff8911 | 247 | lin->a = pts + pti; |
dicarloj | 9:2a47b9ff8911 | 248 | lin->b = pts + ptn; |
dicarloj | 9:2a47b9ff8911 | 249 | } |
dicarloj | 9:2a47b9ff8911 | 250 | |
dicarloj | 9:2a47b9ff8911 | 251 | // go y-? |
dicarloj | 9:2a47b9ff8911 | 252 | if( (yi > 0)) |
dicarloj | 9:2a47b9ff8911 | 253 | { |
dicarloj | 9:2a47b9ff8911 | 254 | int ptn = (xi) + N_SIDE*(yi - 1); |
dicarloj | 9:2a47b9ff8911 | 255 | line_t* lin = new_linet(); |
dicarloj | 9:2a47b9ff8911 | 256 | lin->a = pts + pti; |
dicarloj | 9:2a47b9ff8911 | 257 | lin->b = pts + ptn; |
dicarloj | 9:2a47b9ff8911 | 258 | } |
dicarloj | 9:2a47b9ff8911 | 259 | |
dicarloj | 9:2a47b9ff8911 | 260 | |
dicarloj | 9:2a47b9ff8911 | 261 | } |
dicarloj | 9:2a47b9ff8911 | 262 | } |
dicarloj | 9:2a47b9ff8911 | 263 | } |
dicarloj | 9:2a47b9ff8911 | 264 | |
dicarloj | 9:2a47b9ff8911 | 265 | void draw_lines() |
dicarloj | 9:2a47b9ff8911 | 266 | { |
dicarloj | 9:2a47b9ff8911 | 267 | for(int i = 0; i < n_pts; i++) |
dicarloj | 9:2a47b9ff8911 | 268 | { |
dicarloj | 9:2a47b9ff8911 | 269 | point_mult(x_rotmat,pts + i,temp,0); |
dicarloj | 9:2a47b9ff8911 | 270 | pts[i].x = temp[0]; |
dicarloj | 9:2a47b9ff8911 | 271 | pts[i].y = temp[1]; |
dicarloj | 9:2a47b9ff8911 | 272 | pts[i].z = temp[2]; |
dicarloj | 9:2a47b9ff8911 | 273 | point_mult(y_rotmat,pts + i,temp,0); |
dicarloj | 9:2a47b9ff8911 | 274 | pts[i].x = temp[0]; |
dicarloj | 9:2a47b9ff8911 | 275 | pts[i].y = temp[1]; |
dicarloj | 9:2a47b9ff8911 | 276 | pts[i].z = temp[2]; |
dicarloj | 9:2a47b9ff8911 | 277 | } |
dicarloj | 9:2a47b9ff8911 | 278 | |
dicarloj | 9:2a47b9ff8911 | 279 | for(int i = 0; i < n_lns; i++) |
dicarloj | 9:2a47b9ff8911 | 280 | { |
dicarloj | 9:2a47b9ff8911 | 281 | line_t* l = lns + i; |
dicarloj | 9:2a47b9ff8911 | 282 | //printf("i: %d, a: %d, b: %d\n",i,l->a,l->b); |
dicarloj | 9:2a47b9ff8911 | 283 | //printf("%.3f, %.3f, %.3f, %.3f\n",l->a->x,l->a->y,l->b->x,l->b->y); |
dicarloj | 9:2a47b9ff8911 | 284 | draw_gfx_line(l->a->x,l->a->y,l->b->x,l->b->y); |
dicarloj | 9:2a47b9ff8911 | 285 | |
dicarloj | 9:2a47b9ff8911 | 286 | } |
dicarloj | 9:2a47b9ff8911 | 287 | } |