*edit* what I wrote applies as much to HL as to any other engine (such as RTCW)
Use the player's angles, flatten them if needed
Code:
Vector v_myangles = pPlayerEdict->v.angles;
v_myangles.z = 0;
Add 45° on one side (horizontal plane), make sure it stays in bounds
Code:
v_myangles.y += 45;
if (v_myangles.y > 180)
v_myangles.y -= 360;
Build a referential out of it
Code:
MAKE_VECTORS (v_myangles);
then use the forward, right and upwards vectors generated to fire your traceline
Code:
TraceResult tr;
TRACE_LINE (pPlayerEdict->v.origin,
pPlayerEdict->v.origin + (gpGlobals->v_forward * 9999),
ignore_monsters,
pPlayerEdict,
&tr);
Do the same for the other side.
That's it.
If you want something faster than MAKE_VECTORS(), or if MAKE_VECTORS() is not available for your engine, well it can look like this:
Code:
void BuildReferential (const Vector &v_angles)
{
// this function builds a 3D referential from a view angle, that is to say, the relative
// "forward", "right" and "upwards" direction that a player would have if he were facing this
// view angle. World angles are stored in Vector structs too, the "x" component corresponding
// to the X angle (horizontal angle), and the "y" component corresponding to the Y angle
// (vertical angle). Beware, heavy math here.
static float degrees_to_radians = 2 * MATH_PI / 360;
float angle;
float sin_pitch;
float sin_yaw;
float sin_roll;
float cos_pitch;
float cos_yaw;
float cos_roll;
// compute the sin and cosine of the pitch component
angle = v_angles.x * degrees_to_radians;
sin_pitch = sinf (angle);
cos_pitch = cosf (angle);
// compute the sin and cosine of the yaw component
angle = v_angles.y * degrees_to_radians;
sin_yaw = sinf (angle);
cos_yaw = cosf (angle);
// compute the sin and cosine of the roll component
angle = v_angles.z * degrees_to_radians;
sin_roll = sinf (angle);
cos_roll = cosf (angle);
// build the FORWARD vector
referential.v_forward.x = cos_pitch * cos_yaw;
referential.v_forward.y = cos_pitch * sin_yaw;
referential.v_forward.z = -sin_pitch;
// build the RIGHT vector
referential.v_right.x = (-(sin_roll * sin_pitch * cos_yaw) - (cos_roll * -sin_yaw));
referential.v_right.y = (-(sin_roll * sin_pitch * sin_yaw) - (cos_roll * cos_yaw));
referential.v_right.z = -(sin_roll * cos_pitch);
// build the UPWARDS vector
referential.v_up.x = ((cos_roll * sin_pitch * cos_yaw) - (sin_roll * -sin_yaw));
referential.v_up.y = ((cos_roll * sin_pitch * sin_yaw) - (sin_roll * cos_yaw));
referential.v_up.z = cos_roll * cos_pitch;
return;
}
Comes straight from RACC
If you're using only the forward vector you can get rid of 60% of this function
Code:
Vector BuildForwardVector (const Vector &v_angles)
{
// this function builds a "forward" vector from a view angle
static float degrees_to_radians = 2 * MATH_PI / 360;
float angle;
float sin_pitch;
float sin_yaw;
float cos_pitch;
float cos_yaw;
Vector v_forward;
// compute the sin and cosine of the pitch component
angle = v_angles.x * degrees_to_radians;
sin_pitch = sinf (angle);
cos_pitch = cosf (angle);
// compute the sin and cosine of the yaw component
angle = v_angles.y * degrees_to_radians;
sin_yaw = sinf (angle);
cos_yaw = cosf (angle);
// build the FORWARD vector
v_forward.x = cos_pitch * cos_yaw;
v_forward.y = cos_pitch * sin_yaw;
v_forward.z = -sin_pitch;
return (v_forward);
}
Nothing faster - AFAIK.