ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This file is part of the SourceMod/SourcePawn SDK. ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #if defined _vector_included ds@1952: #endinput ds@1952: #endif ds@1952: #define _vector_included ds@1952: ds@1952: /** ds@1952: * Calculates a vector's length. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @param squared If true, the result will be squared (for optimization). ds@1952: * @return Vector length (magnitude). ds@1952: */ ds@1952: native Float:GetVectorLength(const Float:vec[3], bool:squared=false); ds@1952: ds@1952: /** ds@1952: * Calculates the distance between two vectors. ds@1952: * ds@1952: * @param vec1 First vector. ds@1952: * @param vec2 Second vector. ds@1952: * @param squared If true, the result will be squared (for optimization). ds@1952: * @return Vector distance. ds@1952: */ ds@1952: native Float:GetVectorDistance(const Float:vec1[3], const Float:vec2[3], bool:squared=false); ds@1952: ds@1952: /** ds@1952: * Calculates the dot product of two vectors. ds@1952: * ds@1952: * @param vec1 First vector. ds@1952: * @param vec2 Second vector. ds@1952: * @return Dot product of the two vectors. ds@1952: */ ds@1952: native Float:GetVectorDotProduct(const Float:vec1[3], const Float:vec2[3]); ds@1952: ds@1952: /** ds@1952: * Computes the cross product of two vectors. Any input array can be the same ds@1952: * as the output array. ds@1952: * ds@1952: * @param vec1 First vector. ds@1952: * @param vec2 Second vector. ds@1952: * @param result Resultant vector. ds@1952: * @noreturn ds@1952: */ ds@1952: native GetVectorCrossProduct(const Float:vec1[3], const Float:vec2[3], Float:result[3]); ds@1952: ds@1952: /** ds@1952: * Normalizes a vector. The input array can be the same as the output array. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @param result Resultant vector. ds@1952: * @return Vector length. ds@1952: */ ds@1952: native Float:NormalizeVector(const Float:vec[3], Float:result[3]); ds@1952: ds@1952: /** ds@1952: * Returns vectors in the direction of an angle. ds@1952: * ds@1952: * @param angle Angle. ds@1952: * @param fwd Forward vector buffer or NULL_VECTOR. ds@1952: * @param right Right vector buffer or NULL_VECTOR. ds@1952: * @param up Up vector buffer or NULL_VECTOR. ds@1952: * @noreturn ds@1952: */ ds@1952: native GetAngleVectors(const Float:angle[3], Float:fwd[3], Float:right[3], Float:up[3]); ds@1952: ds@1952: /** ds@1952: * Returns angles from a vector. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @param angle Angle buffer. ds@1952: * @noreturn ds@1952: */ ds@1952: native GetVectorAngles(const Float:vec[3], Float:angle[3]); ds@1952: ds@1952: /** ds@1952: * Returns direction vectors from a vector. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @param right Right vector buffer or NULL_VECTOR. ds@1952: * @param up Up vector buffer or NULL_VECTOR. ds@1952: * @noreturn ds@1952: */ ds@1952: native GetVectorVectors(const Float:vec[3], Float:right[3], Float:up[3]); ds@1952: ds@1952: /** ds@1952: * Adds two vectors. It is safe to use either input buffer as an output ds@1952: * buffer. ds@1952: * ds@1952: * @param vec1 First vector. ds@1952: * @param vec2 Second vector. ds@1952: * @param result Result buffer. ds@1952: * @noreturn ds@1952: */ ds@1952: stock AddVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3]) ds@1952: { ds@1952: result[0] = vec1[0] + vec2[0]; ds@1952: result[1] = vec1[1] + vec2[1]; ds@1952: result[2] = vec1[2] + vec2[2]; ds@1952: } ds@1952: ds@1952: /** ds@1952: * Subtracts a vector from another vector. It is safe to use either input ds@1952: * buffer as an output buffer. ds@1952: * ds@1952: * @param vec1 First vector. ds@1952: * @param vec2 Second vector to subtract from first. ds@1952: * @param result Result buffer. ds@1952: * @noreturn ds@1952: */ ds@1952: stock SubtractVectors(const Float:vec1[3], const Float:vec2[3], Float:result[3]) ds@1952: { ds@1952: result[0] = vec1[0] - vec2[0]; ds@1952: result[1] = vec1[1] - vec2[1]; ds@1952: result[2] = vec1[2] - vec2[2]; ds@1952: } ds@1952: ds@1952: /** ds@1952: * Scales a vector. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @param scale Scale value. ds@1952: * @noreturn ds@1952: */ ds@1952: stock ScaleVector(Float:vec[3], Float:scale) ds@1952: { ds@1952: vec[0] *= scale; ds@1952: vec[1] *= scale; ds@1952: vec[2] *= scale; ds@1952: } ds@1952: ds@1952: /** ds@1952: * Negatives a vector. ds@1952: * ds@1952: * @param vec Vector. ds@1952: * @noreturn ds@1952: */ ds@1952: stock NegateVector(Float:vec[3]) ds@1952: { ds@1952: vec[0] = -vec[0]; ds@1952: vec[1] = -vec[1]; ds@1952: vec[2] = -vec[2]; ds@1952: } ds@1952: ds@1952: /** ds@1952: * Builds a vector from two points by subtracting the points. ds@1952: * ds@1952: * @param pt1 First point (to be subtracted from the second). ds@1952: * @param pt2 Second point. ds@1952: * @param output Output vector buffer. ds@1952: * @noreturn ds@1952: */ ds@1952: stock MakeVectorFromPoints(const Float:pt1[3], const Float:pt2[3], Float:output[3]) ds@1952: { ds@1952: output[0] = pt2[0] - pt1[0]; ds@1952: output[1] = pt2[1] - pt1[1]; ds@1952: output[2] = pt2[2] - pt1[2]; ds@1952: }