Tutorial *10*

Written by Jacques Krige (Korax)
email: jkrige@ananzi.co.za
website: http://www.excentrax.co.za

---

Lets add some cool waterripple to the engine. In actual fact I've hacked this tutorial off the code from disabling the waterwarp. Actually I'm warping the water surface instead of the walls and stuff :)
Also very simple, straightforward and easy! :)

First, lets make a new CVAR...
Open the file called "gl_rmain.c"

Find the following line in the file:

cvar_t	gl_reporttjunctions ="gl_reporttjunctions","0"};

Then right below it add the following:
//jkrige - cvars

cvar_t	gl_waterripple ="gl_waterripple", "2"};

//jkrige - cvars

Now open the file called "glquake.h" and find the following line:
extern	cvar_t	gl_playermip;

Below that add the following:
//jkrige

extern	cvar_t	gl_waterripple;

//jkrige

Now, lets go register our new CVAR:
Open the file called "gl_rmisc.c" and find the function called "R_Init".
In that function find the line:
Cvar_RegisterVariable (&gl_reporttjunctions);

Below that line, add the following:
//jkrige - cvars

Cvar_RegisterVariable (&gl_waterripple);

//jkrige - cvars

Now for the fun-part.
Open up the file called gl_warp.c and find the function called "EmitWaterPolys".

When you did, replace it with this function I've already modified for you:
void EmitWaterPolys (msurface_t *fa)

{

	glpoly_t	*p;

	float		*v;

	int			i;

	float		s, t, os, ot;

	vec3_t	nv;



	//jkrige - clamp waterripple values

	if(gl_waterripple.value>10)

		gl_waterripple.value=10;



	if(gl_waterripple.value<0)

		gl_waterripple.value=0

	//jkrige - clamp waterripple values



	for (p=fa->polys ; p ; p=p->next)

	{

		glBegin (GL_POLYGON);

		for (i=0,v=p->verts[0] ; inumverts ; i++, v+=VERTEXSIZE)

		{

			os =v[3];

			ot =[4];



			//jkrige - waterripple

			nv[0] =v[0];

			nv[1] =v[1];

			nv[2] =v[2] + gl_waterripple.value*sin(v[0]*0.05+realtime)*sin(v[2]*0.05+realtime);

			//jkrige - waterripple



			s =s + turbsin[(int)((ot*0.125+realtime) * TURBSCALE) & 255];

			s *=(1.0/64);



			t =t + turbsin[(int)((os*0.125+realtime) * TURBSCALE) & 255];

			t *=(1.0/64);



			glTexCoord2f (s, t);

			glVertex3fv (nv);

		}

		glEnd ();

	}

}

There!
What I did is clamp the size of the warp or ripple effect you can have. Does it get any easier? :)

Enjoy the tutorial and rock-on!
Jacques Krige.


 
Not logged in
Sign up
Login:
Passwd: