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