Originally Posted by

**sullydude**
Thanks Kenshin. That Explains it in good detail but what im wondering is how you set your crosshairs over the player? also How do you translate player coordinates to mouse movement over head?

The ViewMatrix is used for this. It's a structure (much like RefDef structure but this just stores your Viewangles.)

Here's how it looks:

Code:

typedef struct tViewMatrix
{
float AngleOfImpactX; //X Angle Of Impact
float AngleOfImpactY; //Y Angle Of Impact
float PlayerVelocity; //Speed Of Player
vec3_t WeaponPunchAngles[3]; //Angles at which the weapon moves as it fires
float weaponViewAngleY; //The View Angle Of Your Weapon In Terms Of The X-Axis
float weaponViewAngleX; //Same as the above but in terms of the Y-Axis
vec3_t weaponSway; //Vector Holding the Sway Movement of the weapon
vec3_t viewAxis[3]; //The 3D Location Of the View
vec3_t weaponOrigin; //3D Origin Of the weapon
}ViewMatrix_t;

I believe what you're asking is how do you translate a 3D (Y, X & Z) Co-Ordinate to a 2D (Y & X)?

If I could only find the post @-InSaNe- did describing it...

But I'll try to explain it....

Lets say we have a vector containing the enemies head location.

Vector3 EnemyHeadLoc;

To Transform it to 2D:

Code:

VectorSubtract ( EnemyHeadLoc, RefDef->CurrentOrigin, CalculatedPos ); //Subtract RefDef's Origin From The Bone's (Head) Location
VectorAngles ( CalculatedPos, VectorAngle ); //Convert the Vector To Angles and store it in VectorAngle (Now Z Angle isn't needed anymore)
* ( float* ) 0x1063898 += ( VectorAngle[ 0 ] -= RefDef->ViewAngles[ 0 ] ) ; //Add the difference of the calculated vector angle minus the current view angle to the ViewAngleX
* ( float* ) 0x106389C += ( VectorAngle[ 1 ] -= RefDef->ViewAngles[ 1 ] ) ; //Same as above but for Y

Here's those function for you:

Code:

void VectorSubtract ( float* v1, float* v2, float* out ) {
out[0] = v1[0] - v2[0];
out[1] = v1[1] - v2[1];
out[2] = v1[2] - v2[2];
}
void VectorAngles ( const float value1[3], float angles[3] ) {
float forward;
float yaw, pitch;
if ( value1[1] == 0 && value1[0] == 0 ) {
yaw = 0;
if ( value1[2] > 0 ) {
pitch = 90;
} else {
pitch = 270;
}
} else {
if ( value1[0] ) {
yaw = (float)( atan2 ( value1[1], value1[0] ) * 180 / M_PI );
} else if ( value1[1] > 0 ) {
yaw = 90;
} else {
yaw = 270;
}
if ( yaw < 0 ) {
yaw += 360;
}
forward = sqrt ( value1[0] * value1[0] + value1[1] * value1[1] );
pitch = (float)( atan2 ( value1[2], forward ) * 180 / M_PI );
if ( pitch < 0 ) {
pitch += 360;
}
}