diff options
Diffstat (limited to '3de.c')
-rw-r--r-- | 3de.c | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -3,6 +3,7 @@ #include "memory.h" #include "plat.h" #include "render.h" +#include "tile.h" #include "torus.h" #include <stdio.h> @@ -16,37 +17,49 @@ void draw_spinny(Renderer* r, Colour c) { a += 20; } -void draw_torus(Renderer* r, Colour c) { +void draw_torus(Renderer* r) { static int a = 0; + Bitmap tex = { (Colour*)tile_pixels, 16, 16 }; const int pc = sizeof torus_points / sizeof *torus_points; int asp = (r->clip.w << fbits) / r->clip.h; int p[4 * 3] = { 0, 0, 5 << fbits, f1, 0, 0, 0, f1, 0, 0, 0, f1 }, * wp; + int v[8 * 3]; int i, j; mtx_push_trans(p); mtx_push_rot_x(a); mtx_push_rot_y(a); mtx_push_rot_z(a); - for (i = 0; i < pc; i += 9) { + for (i = 0; i < pc; i += 3 * 5) { for (j = 0; j < 3; j++) { wp = &p[j * 4]; - vec_cpy(wp, &torus_points[i + j * 3], 3); + vec_cpy(wp, &torus_points[i + j * 5], 3); mtx_apply(mtx_peek(), wp); persp(wp, asp); ndc2clip((int*)&r->clip, wp); } - ren_tri(r, c, &p[0], &p[4], &p[8], tri_mode_flat); + for (j = 0; j < 3; j++) { + int j8 = j * 8; + vec_cpy(&v[j8], &p[j * 4], 3); + v[j8 + 3] = torus_points[i + j * 5]; + v[j8 + 4] = torus_points[i + j * 5 + 1]; + v[j8 + 5] = f1; + v[j8 + 6] = f1; + v[j8 + 7] = f1; + } + ren_tri(r, &v[0], &v[8], &v[16], &tex); } mtx_popn(4); a += 3; } -void draw_tri(Renderer* r, Colour c, int x, int y) { - int v0[] = { 100, 100 }; - int v1[] = { 0, 0 }; - int v2[] = { 150, 300 }; +void draw_tri(Renderer* r, int x, int y) { + Bitmap t = { (Colour*)tile_pixels, 16, 16 }; + int v0[] = { 100, 100, 0, 0, 0, f1, 0, 0 }; + int v1[] = { 200, 200, 0, f1, f1/2, 0, f1, 0 }; + int v2[] = { 150, 300, 0, 0, f1, 0, 0, f1 }; v1[0] = x; v1[1] = y; - ren_tri(r, c, v0, v1, v2, tri_mode_flat); + ren_tri(r, v0, v1, v2, &t); } int entrypoint(int argc, const char** argv, Arena* a) { @@ -86,7 +99,8 @@ int entrypoint(int argc, const char** argv, Arena* a) { ren_text(&r, blue, 3, 13, buf); sprintf(buf, "MOUSE: %d, %d", app->mx, app->my); ren_text(&r, blue, 3, 23, buf); - draw_torus(&r, blue); + draw_torus(&r); + draw_tri(&r, app->mx, app->my); ren_end(&r); app_end(app); fps_update(&f); |