Quake3World.com
https://www.quake3world.com/forum/

Spreadfire crosshair
https://www.quake3world.com/forum/viewtopic.php?f=16&t=1314
Page 1 of 1

Author:  corncobman [ 02-28-2005 01:56 AM ]
Post subject:  Spreadfire crosshair

After mucking around with the draw crosshair function, I have managed to get the game to draw 3 crosshairs on screen when the player has the spreadfire powerup.

The only problem is that the screen size throws it off completely. If I get it worknig for a large screenshot it doesn't work for a large screen size.

I am posting my code below, maybe you can see something I missed. You can also steal it if you want :P.

Code:

if((cg.predictedPlayerState.powerups[PW_SPREAD] &&
   ((cg.predictedPlayerState.weapon==WP_MACHINEGUN)||
   (cg.predictedPlayerState.weapon==WP_RAILGUN)||
   (cg.predictedPlayerState.weapon==WP_LIGHTNING)||
   (cg.predictedPlayerState.weapon==WP_ROCKET_LAUNCHER)||
   (cg.predictedPlayerState.weapon==WP_PLASMAGUN)||
   (cg.predictedPlayerState.weapon==WP_BFG)||
   (cg.predictedPlayerState.weapon==WP_SHOTGUN))))
   {
      trace_t tr, tr2;
      float adjacent, hypothenuse, opposite, angle;// width, offset,
      vec3_t forward, right, up, muzzle, endpoint, endpoint2, angles,  dir, dir1, dir2;

      angle = 10;

      VectorCopy( cg.snap->ps.origin, muzzle );
      muzzle[2] += cg.snap->ps.viewheight;
      AngleVectors( cg.snap->ps.viewangles, forward, NULL, NULL );
      VectorMA( muzzle, 14, forward, muzzle );

      AngleVectors( cg.refdefViewAngles, forward, right, up );

      VectorMA(muzzle, 8191, forward, endpoint);

      CG_Trace( &tr, muzzle, NULL, NULL, endpoint, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr.endpos, muzzle, dir1);
      adjacent = VectorLength( dir1 );

      vectoangles(dir1, angles);

      VectorMA(forward, 0.1, right, dir);
      VectorMA(muzzle, 8191, dir, endpoint2);

      CG_Trace( &tr2, muzzle, NULL, NULL, endpoint2, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr2.endpos, muzzle, dir2);

      hypothenuse = VectorLength( dir2);

//CORNCOBMAN - trigonometry turned out to be useful afterall, *<8O)
      opposite = (cg.refdef.width * cg.refdef.width) + (hypothenuse * -sin(angle));

      opposite = ((opposite / (cg.refdef.width / 7.3)) / cg.refdef.fov_x) - 8;

   //   CG_Printf(va("opposite1: %f\n", opposite));

      opposite *= cgs.screenXScale;


      trap_R_DrawStretchPic( x + cg.refdef.x + opposite  + 0.5 * (cg.refdef.width - d),
         y + cg.refdef.y + 0.5 * (cg.refdef.height - d),
         d, d, 0, 0, 1, 1, hShader );

      VectorMA(forward, -0.1, right, dir);
      VectorMA(muzzle, 8191, dir, endpoint2);

      CG_Trace( &tr2, muzzle, NULL, NULL, endpoint2, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr2.endpos, muzzle, dir2);

      hypothenuse = VectorLength( dir2);

      opposite = (cg.refdef.width * cg.refdef.width) + (hypothenuse * -sin(angle));

      opposite = ((opposite / (cg.refdef.width / 7.3)) / cg.refdef.fov_x) - 8;

      opposite *= cgs.screenXScale;


      trap_R_DrawStretchPic( x + cg.refdef.x - opposite + 0.5 * (cg.refdef.width - d),
         y + cg.refdef.y + 0.5 * (cg.refdef.height - d),
         d, d, 0, 0, 1, 1, hShader );
   }
//END CORNCOBMAN


Author:  Lenard [ 02-28-2005 10:12 PM ]
Post subject: 

That is a really great accomplishment, don't get me wrong, but could there possibly be a point to this? Let's brainstorm.

