Adapt halo switch system to teleports (aka jumps). Fix #61
authormrtout <mrtout@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 9 Mar 2006 19:49:28 +0000 (19:49 +0000)
committermrtout <mrtout@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 9 Mar 2006 19:49:28 +0000 (19:49 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@298 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/game.c
putt/game.c
share/geom.c
share/geom.h
share/solid.c

index 4d14369..615202e 100644 (file)
@@ -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();
     }
index cec0618..27aaa25 100644 (file)
@@ -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();
     }
index def33a0..0f5dac7 100644 (file)
@@ -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);
 }
 
 /*---------------------------------------------------------------------------*/
index 0ed379e..af4a4e8 100644 (file)
@@ -45,7 +45,7 @@ void goal_draw(void);
 
 void jump_init(int);
 void jump_free(void);
-void jump_draw(void);
+void jump_draw(int);
 
 /*---------------------------------------------------------------------------*/
 
index 25802c8..6f0936a 100644 (file)
@@ -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;