From 7a4848676a91596f7d9e0ff0c9ef55030fc7062a Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 8 Aug 2020 02:54:06 +0300 Subject: [PATCH] working on the cyberspace part --- src/scr/cybersun.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/tinyfps.c | 7 +++-- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/scr/cybersun.c b/src/scr/cybersun.c index 7a247d2..6cd9f6a 100644 --- a/src/scr/cybersun.c +++ b/src/scr/cybersun.c @@ -1,16 +1,26 @@ #include #include +#include #include "demo.h" #include "3dgfx.h" #include "screen.h" #include "gfxutil.h" #include "mesh.h" #include "image.h" +#include "util.h" +#include "cgmath/cgmath.h" + +#define TM_RIPPLE_START 1.0f +#define TM_RIPPLE_TRANS_LEN 3.0f + +#define VFOV 50.0f +#define HFOV (VFOV * 1.333333f) static int init(void); static void destroy(void); static void start(long trans_time); static void draw(void); +static void draw_mountains(void); static struct screen scr = { "cybersun", @@ -21,7 +31,7 @@ static struct screen scr = { draw }; -static float cam_theta = 0, cam_phi = 10; +static float cam_theta = 0, cam_phi = 0; static float cam_dist = 0; static struct g3d_mesh gmesh; @@ -29,6 +39,11 @@ static struct g3d_mesh gmesh; #define GMESH_SIZE 128 static struct image gtex; +static struct image mounttex; + +static long part_start; + + struct screen *cybersun_screen(void) { return &scr; @@ -48,6 +63,11 @@ static int init(void) if(load_image(>ex, "data/pgrid.png") == -1) { return -1; } + if(load_image(&mounttex, "data/cybmount.png") == -1) { + return -1; + } + assert(mounttex.width == 512); + assert(mounttex.height == 64); return 0; } @@ -56,25 +76,30 @@ static void destroy(void) { destroy_mesh(&gmesh); destroy_image(>ex); + destroy_image(&mounttex); } static void start(long trans_time) { g3d_matrix_mode(G3D_PROJECTION); g3d_load_identity(); - g3d_perspective(50.0, 1.3333333, 0.5, 500.0); + g3d_perspective(VFOV, 1.3333333, 0.5, 500.0); g3d_enable(G3D_CULL_FACE); - g3d_clear_color(0, 0, 0); + g3d_clear_color(85, 70, 136); + + part_start = time_msec; } static void update(void) { int i, j; - float t = time_msec / 1000.0f; + float t = (time_msec - part_start) / 1000.0f; struct g3d_vertex *vptr; + float ampl = cgm_smoothstep(TM_RIPPLE_START, TM_RIPPLE_START + TM_RIPPLE_TRANS_LEN, t); + mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist); /* update mesh */ @@ -91,6 +116,7 @@ static void update(void) vptr->z += cos(y * 0.5 + t); vptr->z += sin(r + t) * 0.5f; vptr->z *= r * 0.1f > 1.0f ? 1.0f : r * 0.1f; + vptr->z *= ampl; vptr++; } } @@ -112,6 +138,7 @@ static void draw(void) } g3d_clear(G3D_COLOR_BUFFER_BIT | G3D_DEPTH_BUFFER_BIT); + draw_mountains(); g3d_set_texture(gtex.width, gtex.height, gtex.pixels); g3d_enable(G3D_TEXTURE_2D); @@ -127,3 +154,47 @@ static void draw(void) swap_buffers(fb_pixels); } + +/* XXX all the sptr calculations assume mounttex.width == 512 */ +static void draw_mountains(void) +{ + int i, j, y; + int32_t x, xstart, xend, dx; + uint16_t *dptr, *sptr; + + xstart = cround64(cam_theta * (256.0 * 512.0 / 90.0)); /* 24.8 fixed point, 512 width */ + xend = cround64((cam_theta + HFOV) * (256.0 * 512.0 / 90.0)); + dx = (xend - xstart) / FB_WIDTH; + x = xstart; + + y = cround64(-cam_phi * (FB_HEIGHT / 45.0)) + (FB_HEIGHT / 2 - 64); + + dptr = fb_pixels + y * FB_WIDTH; + + for(i=0; i> 8) & 0x1ff); + + for(j=0; j<64; j++) { + if(j + y >= FB_HEIGHT) break; + if(j + y >= 0) { + int32_t col = sptr[j << 9]; + if(col != 0x7e0) { + dptr[j * FB_WIDTH] = col; + } + } + } + dptr++; + + x += dx; + } + + y += 64; + if(y < 0) { + memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2); + } else { + if(y < FB_HEIGHT) { + dptr = fb_pixels + y * FB_WIDTH; + memset(dptr, 0, (FB_HEIGHT - y) * FB_WIDTH * 2); + } + } +} diff --git a/src/tinyfps.c b/src/tinyfps.c index 41102e6..269c965 100644 --- a/src/tinyfps.c +++ b/src/tinyfps.c @@ -4,9 +4,10 @@ #include "tinyfps.h" #include "demo.h" -/* TinyFPS, just a minimal fraps like font to show FPS during the demo and not just after. - * I'll be using it in my effects for my performance test purposes, just adding it here. - * Maybe it would be nice if initFpsFonts would be called in demo.c once but I avoided touching that code. +/* TinyFPS, just a minimal fraps like font to show FPS during the demo and not + * just after. I'll be using it in my effects for my performance test + * purposes, just adding it here. Maybe it would be nice if initFpsFonts would + * be called in demo.c once but I avoided touching that code. */ /* -- 1.7.10.4