X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_crosshairs.c;h=c47f34b25d5617a5a57c4ca9be9331d089179ae0;hp=413ee14e7b3d348ba8ed3dbca3bb24ab3204d434;hb=544356c7bb6288760533142b8ab402f4d8d966ef;hpb=6ede411d2e01c293e840313a7409bb331ed1b97b diff --git a/r_crosshairs.c b/r_crosshairs.c index 413ee14e..c47f34b2 100644 --- a/r_crosshairs.c +++ b/r_crosshairs.c @@ -2,15 +2,12 @@ #include "quakedef.h" #include "cl_collision.h" -cvar_t crosshair_brightness = {CVAR_SAVE, "crosshair_brightness", "1"}; -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", "1"}; - -// must match NUMCROSSHAIRS in gl_draw.c -#define NUMCROSSHAIRS 6 +cvar_t crosshair_brightness = {CVAR_SAVE, "crosshair_brightness", "1", "how bright the crosshair should be"}; +cvar_t crosshair_alpha = {CVAR_SAVE, "crosshair_alpha", "1", "how opaque the crosshair should be"}; +cvar_t crosshair_flashspeed = {CVAR_SAVE, "crosshair_flashspeed", "2", "speed at which the crosshair flashes"}; +cvar_t crosshair_flashrange = {CVAR_SAVE, "crosshair_flashrange", "0.1", "how much the crosshair flashes"}; +cvar_t crosshair_size = {CVAR_SAVE, "crosshair_size", "1", "adjusts size of the crosshair on the screen"}; +cvar_t crosshair_static = {CVAR_SAVE, "crosshair_static", "1", "if 1 the crosshair is a 2D overlay, if 0 it is a sprite in the world indicating where your weapon will hit in standard quake mods (if the mod has the weapon somewhere else this won't be accurate)"}; void R_Crosshairs_Init(void) { @@ -25,7 +22,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 +34,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 @@ -70,27 +67,27 @@ void R_DrawWorldCrosshair(void) num = crosshair.integer; if (num < 1 || num > NUMCROSSHAIRS || cl.intermission) return; - if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active) + if (!cl.viewentity || !cl.entities[cl.viewentity].state_current.active) return; - pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true); + pic = r_crosshairs[num]; if (!pic) return; R_GetCrosshairColor(color); // trace the shot path up to a certain distance - VectorCopy(cl_entities[cl.viewentity].render.origin, v1); + Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, v1); v1[2] += 16; // HACK: this depends on the QC // get the forward vector for the gun (not the view) AngleVectors(cl.viewangles, v2, NULL, NULL); - //VectorCopy(r_vieworigin, v1); + //VectorCopy(r_view.origin, v1); VectorMA(v1, 8192, v2, v2); - trace = CL_TraceBox(v1, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false); + trace = CL_TraceBox(v1, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY, false); spritescale = trace.fraction * (8192.0f / 40.0f) * crosshair_size.value; VectorCopy(trace.endpos, spriteorigin); // draw the sprite - 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]); + R_DrawSprite(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, pic->tex, NULL, true, spriteorigin, r_view.right, r_view.up, spritescale, -spritescale, -spritescale, spritescale, color[0], color[1], color[2], color[3]); } void R_Draw2DCrosshair(void) @@ -105,13 +102,13 @@ void R_Draw2DCrosshair(void) num = crosshair.integer; if (num < 1 || num > NUMCROSSHAIRS || cl.intermission) return; - if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active) + if (!cl.viewentity || !cl.entities[cl.viewentity].state_current.active) return; - pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true); + pic = r_crosshairs[num]; if (pic) { R_GetCrosshairColor(color); - 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); + DrawQ_Pic((vid_conwidth.integer - pic->width * crosshair_size.value) * 0.5f, (vid_conheight.integer - pic->height * crosshair_size.value) * 0.5f, pic, pic->width * crosshair_size.value, pic->height * crosshair_size.value, color[0], color[1], color[2], color[3], 0); } }