plugins/include/vector.inc
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
ds@1952
    33
#if defined _vector_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _vector_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Calculates a vector's length.
ds@1952
    40
 *
ds@1952
    41
 * @param vec		Vector.
ds@1952
    42
 * @param squared	If true, the result will be squared (for optimization).
ds@1952
    43
 * @return			Vector length (magnitude).			
ds@1952
    44
 */
ds@1952
    45
native Float:GetVectorLength(const Float:vec[3], bool:squared=false);
ds@1952
    46
ds@1952
    47
/**
ds@1952
    48
 * Calculates the distance between two vectors.
ds@1952
    49
 *
ds@1952
    50
 * @param vec1		First vector.
ds@1952
    51
 * @param vec2		Second vector.
ds@1952
    52
 * @param squared	If true, the result will be squared (for optimization).
ds@1952
    53
 * @return			Vector distance.
ds@1952
    54
 */
ds@1952
    55
native Float:GetVectorDistance(const Float:vec1[3], const Float:vec2[3], bool:squared=false);
ds@1952
    56
ds@1952
    57
/**
ds@1952
    58
 * Calculates the dot product of two vectors.
ds@1952
    59
 *
ds@1952
    60
 * @param vec1		First vector.
ds@1952
    61
 * @param vec2		Second vector.
ds@1952
    62
 * @return			Dot product of the two vectors.
ds@1952
    63
 */
ds@1952
    64
native Float:GetVectorDotProduct(const Float:vec1[3], const Float:vec2[3]);
ds@1952
    65
ds@1952
    66
/**
ds@1952
    67
 * Computes the cross product of two vectors.  Any input array can be the same 
ds@1952
    68
 * as the output array.
ds@1952
    69
 *
ds@1952
    70
 * @param vec1		First vector.
ds@1952
    71
 * @param vec2		Second vector.
ds@1952
    72
 * @param result	Resultant vector.
ds@1952
    73
 * @noreturn
ds@1952
    74
 */
ds@1952
    75
native GetVectorCrossProduct(const Float:vec1[3], const Float:vec2[3], Float:result[3]);
ds@1952
    76
ds@1952
    77
/**
ds@1952
    78
 * Normalizes a vector.  The input array can be the same as the output array.
ds@1952
    79
 *
ds@1952
    80
 * @param vec		Vector.
ds@1952
    81
 * @param result	Resultant vector.
ds@1952
    82
 * @return			Vector length.
ds@1952
    83
 */
ds@1952
    84
native Float:NormalizeVector(const Float:vec[3], Float:result[3]);
ds@1952
    85
ds@1952
    86
/**
ds@1952
    87
 * Returns vectors in the direction of an angle.
ds@1952
    88
 *
ds@1952
    89
 * @param angle		Angle.
ds@1952
    90
 * @param fwd		Forward vector buffer or NULL_VECTOR.
ds@1952
    91
 * @param right		Right vector buffer or NULL_VECTOR.
ds@1952
    92
 * @param up		Up vector buffer or NULL_VECTOR.
ds@1952
    93
 * @noreturn
ds@1952
    94
 */
ds@1952
    95
native GetAngleVectors(const Float:angle[3], Float:fwd[3], Float:right[3], Float:up[3]);
ds@1952
    96
ds@1952
    97
/**
ds@1952
    98
 * Returns angles from a vector.
ds@1952
    99
 *
ds@1952
   100
 * @param vec		Vector.
ds@1952
   101
 * @param angle		Angle buffer.
ds@1952
   102
 * @noreturn
ds@1952
   103
 */
ds@1952
   104
native GetVectorAngles(const Float:vec[3], Float:angle[3]);
ds@1952
   105
ds@1952
   106
