]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_crosshairs.c
eliminated qbyte type, now uses unsigned char throughout the engine for this purpose
[xonotic/darkplaces.git] / r_crosshairs.c
index 12ca524bfe462ef19d253e3708bb5dc68a7fa316..113ed591c0db3147803a11f24bc848274e05d136 100644 (file)
@@ -7,10 +7,10 @@ cvar_t crosshair_alpha = {CVAR_SAVE, "crosshair_alpha", "1"};
 cvar_t crosshair_flashspeed = {CVAR_SAVE, "crosshair_flashspeed", "2"};
 cvar_t crosshair_flashrange = {CVAR_SAVE, "crosshair_flashrange", "0.1"};
 cvar_t crosshair_size = {CVAR_SAVE, "crosshair_size", "1"};
-cvar_t crosshair_static = {CVAR_SAVE, "crosshair_static", "0"};
+cvar_t crosshair_static = {CVAR_SAVE, "crosshair_static", "1"};
 
 // must match NUMCROSSHAIRS in gl_draw.c
-#define NUMCROSSHAIRS 5
+#define NUMCROSSHAIRS 6
 
 void R_Crosshairs_Init(void)
 {
@@ -25,7 +25,7 @@ void R_Crosshairs_Init(void)
 void R_GetCrosshairColor(float *out)
 {
        int i;
-       qbyte *color;
+       unsigned char *color;
        float scale, base;
        if (cl.viewentity >= 1 && cl.viewentity <= cl.maxclients)
        {
@@ -37,7 +37,7 @@ void R_GetCrosshairColor(float *out)
        }
        else
                i = 15;
-       color = (qbyte *) &palette_complete[i];
+       color = (unsigned char *) &palette_complete[i];
        if (crosshair_flashspeed.value >= 0.01f)
                base = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value);
        else
@@ -62,6 +62,9 @@ void R_DrawWorldCrosshair(void)
        vec3_t v1, v2, spriteorigin;
        vec_t spritescale;
        vec4_t color;
+       trace_t trace;
+       if (r_letterbox.value)
+               return;
        if (crosshair_static.integer)
                return;
        num = crosshair.integer;
@@ -69,7 +72,7 @@ void R_DrawWorldCrosshair(void)
                return;
        if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active)
                return;
-       pic = Draw_CachePic(va("gfx/crosshair%i.tga", num));
+       pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true);
        if (!pic)
                return;
        R_GetCrosshairColor(color);
@@ -82,10 +85,12 @@ void R_DrawWorldCrosshair(void)
        AngleVectors(cl.viewangles, v2, NULL, NULL);
        //VectorCopy(r_vieworigin, v1);
        VectorMA(v1, 8192, v2, v2);
-       spritescale = CL_TraceLine(v1, v2, spriteorigin, NULL, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY) * (8192.0f / 40.0f) * crosshair_size.value;
+       trace = CL_TraceBox(v1, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
+       spritescale = trace.fraction * (8192.0f / 40.0f) * crosshair_size.value;
+       VectorCopy(trace.endpos, spriteorigin);
 
        // draw the sprite
-       R_DrawSprite(GL_SRC_ALPHA, GL_ONE, pic->tex, true, spriteorigin, r_viewright, r_viewup, spritescale, -spritescale, -spritescale, spritescale, color[0], color[1], color[2], color[3]);
+       R_DrawSprite(GL_ONE, GL_ONE, pic->tex, NULL, true, spriteorigin, r_viewright, r_viewup, spritescale, -spritescale, -spritescale, spritescale, color[0], color[1], color[2], color[3]);
 }
 
 void R_Draw2DCrosshair(void)
@@ -93,6 +98,8 @@ void R_Draw2DCrosshair(void)
        int num;
        cachepic_t *pic;
        vec4_t color;
+       if (r_letterbox.value)
+               return;
        if (!crosshair_static.integer)
                return;
        num = crosshair.integer;
@@ -100,11 +107,11 @@ void R_Draw2DCrosshair(void)
                return;
        if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active)
                return;
-       pic = Draw_CachePic(va("gfx/crosshair%i.tga", num));
+       pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true);
        if (pic)
        {
                R_GetCrosshairColor(color);
-               DrawQ_Pic((vid.conwidth - pic->width * crosshair_size.value) * 0.5f, (vid.conheight - pic->height * crosshair_size.value) * 0.5f, pic->name, pic->width * crosshair_size.value, pic->height * crosshair_size.value, color[0], color[1], color[2], color[3], 0);
+               DrawQ_Pic((vid_conwidth.integer - pic->width * crosshair_size.value) * 0.5f, (vid_conheight.integer - pic->height * crosshair_size.value) * 0.5f, pic->name, pic->width * crosshair_size.value, pic->height * crosshair_size.value, color[0], color[1], color[2], color[3], 0);
        }
 }