Tweak shadow code to keep the transforms in one place
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 13 Mar 2011 17:58:01 +0000 (17:58 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 13 Mar 2011 17:58:01 +0000 (17:58 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3521 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/game_draw.c
putt/game.c
share/geom.c
share/geom.h
share/solid_draw.c
share/solid_draw.h

index ba75b0e..7d039fc 100644 (file)
@@ -383,7 +383,6 @@ static void game_draw_fore(const struct game_draw *gd,
                            int d, float t)
 {
     const float *ball_p = gd->vary.uv[0].p;
-    const float  ball_r = gd->vary.uv[0].r;
 
     const struct s_draw *draw = &gd->draw;
 
@@ -424,8 +423,8 @@ static void game_draw_fore(const struct game_draw *gd,
 
             if (d > 0 && config_get_d(CONFIG_SHADOW))
             {
-                shad_draw_set(ball_p, ball_r);
-                sol_shad(draw);
+                shad_draw_set();
+                sol_shad(draw, 0);
                 shad_draw_clr();
             }
 
index 746edbb..728976a 100644 (file)
@@ -355,8 +355,8 @@ void game_draw(int pose, float t)
 
         if (config_get_d(CONFIG_SHADOW) && !pose)
         {
-            shad_draw_set(fp->vary->uv[ball].p, fp->vary->uv[ball].r);
-            sol_shad(fp);
+            shad_draw_set();
+            sol_shad(fp, ball);
             shad_draw_clr();
         }
 
index 88725c8..920c0b5 100644 (file)
@@ -322,18 +322,13 @@ void shad_free(void)
         glDeleteTextures(1, &shad_text);
 }
 
-void shad_draw_set(const float *p, float r)
+void shad_draw_set(void)
 {
     glBindTexture(GL_TEXTURE_2D, shad_text);
 
     glMatrixMode(GL_TEXTURE);
     {
-        float k = 0.25f / r;
-
         glLoadIdentity();
-        glTranslatef(0.5f - k * p[0],
-                     0.5f - k * p[2], 0.f);
-        glScalef(k, k, 1.0f);
     }
     glMatrixMode(GL_MODELVIEW);
 
@@ -346,12 +341,6 @@ void shad_draw_set(const float *p, float r)
 
 void shad_draw_clr(void)
 {
-    glMatrixMode(GL_TEXTURE);
-    {
-        glLoadIdentity();
-    }
-    glMatrixMode(GL_MODELVIEW);
-
     glDisable(GL_TEXTURE_GEN_S);
     glDisable(GL_TEXTURE_GEN_T);
 }
index f704027..4d34073 100644 (file)
@@ -44,7 +44,7 @@ void flag_draw(void);
 
 void shad_init(void);
 void shad_free(void);
-void shad_draw_set(const float *, float);
+void shad_draw_set(void);
 void shad_draw_clr(void);
 
 /*---------------------------------------------------------------------------*/
index 2fb555e..bc8b0e7 100644 (file)
@@ -520,9 +520,11 @@ static void sol_shad_body(const struct s_base *base,
 }
 
 static void sol_shad_list(const struct s_vary *vary,
+                          const struct v_ball *up,
                           const struct v_body *bp, GLuint list)
 {
     float p[3], e[4], u[3], a;
+    float d[3];
 
     float X[] = { 1.0f, 0.0f, 0.0f, 0.0f };
     float Z[] = { 0.0f, 0.0f, 1.0f, 0.0f };
@@ -530,6 +532,8 @@ static void sol_shad_list(const struct s_vary *vary,
     sol_body_p(p, vary, bp->pi, bp->t);
     sol_body_e(e, vary, bp, 0);
 
+    v_sub(d, up->p, p);
+
     if (e[0] != 1.0f)
     {
         q_as_axisangle(e, u, &a);
@@ -555,8 +559,12 @@ static void sol_shad_list(const struct s_vary *vary,
 
     glMatrixMode(GL_TEXTURE);
     {
+        float k = 0.25f / up->r;
+
         glPushMatrix();
-        glTranslatef(p[0], p[2], 0.0f);
+        glTranslatef(0.5f - k * d[0],
+                     0.5f - k * d[2], 0.0f);
+        glScalef(k, k, 0.0f);
     }
     glMatrixMode(GL_MODELVIEW);
 
@@ -580,7 +588,7 @@ static void sol_shad_list(const struct s_vary *vary,
     glMatrixMode(GL_MODELVIEW);
 }
 
-void sol_shad(const struct s_draw *draw)
+void sol_shad(const struct s_draw *draw, int ui)
 {
     int bi;
 
@@ -590,7 +598,9 @@ void sol_shad(const struct s_draw *draw)
     {
         for (bi = 0; bi < draw->bc; bi++)
             if (draw->bv[bi].sl)
-                sol_shad_list(draw->vary, draw->vary->bv + bi, draw->bv[bi].sl);
+                sol_shad_list(draw->vary,
+                              draw->vary->uv + ui,
+                              draw->vary->bv + bi, draw->bv[bi].sl);
     }
     glDepthMask(GL_TRUE);
 }
index f6fcae6..30d1583 100644 (file)
@@ -64,7 +64,7 @@ void sol_back(const struct s_draw *, float, float, float);
 void sol_refl(const struct s_draw *);
 void sol_draw(const struct s_draw *, int, int);
 void sol_bill(const struct s_draw *, const float *, float);
-void sol_shad(const struct s_draw *);
+void sol_shad(const struct s_draw *, int);
 
 /*---------------------------------------------------------------------------*/