/**
ds@1952
   107
 * Returns direction vectors from a vector.
ds@1952
   108
 *
ds@1952
   109
 * @param vec		Vector.
ds@1952
   110
 * @param right		Right vector buffer or NULL_VECTOR.
ds@1952
   111
 * @param up		Up vector buffer or NULL_VECTOR.
ds@1952
   112
 * @noreturn
ds@1952
   113
 */
ds@1952
   114
native GetVectorVectors(const Float:vec[3], Float:right[3], Float:up[3]);
ds@1952
   115
ds@1952
   116
/**
ds@1952
   117
 * Adds two vectors.  It is safe to use either input buffer as an output 
ds@1952
   118
 * buffer.
ds@1952
   119
 * 
ds@1952
   120
 * @param vec1		First vector.
ds@1952
   121
 * @param vec2		Second vector.
ds@1952
   122
 * @param result	Result buffer.
ds@1952
   123
 * @noreturn
ds@1952
   124
 */
ds@1952
   125
stock AddVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3])
ds@1952
   126
{
ds@1952
   127
	result[0] = vec1[0] + vec2[0];
ds@1952
   128
	result[1] = vec1[1] + vec2[1];
ds@1952
   129
	result[2] = vec1[2] + vec2[2];
ds@1952
   130
}
ds@1952
   131
ds@1952
   132
/**
ds@1952
   133
 * Subtracts a vector from another vector.  It is safe to use either input 
ds@1952
   134
 * buffer as an output buffer.
ds@1952
   135
 * 
ds@1952
   136
 * @param vec1		First vector.
ds@1952
   137
 * @param vec2		Second vector to subtract from first.
ds@1952
   138
 * @param result	Result buffer.
ds@1952
   139
 * @noreturn
ds@1952
   140
 */
ds@1952
   141
stock SubtractVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3])
ds@1952
   142
{
ds@1952
   143
	result[0] = vec1[0] - vec2[0];
ds@1952
   144
	result[1] = vec1[1] - vec2[1];
ds@1952
   145
	result[2] = vec1[2] - vec2[2];
ds@1952
   146
}
ds@1952
   147
ds@1952
   148
/**
ds@1952
   149
 * Scales a vector.
ds@1952
   150
 *
ds@1952
   151
 * @param vec		Vector.
ds@1952
   152
 * @param scale		Scale value.
ds@1952
   153
 * @noreturn
ds@1952
   154
 */
ds@1952
   155
stock ScaleVector(Float:vec[3], Float:scale)
ds@1952
   156
{
ds@1952
   157
	vec[0] *= scale;
ds@1952
   158
	vec[1] *= scale;
ds@1952
   159
	vec[2] *= scale;
ds@1952
   160
}
ds@1952
   161
ds@1952
   162
/**
ds@1952
   163
 * Negatives a vector.
ds@1952
   164
 *
ds@1952
   165
 * @param vec		Vector.
ds@1952
   166
 * @noreturn
ds@1952
   167
 */
ds@1952
   168
stock NegateVector(Float:vec[3])
ds@1952
   169
{
ds@1952
   170
	vec[0] = -vec[0];
ds@1952
   171
	vec[1] = -vec[1];
ds@1952
   172
	vec[2] = -vec[2];
ds@1952
   173
}
ds@1952
   174
ds@1952
   175
/**
ds@1952
   176
 * Builds a vector from two points by subtracting the points.
ds@1952
   177
 *
ds@1952
   178
 * @param pt1		First point (to be subtracted from the second).
ds@1952
   179
 * @param pt2		Second point.
ds@1952
   180
 * @param output	Output vector buffer.
ds@1952
   181
 * @noreturn
ds@1952
   182
 */
ds@1952
   183
stock MakeVectorFromPoints(const Float:pt1[3], const Float:pt2[3], Float:output[3])
ds@1952
   184
{
ds@1952
   185
	output[0] = pt2[0] - pt1[0];
ds@1952
   186
	output[1] = pt2[1] - pt1[1];
ds@1952
   187
	output[2] = pt2[2] - pt1[2];
ds@1952
   188
}