From 26c7eaa698e76ed25f0ef3667dbcd9b6288bf0df Mon Sep 17 00:00:00 2001 From: mrtout Date: Thu, 9 Mar 2006 19:49:28 +0000 Subject: [PATCH] Adapt halo switch system to teleports (aka jumps). Fix #61 git-svn-id: https://s.snth.net/svn/neverball/trunk@298 78b8d119-cf0a-0410-b17c-f493084dd1d7 --- ball/game.c | 2 +- putt/game.c | 2 +- share/geom.c | 63 ++++++++++++++++++++++++++++++--------------------------- share/geom.h | 2 +- share/solid.c | 32 ++++++++++++++++++++--------- 5 files changed, 59 insertions(+), 42 deletions(-) diff --git a/ball/game.c b/ball/game.c index 4d14369..615202e 100644 --- a/ball/game.c +++ b/ball/game.c @@ -252,7 +252,7 @@ static void game_draw_jumps(const struct s_file *fp) fp->jv[ji].p[2]); glScalef(fp->jv[ji].r, 1.f, fp->jv[ji].r); - jump_draw(); + jump_draw(!jump_e); } glPopMatrix(); } diff --git a/putt/game.c b/putt/game.c index cec0618..27aaa25 100644 --- a/putt/game.c +++ b/putt/game.c @@ -241,7 +241,7 @@ static void game_draw_jumps(const struct s_file *fp) fp->jv[ji].p[2]); glScalef(fp->jv[ji].r, 1.f, fp->jv[ji].r); - jump_draw(); + jump_draw(!jump_e); } glPopMatrix(); } diff --git a/share/geom.c b/share/geom.c index def33a0..0f5dac7 100644 --- a/share/geom.c +++ b/share/geom.c @@ -405,40 +405,43 @@ static GLuint jump_list; void jump_init(int b) { - int i, n = b ? 32 : 8; + int k, i, n = b ? 32 : 8; - jump_list = glGenLists(1); + jump_list = glGenLists(2); - glNewList(jump_list, GL_COMPILE); + for (k=0; k<12; k++) { - glPushAttrib(GL_TEXTURE_BIT | - GL_LIGHTING_BIT | - GL_DEPTH_BUFFER_BIT); - { - glEnable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); - glDepthMask(GL_FALSE); + glNewList(jump_list + k, GL_COMPILE); + { + glPushAttrib(GL_TEXTURE_BIT | + GL_LIGHTING_BIT | + GL_DEPTH_BUFFER_BIT); + { + glEnable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDepthMask(GL_FALSE); - glBegin(GL_QUAD_STRIP); - { - for (i = 0; i <= n; i++) - { - float x = fcosf(2.f * PI * i / n); - float y = fsinf(2.f * PI * i / n); - - glColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glVertex3f(x, 0.0f, y); + glBegin(GL_QUAD_STRIP); + { + for (i = 0; i <= n; i++) + { + float x = fcosf(2.f * PI * i / n); + float y = fsinf(2.f * PI * i / n); - glColor4f(1.0f, 1.0f, 1.0f, 0.0f); - glVertex3f(x, JUMP_HEIGHT, y); - } - } - glEnd(); - } - glPopAttrib(); + glColor4f(1.0f, 1.0f, 1.0f, (k==0 ? 0.5f : 0.8f)); + glVertex3f(x, 0.0f, y); + + glColor4f(1.0f, 1.0f, 1.0f, 0.0f); + glVertex3f(x, JUMP_HEIGHT, y); + } + } + glEnd(); + } + glPopAttrib(); + } + glEndList(); } - glEndList(); } void jump_free(void) @@ -449,9 +452,9 @@ void jump_free(void) jump_list = 0; } -void jump_draw(void) +void jump_draw(int highlight) { - glCallList(jump_list); + glCallList(jump_list + highlight); } /*---------------------------------------------------------------------------*/ diff --git a/share/geom.h b/share/geom.h index 0ed379e..af4a4e8 100644 --- a/share/geom.h +++ b/share/geom.h @@ -45,7 +45,7 @@ void goal_draw(void); void jump_init(int); void jump_free(void); -void jump_draw(void); +void jump_draw(int); /*---------------------------------------------------------------------------*/ diff --git a/share/solid.c b/share/solid.c index 25802c8..6f0936a 100644 --- a/share/solid.c +++ b/share/solid.c @@ -1901,10 +1901,16 @@ int sol_goal_test(struct s_file *fp, float *p, int ui) } int sol_jump_test(struct s_file *fp, float *p, int ui) +/* Test if the ball ui in inside a jump */ +/* Return 1 if yes and fill p with the destination position */ +/* Return 0 if no */ +/* Return 2 if the ball is on the border of a jump */ { const float *ball_p = fp->uv[ui].p; const float ball_r = fp->uv[ui].r; int ji; + float l; + int res = 0; for (ji = 0; ji < fp->jc; ji++) { @@ -1914,18 +1920,24 @@ int sol_jump_test(struct s_file *fp, float *p, int ui) r[1] = ball_p[2] - fp->jv[ji].p[2]; r[2] = 0; - if (v_len(r) < fp->jv[ji].r - ball_r && + l = v_len(r) - fp->jv[ji].r; + if (l < 0 && ball_p[1] > fp->jv[ji].p[1] && ball_p[1] < fp->jv[ji].p[1] + JUMP_HEIGHT / 2) { - p[0] = fp->jv[ji].q[0] + (ball_p[0] - fp->jv[ji].p[0]); - p[1] = fp->jv[ji].q[1] + (ball_p[1] - fp->jv[ji].p[1]); - p[2] = fp->jv[ji].q[2] + (ball_p[2] - fp->jv[ji].p[2]); - - return 1; + if (l < - ball_r ) + { + p[0] = fp->jv[ji].q[0] + (ball_p[0] - fp->jv[ji].p[0]); + p[1] = fp->jv[ji].q[1] + (ball_p[1] - fp->jv[ji].p[1]); + p[2] = fp->jv[ji].q[2] + (ball_p[2] - fp->jv[ji].p[2]); + + return 1; + } + else + res = 2; } } - return 0; + return res; } int sol_swch_test(struct s_file *fp, int ui) @@ -1936,6 +1948,7 @@ int sol_swch_test(struct s_file *fp, int ui) const float *ball_p = fp->uv[ui].p; const float ball_r = fp->uv[ui].r; int xi; + float l; int res = 0; /* result */ for (xi = 0; xi < fp->xc; xi++) @@ -1950,11 +1963,12 @@ int sol_swch_test(struct s_file *fp, int ui) r[1] = ball_p[2] - xp->p[2]; r[2] = 0; - if (v_len(r) < xp->r + ball_r && + l = v_len(r) - xp->r; + if (l < ball_r && ball_p[1] > xp->p[1] && ball_p[1] < xp->p[1] + SWCH_HEIGHT / 2) { - if (!xp->e && v_len(r) < xp->r - ball_r) + if (!xp->e && l < - ball_r) { int pi = xp->pi; int pj = xp->pi; -- 1.7.9.5