X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fscr%2Fcybersun.c;h=fde29ab0ad69d862897da5882958c032f6bc1ec9;hb=6bb6e7b35b1f10eb26fcd46f2b45af0afa782a1f;hp=7a247d2ad6620471943f740d0d261e25c8343d25;hpb=df9e386a2a7727abea47ae0c7b94015ce5bc62c4;p=dosdemo diff --git a/src/scr/cybersun.c b/src/scr/cybersun.c index 7a247d2..fde29ab 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,14 @@ static struct g3d_mesh gmesh; #define GMESH_SIZE 128 static struct image gtex; +#define MOUNTIMG_WIDTH 512 +#define MOUNTIMG_HEIGHT 64 +static struct image mountimg; +static int mountimg_skip[MOUNTIMG_WIDTH]; + +static long part_start; + + struct screen *cybersun_screen(void) { return &scr; @@ -48,6 +66,24 @@ static int init(void) if(load_image(>ex, "data/pgrid.png") == -1) { return -1; } + if(load_image(&mountimg, "data/cybmount.png") == -1) { + return -1; + } + assert(mountimg.width == MOUNTIMG_WIDTH); + assert(mountimg.height == MOUNTIMG_HEIGHT); + + for(i=0; iz += 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 +153,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 +169,47 @@ static void draw(void) swap_buffers(fb_pixels); } + +/* XXX all the sptr calculations assume mountimg.width == 512 */ +static void draw_mountains(void) +{ + int i, j, horizon_y, y; + int32_t x, xstart, xend, dx; + uint16_t *dptr, *sptr; + + /* 24.8 fixed point, 512 width, 90deg arc */ + xstart = cround64(cam_theta * (256.0 * MOUNTIMG_WIDTH / 90.0)); + xend = cround64((cam_theta + HFOV) * (256.0 * MOUNTIMG_WIDTH / 90.0)); + dx = (xend - xstart) / FB_WIDTH; + x = xstart; + + horizon_y = cround64(-cam_phi * (FB_HEIGHT / 45.0)) + FB_HEIGHT / 2; + y = horizon_y - MOUNTIMG_HEIGHT; + + if(y >= FB_HEIGHT) { + /* TODO draw gradient for the sky */ + return; + } + if(horizon_y < 0) { + memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2); + return; + } + + for(i=0; i> 8) & 0x1ff]; + int vspan = MOUNTIMG_HEIGHT - skip; + + dptr = fb_pixels + (y + skip) * FB_WIDTH + i; + + for(j=0; j