st->imm_curv.nz = z;
}
+#define CLAMP(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
+
void g3d_color3b(unsigned char r, unsigned char g, unsigned char b)
{
- st->imm_curv.r = r;
- st->imm_curv.g = g;
- st->imm_curv.b = b;
+ st->imm_curv.r = CLAMP(r, 0, 255);
+ st->imm_curv.g = CLAMP(g, 0, 255);
+ st->imm_curv.b = CLAMP(b, 0, 255);
st->imm_curv.a = 255;
}
void g3d_color4b(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
- st->imm_curv.r = r;
- st->imm_curv.g = g;
- st->imm_curv.b = b;
- st->imm_curv.a = a;
+ st->imm_curv.r = CLAMP(r, 0, 255);
+ st->imm_curv.g = CLAMP(g, 0, 255);
+ st->imm_curv.b = CLAMP(b, 0, 255);
+ st->imm_curv.a = CLAMP(a, 0, 255);
}
void g3d_color3f(float r, float g, float b)
int ir = r * 255.0f;
int ig = g * 255.0f;
int ib = b * 255.0f;
- st->imm_curv.r = ir > 255 ? 255 : ir;
- st->imm_curv.g = ig > 255 ? 255 : ig;
- st->imm_curv.b = ib > 255 ? 255 : ib;
+ st->imm_curv.r = CLAMP(ir, 0, 255);
+ st->imm_curv.g = CLAMP(ig, 0, 255);
+ st->imm_curv.b = CLAMP(ib, 0, 255);
st->imm_curv.a = 255;
}
int ig = g * 255.0f;
int ib = b * 255.0f;
int ia = a * 255.0f;
- st->imm_curv.r = ir > 255 ? 255 : ir;
- st->imm_curv.g = ig > 255 ? 255 : ig;
- st->imm_curv.b = ib > 255 ? 255 : ib;
- st->imm_curv.a = ia > 255 ? 255 : ia;
+ st->imm_curv.r = CLAMP(ir, 0, 255);
+ st->imm_curv.g = CLAMP(ig, 0, 255);
+ st->imm_curv.b = CLAMP(ib, 0, 255);
+ st->imm_curv.a = CLAMP(ia, 0, 255);
}
void g3d_texcoord(float u, float v)
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include "census.h"
+#include "logo.h"
+#include "timer.h"
#include "3dgfx.h"
#include "panic.h"
+static void draw_disc(float x, float y, float rad, int sub);
+static void draw_line(float x0, float y0, float x1, float y1, float rad);
+
+static int nverts = 256;
+static long start_time;
+
+#define LOOPTIME 1.45f
+
void init_census(void *pixels, int xsz, int ysz)
{
+ float aspect = (float)xsz / (float)ysz;
+
+ init_logo(0);
+
fb_pixels = pixels;
fb_width = xsz;
fb_height = ysz;
g3d_init();
g3d_framebuffer(xsz, ysz, fb_pixels);
g3d_polygon_mode(G3D_FLAT);
+
g3d_viewport(0, 0, xsz, ysz);
+ g3d_matrix_mode(G3D_PROJECTION);
+ g3d_load_identity();
+ g3d_scale(1.0f / aspect , 1.0f, 1.0f);
+
+ start_time = TICKS_TO_MSEC(nticks);
}
void draw_census(void)
{
int i;
+ long msec = TICKS_TO_MSEC(nticks);
+ float t = (float)msec / 1000.0f;
+ float a[2], b[2], dt;
+ float anim, alpha, center_alpha;
+
memset(fb_pixels, 0, fb_width * fb_height * 4);
- g3d_matrix_mode(G3D_MODELVIEW);
- g3d_load_identity();
+ anim = fmod(t / 6.0f, LOOPTIME);
+ alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f);
+ if(alpha < 0.0f) alpha = 0.0f;
+ if(alpha > 1.0f) alpha = 1.0f;
+
+ dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
+
+ g3d_color4f(1, 1, 1, alpha);
+ for(i=0; i<nverts-1; i++) {
+ float t0 = (float)i * dt;
+ float t1 = (float)(i + 1) * dt;
+ eval_logo(a, t0);
+ eval_logo(b, t1);
+ draw_line(a[0], a[1], b[0], b[1], 0.02);
+ }
+
+ if(anim > 0.0f) {
+ eval_logo(a, 0);
+ draw_disc(a[0], a[1], 0.05, 22);
+ }
+ if(anim >= 1.0f) {
+ eval_logo(b, 1);
+ draw_disc(b[0], b[1], 0.05, 22);
+ }
+
+
+ center_alpha = 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f);
+ if(center_alpha > 0.4) {
+ g3d_color4f(0.8, 0, 0, center_alpha);
+ draw_disc(0, 0, 0.14, 30);
+ }
- g3d_enable(G3D_BLEND);
+}
+
+static void draw_disc(float x, float y, float rad, int sub)
+{
+ int i;
+ float dt = 1.0f / (float)(sub - 1);
+ float da = dt * M_PI * 2.0;
- g3d_color4b(64, 128, 255, 255);
- for(i=0; i<2; i++) {
- g3d_begin(G3D_QUADS);
- g3d_vertex(-0.4, -0.5, 0);
- g3d_vertex(0.6, -0.2, 0);
- g3d_vertex(0, 0.8, 0);
- g3d_vertex(-0.5, 0.6, 0);
- g3d_end();
+ g3d_begin(G3D_TRIANGLES);
+ for(i=0; i<sub; i++) {
+ float theta = i * da;
- g3d_translate(0.2, -0.2, 0);
- g3d_color4b(255, 32, 255, 128);
+ g3d_vertex(x, y, 0);
+ g3d_vertex(cos(theta) * rad + x, sin(theta) * rad + y, 0);
+ g3d_vertex(cos(theta + da) * rad + x, sin(theta + da) * rad + y, 0);
}
+ g3d_end();
+}
+
+static void draw_line(float x0, float y0, float x1, float y1, float rad)
+{
+ float dx, dy, rx, ry, len;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+ len = sqrt(dx * dx + dy * dy);
- g3d_disable(G3D_BLEND);
+ rx = rad * dy / len;
+ ry = -rad * dx / len;
+
+ draw_disc(x0, y0, rad, 12);
+ draw_disc(x1, y1, rad, 12);
+
+ g3d_begin(G3D_QUADS);
+ g3d_vertex(x0 + rx, y0 + ry, 0);
+ g3d_vertex(x1 + rx, y1 + ry, 0);
+ g3d_vertex(x1 - rx, y1 - ry, 0);
+ g3d_vertex(x0 - rx, y0 - ry, 0);
+ g3d_end();
}
+