From bfc470c7ab9e537d91c8a4dc98afb500f836fc15 Mon Sep 17 00:00:00 2001
From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Wed, 16 May 2007 09:27:04 +0000
Subject: [PATCH] optimized the Mod_Q3BSP_LightPoint pitch/yaw math by using
 the mod_md3_sin table rather than a lot of angle math to feed to cos/sin

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7288 d7cf8633-e32d-0410-b094-e92efae38249
---
 model_brush.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/model_brush.c b/model_brush.c
index f3b4dbaa..ae1e1b97 100644
--- a/model_brush.c
+++ b/model_brush.c
@@ -5625,12 +5625,12 @@ static void Mod_Q3BSP_LightPoint(model_t *model, const vec3_t p, vec3_t ambientc
 				s = a + (k * model->brushq3.num_lightgrid_isize[1] + j) * model->brushq3.num_lightgrid_isize[0] + i;
 				VectorMA(ambientcolor, blend * (1.0f / 128.0f), s->ambientrgb, ambientcolor);
 				VectorMA(diffusecolor, blend * (1.0f / 128.0f), s->diffusergb, diffusecolor);
-				pitch = s->diffusepitch * M_PI / 128;
-				yaw = s->diffuseyaw * M_PI / 128;
-				sinpitch = sin(pitch);
-				diffusenormal[0] += blend * (cos(yaw) * sinpitch);
-				diffusenormal[1] += blend * (sin(yaw) * sinpitch);
-				diffusenormal[2] += blend * (cos(pitch));
+				// this uses the mod_md3_sin table because the values are
+				// already in the 0-255 range, the 64+ bias fetches a cosine
+				// instead of a sine value
+				diffusenormal[0] += blend * (mod_md3_sin[64 + s->diffuseyaw] * mod_md3_sin[s->diffusepitch]);
+				diffusenormal[1] += blend * (mod_md3_sin[     s->diffuseyaw] * mod_md3_sin[s->diffusepitch]);
+				diffusenormal[2] += blend * (mod_md3_sin[64 + s->diffusepitch]);
 				//Con_Printf("blend %f: ambient %i %i %i, diffuse %i %i %i, diffusepitch %i diffuseyaw %i (%f %f, normal %f %f %f)\n", blend, s->ambientrgb[0], s->ambientrgb[1], s->ambientrgb[2], s->diffusergb[0], s->diffusergb[1], s->diffusergb[2], s->diffusepitch, s->diffuseyaw, pitch, yaw, (cos(yaw) * cospitch), (sin(yaw) * cospitch), (-sin(pitch)));
 			}
 		}
-- 
2.39.5