Author:  corncobman [ 03-01-2005 07:50 AM ]
Post subject: 

I seem to have fixed it, I haven't tested extensively but here is the code in case anyone is interested:


Code:
//CORNCOBMAN - spreadfire corsshairs
   if((cg.predictedPlayerState.powerups[PW_SPREAD] &&
   ((cg.predictedPlayerState.weapon==WP_MACHINEGUN)||
   (cg.predictedPlayerState.weapon==WP_RAILGUN)||
   (cg.predictedPlayerState.weapon==WP_LIGHTNING)||
   (cg.predictedPlayerState.weapon==WP_ROCKET_LAUNCHER)||
   (cg.predictedPlayerState.weapon==WP_PLASMAGUN)||
   (cg.predictedPlayerState.weapon==WP_BFG)||
   (cg.predictedPlayerState.weapon==WP_SHOTGUN))))
   {
      trace_t tr, tr2;
      float adjacent, hypothenuse, opposite, angle;// width, offset,
      vec3_t forward, right, up, muzzle, endpoint, endpoint2, angles,  dir, dir1, dir2;

      angle = 10;

      VectorCopy( cg.snap->ps.origin, muzzle );
      muzzle[2] += cg.snap->ps.viewheight;
      AngleVectors( cg.snap->ps.viewangles, forward, NULL, NULL );
      VectorMA( muzzle, 14, forward, muzzle );

      AngleVectors( cg.refdefViewAngles, forward, right, up );

      VectorMA(muzzle, 8191, forward, endpoint);

      CG_Trace( &tr, muzzle, NULL, NULL, endpoint, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr.endpos, muzzle, dir1);
      adjacent = VectorLength( dir1 );

      vectoangles(dir1, angles);

      VectorMA(forward, 0.1, right, dir);
      VectorMA(muzzle, 8191, dir, endpoint2);

      CG_Trace( &tr2, muzzle, NULL, NULL, endpoint2, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr2.endpos, muzzle, dir2);

      hypothenuse = VectorLength( dir2);

//CORNCOBMAN - trigonometry turned out to be useful afterall, *<8O)
      opposite = (hypothenuse * -sin(angle));

      opposite = ((cg.refdef.width*1.7)*(108-cg.refdef.fov_x))+opposite;

      opposite /= cg.refdef.width/1.1;

      opposite *= cgs.screenXScale;
      
      trap_R_DrawStretchPic( x + cg.refdef.x + opposite  + 0.5 * (cg.refdef.width - d),
         y + cg.refdef.y + 0.5 * (cg.refdef.height - d),
         d, d, 0, 0, 1, 1, hShader );

      VectorMA(forward, -0.1, right, dir);
      VectorMA(muzzle, 8191, dir, endpoint2);

      CG_Trace( &tr2, muzzle, NULL, NULL, endpoint2, cg.clientNum, MASK_SHOT );

      VectorSubtract(tr2.endpos, muzzle, dir2);

      hypothenuse = VectorLength( dir2);

      opposite = (hypothenuse * -sin(angle));

      opposite = ((cg.refdef.width*1.7)*(108-cg.refdef.fov_x))+opposite;

      opposite /= cg.refdef.width/1.1;

      opposite *= cgs.screenXScale;

      trap_R_DrawStretchPic( x + cg.refdef.x - opposite + 0.5 * (cg.refdef.width - d),
         y + cg.refdef.y + 0.5 * (cg.refdef.height - d),
         d, d, 0, 0, 1, 1, hShader );
   }
//END CORNCOBMAN


Author:  LegendGuard [ 10-10-2022 12:50 AM ]
Post subject:  Re: Spreadfire crosshair

That's dual eyed crosshair.

Image

I just modified a bit the code, I put PW_QUAD to test. d variable doesn't exist, you're trying to use w and h variables, the default ones from Q3 code:
Code:
   w = h = cg_crosshairSize.value;


I guess this fits for dual weapons, I wonder if there's akimbo source code in some place, just I found compiled mods though.

I think this topic should (or must) be in Programming Discussion section.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/