Quake3World.com Forums
     Programming Discussion
        Spreadfire crosshair


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Spreadfire crosshair

Gomu Gomu no.....
Gomu Gomu no.....
Joined: 07 Aug 2003
Posts: 1902
PostPosted: 02-28-2005 01:56 AM           Profile Send private message  E-mail  Edit post Reply with quote


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



_________________
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-

-An eyeful a day is bloody fantastic!-


Top
                 

NOT OK
NOT OK
Joined: 03 Aug 2003
Posts: 1017
PostPosted: 02-28-2005 10:12 PM           Profile Send private message  E-mail  Edit post Reply with quote


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



_________________
Image


Top
                 

Gomu Gomu no.....
Gomu Gomu no.....
Joined: 07 Aug 2003
Posts: 1902
PostPosted: 03-01-2005 07:50 AM           Profile Send private message  E-mail  Edit post Reply with quote


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



_________________
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-

-An eyeful a day is bloody fantastic!-


Top
                 

Commander
Commander
Joined: 08 Jun 2022
Posts: 100
PostPosted: 10-10-2022 12:50 AM           Profile Send private message  E-mail  Edit post Reply with quote


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.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.