It's done using camera movement variables, well here is code, please keep in mind Q3 SDK licensesTorr Samaho wrote:The current bobbing is just the first implementation I could come up with. I'm open for suggestions on how to improve it. Since I don't know how the Quake 3 bobbing is achieved (and don't have the time to investigate this), I need specific suggestion on how the weapon should bob (best in terms of translations and rotations).
 
Code: Select all
static void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles ) {
	float	scale;
	int		delta;
	float	fracsin;
	VectorCopy( cg.refdef_current->vieworg, origin );
	VectorCopy( cg.refdefViewAngles, angles );
	
	// on odd legs, invert some angles
	if ( cg.bobcycle & 1 ) {
		scale = -cg.xyspeed;
	} else {
		scale = cg.xyspeed;
	}
	// gun angles from bobbing
	angles[ROLL]	+= scale		* cg.bobfracsin * 0.005;
	angles[YAW]	+= scale		* cg.bobfracsin * 0.01;
	angles[PITCH]	+= cg.xyspeed	* cg.bobfracsin * 0.005;
	// drop the weapon when landing
	delta = cg.time - cg.landTime;
	if ( delta < LAND_DEFLECT_TIME ) {
		origin[2] += cg.landChange*0.25 * delta / LAND_DEFLECT_TIME;
	} else if ( delta < LAND_DEFLECT_TIME + LAND_RETURN_TIME ) {
		origin[2] += cg.landChange*0.25 * 
			(LAND_DEFLECT_TIME + LAND_RETURN_TIME - delta) / LAND_RETURN_TIME;
	}
	fracsin = sin( cg.time * 0.001 );
	angles[ROLL] += scale * fracsin * 0.01;
	angles[YAW] += scale * fracsin * 0.01;
	angles[PITCH] += scale * fracsin * 0.01;
	// RF, subtract the kickAngles
	VectorMA( angles, -1.0, cg.kickAngles, angles );
}bobcycle is updated every client frame
Code: Select all
	if( cg.bobfracsin > 0 && !ps->bobCycle ) {
		cg.lastvalidBobcycle = cg.bobcycle;
		cg.lastvalidBobfracsin = cg.bobfracsin;
	}
	cg.bobcycle = ( ps->bobCycle & 128 ) >> 7;
	cg.bobfracsin = fabs( sin( ( ps->bobCycle & 127 ) / 127.0 * M_PI ) );
	cg.xyspeed = sqrt( ps->velocity[0] * ps->velocity[0] + ps->velocity[1] * ps->velocity[1] );


