Spreadfire crosshair

Locked
corncobman
Posts: 304
Joined: Fri Aug 08, 2003 7:00 am

Spreadfire crosshair

Post by corncobman »

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: Select all


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)-

[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Lenard
Posts: 737
Joined: Mon Aug 04, 2003 7:00 am

Post by Lenard »

That is a really great accomplishment, don't get me wrong, but could there possibly be a point to this? Let's brainstorm.
[img]http://myspace-001.vo.llnwd.net/00555/10/05/555355001_l.gif[/img]
corncobman
Posts: 304
Joined: Fri Aug 08, 2003 7:00 am

Post by corncobman »

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

Code: Select all

//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)-

[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
User avatar
LegendGuard
Posts: 121
Joined: Thu Jun 09, 2022 7:35 am

Re: Spreadfire crosshair

Post by LegendGuard »

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: Select all

	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.
Locked