Page 1 of 1

gl_doubleeyes fix

Posted: Tue Sep 25, 2012 5:00 pm
by mh
...and I don't mean running the name through a spell-checker.

gl_doubleeyes is broken. The idea is to increase the size of the eyes model because it's harder to see, but it fails on account of the fact that the translation used for doing it is all wrong. You can see this for yourself - fire up a map that has the Ring in it, switch to chase_active 1, grab the Ring, and flip back and forth between values of 1 and 0. See how it moves around as well as scaling? It shouldn't move, and the comment over this section of code is quite clear that the intention is just to change the size.

The reason for this is that - after application of scale and scale_origin, eyes.mdl is not centered on [0,0,0] - presumably this was done so that the model can be easily switched without having to respecify entity origin as well.

Here's the fix. Find this piece of nasty junk:

Code: Select all

	if (!strcmp (clmodel->name, "progs/eyes.mdl") && gl_doubleeyes.value) {
		glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2] - (22 + 8));
		// double size of eyes, since they are really hard to see in gl
		glScalef (paliashdr->scale[0]*2, paliashdr->scale[1]*2, paliashdr->scale[2]*2);
	} else {
		glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
		glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
	}
And replace it with this:

Code: Select all

	if (!strcmp (e->model->name, "progs/eyes.mdl") && gl_doubleeyes.value > 0.0f)
	{
		// scaling factor - gl_doubleeyes 0 = unscaled, gl_doubleeyes 1 = 2x
		float sc = gl_doubleeyes.value + 1.0f;

		// offsets for eyes.mdl derived by taking the scaled midpoint of all verts in the mdl
		// you may wish to calculate these at load time rather than hard-code them in the engine
		float ofs[3] = {-0.13172054 * gl_doubleeyes.value, -0.078105450 * gl_doubleeyes.value, 25.347622 * gl_doubleeyes.value};

		// matrix for scaling and positioning the eyes
		float eyematrix[16] = {sc, 0, 0, 0, 0, sc, 0, 0, 0, 0, sc, 0, -ofs[0], -ofs[1], -ofs[2], 1};

		// and fix things up
		glMultMatrixf (eyematrix);
	}

	glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
	glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
Now do the same exercise and see how much better things are. As a bonus you get to use values of gl_doubleeyes other than 0 or 1 for a variable scaling.

Can this be called cheating? Yes, and no. It's client-side code, and any concept of preventing cheating in client-side code is fundamentally bogus. There's nothing to prevent a potential cheater from recompiling the engine with as many changes as they want (such as intercepting a switch to "eyes.mdl" and replacing it with a version of "player.mdl" that has a bright blue skin, for example).

Re: gl_doubleeyes fix

Posted: Tue Sep 25, 2012 6:28 pm
by Baker
This is funny. Last night before releasing ProQuake 4.90, I decided to kill the "gl_doubleyes" cvar (and leave the behavior to the default "gl_doubleyes" value of 1).