# HG changeset patch # User John Tsiombikas # Date 1322449328 -7200 # Node ID 0909996838ff98fd0dfb998d567950e0d4d91c29 # Parent bce78aaafc68591efd2bc425466d1322e1e0ad1f fucked up lighting and enabled key repeat in dosemu diff -r bce78aaafc68 -r 0909996838ff dosemu/dosemu.c --- a/dosemu/dosemu.c Sat Nov 26 03:59:48 2011 +0200 +++ b/dosemu/dosemu.c Mon Nov 28 05:02:08 2011 +0200 @@ -57,10 +57,12 @@ abort(); } SDL_ShowCursor(0); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); break; case 3: SDL_ShowCursor(1); + SDL_EnableKeyRepeat(0, 0); SDL_Quit(); break; diff -r bce78aaafc68 -r 0909996838ff src/mglimpl.h --- a/src/mglimpl.h Sat Nov 26 03:59:48 2011 +0200 +++ b/src/mglimpl.h Mon Nov 28 05:02:08 2011 +0200 @@ -69,7 +69,7 @@ int vidx; int vp[4]; /* viewport */ int col_range; /* color interpolation range */ - vec3_t ldir[MAX_LIGHTS]; + vec4_t lpos[MAX_LIGHTS]; float lint[MAX_LIGHTS]; struct texture tex; diff -r bce78aaafc68 -r 0909996838ff src/mingl.c --- a/src/mingl.c Sat Nov 26 03:59:48 2011 +0200 +++ b/src/mingl.c Mon Nov 28 05:02:08 2011 +0200 @@ -26,6 +26,17 @@ #define DOT(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z) +#define NORMALIZE(v) \ + do { \ + float mag = sqrt(DOT(v, v)); \ + if(fabs(mag) > 1e-6) { \ + float invmag = 1.0 / mag; \ + (v).x *= invmag; \ + (v).y *= invmag; \ + (v).z *= invmag; \ + } \ + } while(0) + static void transform(vec4_t *res, vec4_t *v, float *mat); static void transform3(vec3_t *res, vec3_t *v, float *mat); static void vertex_proc(struct vertex *vert); @@ -74,8 +85,8 @@ st.col_range = 256; for(i=0; i= 0 && ltidx < MAX_LIGHTS); - dir.x = x; - dir.y = y; - dir.z = z; - transform3(&st.ldir[ltidx], &dir, st.matrix[MGL_MODELVIEW][st.mtop[MGL_MODELVIEW]]); + pos.x = x; + pos.y = y; + pos.z = z; + pos.w = w; + transform(&st.lpos[ltidx], &pos, st.matrix[MGL_MODELVIEW][st.mtop[MGL_MODELVIEW]]); - mag = sqrt(DOT(st.ldir[ltidx], st.ldir[ltidx])); - if(fabs(mag) < 1e-6) { - mag = 1.0f; + if(fabs(st.lpos[ltidx].w) < 1e-6) { + st.lpos[ltidx].w = 1.0; + + NORMALIZE(st.lpos[ltidx]); + } else { + st.lpos[ltidx].x /= st.lpos[ltidx].w; + st.lpos[ltidx].y /= st.lpos[ltidx].w; + st.lpos[ltidx].z /= st.lpos[ltidx].w; } - st.ldir[ltidx].x /= mag; - st.ldir[ltidx].y /= mag; - st.ldir[ltidx].z /= mag; } void mgl_begin(int prim) @@ -313,7 +326,22 @@ for(i=0; i 1e-6f) { - float ndotl = DOT(norm, st.ldir[i]); + float ndotl; + vec3_t ldir; + + if(st.lpos[i].w == 0.0) { + ldir.x = st.lpos[i].x; + ldir.y = st.lpos[i].y; + ldir.z = st.lpos[i].z; + } else { + ldir.x = st.lpos[i].x - pview.x; + ldir.y = st.lpos[i].y - pview.y; + ldir.z = st.lpos[i].z - pview.z; + + NORMALIZE(ldir); + } + + ndotl = DOT(norm, ldir); if(ndotl < 0.0) { ndotl = 0.0; } diff -r bce78aaafc68 -r 0909996838ff src/mingl.h --- a/src/mingl.h Sat Nov 26 03:59:48 2011 +0200 +++ b/src/mingl.h Mon Nov 28 05:02:08 2011 +0200 @@ -59,7 +59,7 @@ void mgl_color_range(int rng); void mgl_light_intensity(int ltidx, float intens); -void mgl_light_direction(int ltidx, float x, float y, float z); +void mgl_light_position(int ltidx, float x, float y, float z, float w); void mgl_begin(int prim); void mgl_end(void);