plugins/include/vector.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Aug 10 09:16:58 2007 +0000 (2007-08-10)
changeset 1301 a9e6cd2953f2
parent 1155 7280db5fdd31
child 1330 ab94316bb52b
permissions -rw-r--r--
Added replicate and notify parameters to ResetConVar() - these were already available for SetConVarX()
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _vector_included
    17  #endinput
    18 #endif
    19 #define _vector_included
    20 
    21 /**
    22  * Calculates a vector's length.
    23  *
    24  * @param vec		Vector.
    25  * @param squared	If true, the result will be squared (for optimization).
    26  * @return			Vector length (magnitude).			
    27  */
    28 native Float:GetVectorLength(const Float:vec[3], bool:squared=false);
    29 
    30 /**
    31  * Calculates the distance between two vectors.
    32  *
    33  * @param vec1		First vector.
    34  * @param vec2		Second vector.
    35  * @param squared	If true, the result will be squared (for optimization).
    36  * @return			Vector distance.
    37  */
    38 native Float:GetVectorDistance(const Float:vec1[3], const Float:vec2[3], bool:squared=false);
    39 
    40 /**
    41  * Calculates the dot product of two vectors.
    42  *
    43  * @param vec1		First vector.
    44  * @param vec2		Second vector.
    45  * @return			Dot product of the two vectors.
    46  */
    47 native Float:GetVectorDotProduct(const Float:vec1[3], const Float:vec2[3]);
    48 
    49 /**
    50  * Computes the cross product of two vectors.  Any input array can be the same 
    51  * as the output array.
    52  *
    53  * @param vec1		First vector.
    54  * @param vec2		Second vector.
    55  * @param result	Resultant vector.
    56  * @noreturn
    57  */
    58 native GetVectorCrossProduct(const Float:vec1[3], const Float:vec2[3], Float:result[3]);
    59 
    60 /**
    61  * Normalizes a vector.  The input array can be the same as the output array.
    62  *
    63  * @param vec		Vector.
    64  * @param result	Resultant vector.
    65  * @return			Vector length.
    66  */
    67 native Float:NormalizeVector(const Float:vec[3], Float:result[3]);
    68 
    69 /**
    70  * Returns vectors in the direction of an angle.
    71  *
    72  * @param angle		Angle.
    73  * @param fwd		Forward vector buffer or NULL_VECTOR.
    74  * @param right		Right vector buffer or NULL_VECTOR.
    75  * @param up		Up vector buffer or NULL_VECTOR.
    76  * @noreturn
    77  */
    78 native GetAngleVectors(const Float:angle[3], Float:fwd[3], Float:right[3], Float:up[3]);
    79 
    80 /**
    81  * Returns angles from a vector.
    82  *
    83  * @param vec		Vector.
    84  * @param angle		Angle buffer.
    85  * @noreturn
    86  */
    87 native GetVectorAngles(const Float:vec[3], Float:angle[3]);
    88 
    89 /**
    90  * Returns direction vectors from a vector.
    91  *
    92  * @param vec		Vector.
    93  * @param right		Right vector buffer or NULL_VECTOR.
    94  * @param up		Up vector buffer or NULL_VECTOR.
    95  * @noreturn
    96  */
    97 native GetVectorVectors(const Float:vec[3], Float:right[3], Float:up[3]);
    98 
    99 /**
   100  * Adds two vectors.  It is safe to use either input buffer as an output 
   101  * buffer.
   102  * 
   103  * @param vec1		First vector.
   104  * @param vec2		Second vector.
   105  * @param result	Result buffer.
   106  * @noreturn
   107  */
   108 stock AddVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3])
   109 {
   110 	result[0] = vec1[0] + vec2[0];
   111 	result[1] = vec1[1] + vec2[1];
   112 	result[2] = vec1[2] + vec2[2];
   113 }
   114 
   115 /**
   116  * Subtracts a vector from another vector.  It is safe to use either input 
   117  * buffer as an output buffer.
   118  * 
   119  * @param vec1		First vector.
   120  * @param vec2		Second vector to subtract from first.
   121  * @param result	Result buffer.
   122  * @noreturn
   123  */
   124 stock SubtractVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3])
   125 {
   126 	result[0] = vec1[0] - vec2[0];
   127 	result[1] = vec1[1] - vec2[1];
   128 	result[2] = vec1[2] - vec2[2];
   129 }
   130 
   131 /**
   132  * Scales a vector.
   133  *
   134  * @param vec		Vector.
   135  * @param scale		Scale value.
   136  * @noreturn
   137  */
   138 stock ScaleVector(Float:vec[3], Float:scale)
   139 {
   140 	vec[0] *= scale;
   141 	vec[1] *= scale;
   142 	vec[2] *= scale;
   143 }
   144 
   145 /**
   146  * Negatives a vector.
   147  *
   148  * @param vec		Vector.
   149  * @noreturn
   150  */
   151 stock NegateVector(Float:vec[3])
   152 {
   153 	vec[0] = -vec[0];
   154 	vec[1] = -vec[1];
   155 	vec[2] = -vec[2];
   156 }
   157 
   158 /**
   159  * Builds a vector from two points by subtracting the points.
   160  *
   161  * @param pt1		First point (to be subtracted from the second).
   162  * @param pt2		Second point.
   163  * @param output	Output vector buffer.
   164  * @noreturn
   165  */
   166 stock MakeVectorFromPoints(const Float:pt1[3], const Float:pt2[3], Float:output[3])
   167 {
   168 	output[0] = pt2[0] - pt1[0];
   169 	output[1] = pt2[1] - pt1[1];
   170 	output[2] = pt2[2] - pt1[2];
   171 }