deepstone

changeset 11:0909996838ff

fucked up lighting and enabled key repeat in dosemu
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Nov 2011 05:02:08 +0200
parents bce78aaafc68
children c29a6e024950
files dosemu/dosemu.c src/mglimpl.h src/mingl.c src/mingl.h
diffstat 4 files changed, 48 insertions(+), 18 deletions(-) [+]
line diff
     1.1 --- a/dosemu/dosemu.c	Sat Nov 26 03:59:48 2011 +0200
     1.2 +++ b/dosemu/dosemu.c	Mon Nov 28 05:02:08 2011 +0200
     1.3 @@ -57,10 +57,12 @@
     1.4  			abort();
     1.5  		}
     1.6  		SDL_ShowCursor(0);
     1.7 +		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
     1.8  		break;
     1.9  
    1.10  	case 3:
    1.11  		SDL_ShowCursor(1);
    1.12 +		SDL_EnableKeyRepeat(0, 0);
    1.13  		SDL_Quit();
    1.14  		break;
    1.15  
     2.1 --- a/src/mglimpl.h	Sat Nov 26 03:59:48 2011 +0200
     2.2 +++ b/src/mglimpl.h	Mon Nov 28 05:02:08 2011 +0200
     2.3 @@ -69,7 +69,7 @@
     2.4  	int vidx;
     2.5  	int vp[4];	/* viewport */
     2.6  	int col_range;	/* color interpolation range */
     2.7 -	vec3_t ldir[MAX_LIGHTS];
     2.8 +	vec4_t lpos[MAX_LIGHTS];
     2.9  	float lint[MAX_LIGHTS];
    2.10  
    2.11  	struct texture tex;
     3.1 --- a/src/mingl.c	Sat Nov 26 03:59:48 2011 +0200
     3.2 +++ b/src/mingl.c	Mon Nov 28 05:02:08 2011 +0200
     3.3 @@ -26,6 +26,17 @@
     3.4  
     3.5  #define DOT(a, b)	((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
     3.6  
     3.7 +#define NORMALIZE(v)	\
     3.8 +	do { \
     3.9 +		float mag = sqrt(DOT(v, v)); \
    3.10 +		if(fabs(mag) > 1e-6) { \
    3.11 +			float invmag = 1.0 / mag; \
    3.12 +			(v).x *= invmag; \
    3.13 +			(v).y *= invmag; \
    3.14 +			(v).z *= invmag; \
    3.15 +		} \
    3.16 +	} while(0)
    3.17 +
    3.18  static void transform(vec4_t *res, vec4_t *v, float *mat);
    3.19  static void transform3(vec3_t *res, vec3_t *v, float *mat);
    3.20  static void vertex_proc(struct vertex *vert);
    3.21 @@ -74,8 +85,8 @@
    3.22  
    3.23  	st.col_range = 256;
    3.24  	for(i=0; i<MAX_LIGHTS; i++) {
    3.25 -		st.ldir[i].x = st.ldir[i].y = 0.0f;
    3.26 -		st.ldir[i].z = 1.0f;
    3.27 +		st.lpos[i].x = st.lpos[i].y = st.lpos[i].w = 0.0f;
    3.28 +		st.lpos[i].z = 1.0f;
    3.29  		st.lint[i] = 0.0f;
    3.30  	}
    3.31  
    3.32 @@ -173,24 +184,26 @@
    3.33  	st.lint[ltidx] = intens;
    3.34  }
    3.35  
    3.36 -void mgl_light_direction(int ltidx, float x, float y, float z)
    3.37 +void mgl_light_position(int ltidx, float x, float y, float z, float w)
    3.38  {
    3.39 -	vec3_t dir;
    3.40 -	float mag;
    3.41 +	vec4_t pos;
    3.42  	assert(ltidx >= 0 && ltidx < MAX_LIGHTS);
    3.43  
    3.44 -	dir.x = x;
    3.45 -	dir.y = y;
    3.46 -	dir.z = z;
    3.47 -	transform3(&st.ldir[ltidx], &dir, st.matrix[MGL_MODELVIEW][st.mtop[MGL_MODELVIEW]]);
    3.48 +	pos.x = x;
    3.49 +	pos.y = y;
    3.50 +	pos.z = z;
    3.51 +	pos.w = w;
    3.52 +	transform(&st.lpos[ltidx], &pos, st.matrix[MGL_MODELVIEW][st.mtop[MGL_MODELVIEW]]);
    3.53  
    3.54 -	mag = sqrt(DOT(st.ldir[ltidx], st.ldir[ltidx]));
    3.55 -	if(fabs(mag) < 1e-6) {
    3.56 -		mag = 1.0f;
    3.57 +	if(fabs(st.lpos[ltidx].w) < 1e-6) {
    3.58 +		st.lpos[ltidx].w = 1.0;
    3.59 +
    3.60 +		NORMALIZE(st.lpos[ltidx]);
    3.61 +	} else {
    3.62 +		st.lpos[ltidx].x /= st.lpos[ltidx].w;
    3.63 +		st.lpos[ltidx].y /= st.lpos[ltidx].w;
    3.64 +		st.lpos[ltidx].z /= st.lpos[ltidx].w;
    3.65  	}
    3.66 -	st.ldir[ltidx].x /= mag;
    3.67 -	st.ldir[ltidx].y /= mag;
    3.68 -	st.ldir[ltidx].z /= mag;
    3.69  }
    3.70  
    3.71  void mgl_begin(int prim)
    3.72 @@ -313,7 +326,22 @@
    3.73  
    3.74  			for(i=0; i<MAX_LIGHTS; i++) {
    3.75  				if(st.lint[i] > 1e-6f) {
    3.76 -					float ndotl = DOT(norm, st.ldir[i]);
    3.77 +					float ndotl;
    3.78 +					vec3_t ldir;
    3.79 +
    3.80 +					if(st.lpos[i].w == 0.0) {
    3.81 +						ldir.x = st.lpos[i].x;
    3.82 +						ldir.y = st.lpos[i].y;
    3.83 +						ldir.z = st.lpos[i].z;
    3.84 +					} else {
    3.85 +						ldir.x = st.lpos[i].x - pview.x;
    3.86 +						ldir.y = st.lpos[i].y - pview.y;
    3.87 +						ldir.z = st.lpos[i].z - pview.z;
    3.88 +
    3.89 +						NORMALIZE(ldir);
    3.90 +					}
    3.91 +
    3.92 +					ndotl = DOT(norm, ldir);
    3.93  					if(ndotl < 0.0) {
    3.94  						ndotl = 0.0;
    3.95  					}
     4.1 --- a/src/mingl.h	Sat Nov 26 03:59:48 2011 +0200
     4.2 +++ b/src/mingl.h	Mon Nov 28 05:02:08 2011 +0200
     4.3 @@ -59,7 +59,7 @@
     4.4  
     4.5  void mgl_color_range(int rng);
     4.6  void mgl_light_intensity(int ltidx, float intens);
     4.7 -void mgl_light_direction(int ltidx, float x, float y, float z);
     4.8 +void mgl_light_position(int ltidx, float x, float y, float z, float w);
     4.9  
    4.10  void mgl_begin(int prim);
    4.11  void mgl_end(void);