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)
jump_list = 0;
}
-void jump_draw(void)
+void jump_draw(int highlight)
{
- glCallList(jump_list);
+ glCallList(jump_list + highlight);
}
/*---------------------------------------------------------------------------*/
}
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++)
{
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)
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++)
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;