Skip to content

Commit

Permalink
crosshair placement/alignment changes
Browse files Browse the repository at this point in the history
This has to do with issue #53.

As near as I can tell, the original reQuiem code was working on a couple of
assertions/assumptions.

1) The player's shots are a little off-center.

2) Crosshair images have equal height and width.

#1 is true of course, hence why people fiddle with cl_crossx and maybe
cl_crossy. It looks like JDH or maybe Joe of JoeQuake was trying to correct
for this by shifting the crosshair right and down by a half pixel.
Unfortunately shifting crosshair graphics by a half pixel makes them often
look like garbage.

(The half-pixel shift was only for the built-in 8x8 crosshair graphics. For
user-specified crosshair images, which could be of any dimensions, I don't at
all understand what the original code was trying to do. It gives the same
result as the built-ins if the user-specified image is 8x8, but if it is
larger then it is more and more off-center.)

#2 isn't necessarily true, but it is true for the built-in crosshairs, and
should be usually true for user-specified images. This is probably why the code
was treating the distances "from top to center" and "from left to center" as
one constant value, and then the distances "from right to center" and
"from bottom to center" as a different constant value. And also why for user-
specified crosshair images it was only looking at the image width as the
basis for calculating both vertical and horizontal positions.

==========

These changes shake things around in a few ways:

- Crosshair images are not assumed to have equal height and width.

- Crosshairs are placed dead-center on screen (as with original Quake). If the
user is not happy with that then they can adjust cl_crossx/cl_crossy like
grandpa used to do.

- User-specified crosshair images will be centered, regardless of their size.

I'm also clamping the crosshair graphic so that it doesn't "wraparound bleed",
which might otherwise happen for certain image dimensions and certain
cl_crossx/cl_crossy values.

==========

I'm not sure my interpretation of the original code's behavior is correct, or
that this fix is the right fix.

It also might be preferable to (for example) go ahead and put in a bias of 1
pixel for the crosshair X position. Or default cl_crossx to 1, or something
like that.

I'm just committing this now in case Spirit or any other interested party
wants to try it and give feedback.
  • Loading branch information
neogeographica committed Aug 5, 2014
1 parent bfdb7e7 commit eefeab6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ Draw_Crosshair -- joe, from FuhQuake
*/
void Draw_Crosshair (void)
{
float x, y, ofs1, ofs2, sh, th, sl, tl;
float x, y, ofsx, ofsy, sh, th, sl, tl;
byte col[4];
extern vrect_t scr_vrect;

Expand Down Expand Up @@ -1622,8 +1622,8 @@ void Draw_Crosshair (void)
if (crosshairimage_loaded)
{
GL_Bind (crosshairpic.texnum);
ofs1 = 4 - 4.0 / crosshairpic.width;
ofs2 = 4 + 4.0 / crosshairpic.width;
ofsx = crosshairpic.width / 2.0;
ofsy = crosshairpic.height / 2.0;
sh = crosshairpic.sh;
sl = crosshairpic.sl;
th = crosshairpic.th;
Expand All @@ -1632,24 +1632,26 @@ void Draw_Crosshair (void)
else
{
GL_Bind (crosshairtextures[(int)crosshair.value-1]);
ofs1 = 3.5;
ofs2 = 4.5;
ofsx = 4.0;
ofsy = 4.0;
tl = sl = 0;
sh = th = 1;
}

ofs1 *= /*(vid.width / 320) * */bound(0, crosshairsize.value, 20);
ofs2 *= /*(vid.width / 320) * */bound(0, crosshairsize.value, 20);
ofsx *= /*(vid.width / 320) * */bound(0, crosshairsize.value, 20);
ofsy *= /*(vid.width / 320) * */bound(0, crosshairsize.value, 20);

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBegin (GL_QUADS);
glTexCoord2f (sl, tl);
glVertex2f (x - ofs1, y - ofs1);
glVertex2f (x - ofsx, y - ofsy);
glTexCoord2f (sh, tl);
glVertex2f (x + ofs2, y - ofs1);
glVertex2f (x + ofsx, y - ofsy);
glTexCoord2f (sh, th);
glVertex2f (x + ofs2, y + ofs2);
glVertex2f (x + ofsx, y + ofsy);
glTexCoord2f (sl, th);
glVertex2f (x - ofs1, y + ofs2);
glVertex2f (x - ofsx, y + ofsy);
glEnd ();
}
/*else
Expand Down

0 comments on commit eefeab6

Please sign in to comment.