Vector

Tip

You can use VectorNormalize to normalize vectors.


Properties

  • float x -- Gets the X coordinate
  • float y -- Gets the Y coordinate
  • float z -- Gets the Z coordinate

Declaration

Vector vec;
Vector vec(x,y,z);
Vector vec = Vector(x,y,z);
Vector vec = Vector(x,y,z) - Vector(x,y,z);

Methods

  • void NormalizeInPlace()

Functions

  • float VectorNormalize(Vector& vec)
  • float DotProduct(Vector vec1, Vector vec2)
  • void AngleVectors(QAngle ang, Vector& forward, Vector& right, Vector& up)

Example

// Normalizes the vector for the helicopter
Vector dir = nextpatrol.GetAbsOrigin() - self.GetBaseEntity().GetAbsOrigin();
VectorNormalize(dir);


// This function is used to determine if the activator is facing the register
// 'self' is the register here
bool IsFacingRegister(CP3SObj@ Whom)
{
    Vector tempRight, tempUp;

    // Get a vector from owner origin to target origin
    Vector vecToTarget;
    vecToTarget = Whom.GetBaseEntity().WorldSpaceCenter() - self.GetBaseEntity().WorldSpaceCenter();
    vecToTarget.z = 0.0f;
    vecToTarget.NormalizeInPlace();

    // Get owner forward view vector
    Vector vecOwnerForward;
    AngleVectors( self.GetBaseEntity().EyeAngles(), vecOwnerForward, tempRight, tempUp );
    vecOwnerForward.z = 0.0f;
    vecOwnerForward.NormalizeInPlace();

    float flPosVsOwnerViewDot = DotProduct( vecToTarget, vecOwnerForward ); // Facing?

    if (flPosVsOwnerViewDot > 0.25f)
    {
        Printf("Facing the cash register!\n");
        return true;
    }

    return false;
}