1.1 --- a/core/smn_vector.cpp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,205 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id$
1.33 - */
1.34 -
1.35 -#include "sm_globals.h"
1.36 -#include <vector.h>
1.37 -#include <mathlib/math_base.h>
1.38 -
1.39 -#define SET_VECTOR(addr, vec) \
1.40 - addr[0] = sp_ftoc(vec.x); \
1.41 - addr[1] = sp_ftoc(vec.y); \
1.42 - addr[2] = sp_ftoc(vec.z);
1.43 -
1.44 -static cell_t GetVectorLength(IPluginContext *pContext, const cell_t *params)
1.45 -{
1.46 - cell_t *addr;
1.47 -
1.48 - pContext->LocalToPhysAddr(params[1], &addr);
1.49 -
1.50 - Vector source(sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2]));
1.51 -
1.52 - if (!params[2])
1.53 - {
1.54 - return sp_ftoc(source.Length());
1.55 - } else {
1.56 - return sp_ftoc(source.LengthSqr());
1.57 - }
1.58 -}
1.59 -
1.60 -static cell_t GetVectorDistance(IPluginContext *pContext, const cell_t *params)
1.61 -{
1.62 - cell_t *addr1, *addr2;
1.63 -
1.64 - pContext->LocalToPhysAddr(params[1], &addr1);
1.65 - pContext->LocalToPhysAddr(params[2], &addr2);
1.66 -
1.67 - Vector source(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
1.68 - Vector dest(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
1.69 -
1.70 - if (!params[3])
1.71 - {
1.72 - return sp_ftoc(source.DistTo(dest));
1.73 - } else {
1.74 - return sp_ftoc(source.DistToSqr(dest));
1.75 - }
1.76 -}
1.77 -
1.78 -static cell_t GetVectorDotProduct(IPluginContext *pContext, const cell_t *params)
1.79 -{
1.80 - cell_t *addr1, *addr2;
1.81 -
1.82 - pContext->LocalToPhysAddr(params[1], &addr1);
1.83 - pContext->LocalToPhysAddr(params[2], &addr2);
1.84 -
1.85 - Vector source(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
1.86 - Vector dest(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
1.87 -
1.88 - return sp_ftoc(source.Dot(dest));
1.89 -}
1.90 -
1.91 -static cell_t GetVectorCrossProduct(IPluginContext *pContext, const cell_t *params)
1.92 -{
1.93 - cell_t *addr1, *addr2, *set;
1.94 -
1.95 - pContext->LocalToPhysAddr(params[1], &addr1);
1.96 - pContext->LocalToPhysAddr(params[2], &addr2);
1.97 - pContext->LocalToPhysAddr(params[3], &set);
1.98 -
1.99 - Vector vec1(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
1.100 - Vector vec2(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
1.101 -
1.102 - Vector vec3 = vec1.Cross(vec2);
1.103 -
1.104 - SET_VECTOR(set, vec3);
1.105 -
1.106 - return 1;
1.107 -}
1.108 -
1.109 -static cell_t GetAngleVectors(IPluginContext *pContext, const cell_t *params)
1.110 -{
1.111 - cell_t *ang_addr;
1.112 -
1.113 - pContext->LocalToPhysAddr(params[1], &ang_addr);
1.114 -
1.115 - QAngle angle(sp_ctof(ang_addr[0]), sp_ctof(ang_addr[1]), sp_ctof(ang_addr[2]));
1.116 - Vector fwd, right, up;
1.117 -
1.118 - AngleVectors(angle, &fwd, &right, &up);
1.119 -
1.120 - cell_t *addr_fwd, *addr_right, *addr_up;
1.121 - pContext->LocalToPhysAddr(params[2], &addr_fwd);
1.122 - pContext->LocalToPhysAddr(params[3], &addr_right);
1.123 - pContext->LocalToPhysAddr(params[4], &addr_up);
1.124 -
1.125 - SET_VECTOR(addr_fwd, fwd);
1.126 - SET_VECTOR(addr_right, right);
1.127 - SET_VECTOR(addr_up, up);
1.128 -
1.129 - return 1;
1.130 -}
1.131 -
1.132 -static cell_t GetVectorAngles(IPluginContext *pContext, const cell_t *params)
1.133 -{
1.134 - cell_t *vec_addr;
1.135 -
1.136 - pContext->LocalToPhysAddr(params[1], &vec_addr);
1.137 -
1.138 - Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
1.139 - QAngle angle;
1.140 -
1.141 - VectorAngles(vec, angle);
1.142 -
1.143 - cell_t *ang_addr;
1.144 - pContext->LocalToPhysAddr(params[2], &ang_addr);
1.145 -
1.146 - SET_VECTOR(ang_addr, angle);
1.147 -
1.148 - return 1;
1.149 -}
1.150 -
1.151 -static cell_t GetVectorVectors(IPluginContext *pContext, const cell_t *params)
1.152 -{
1.153 - cell_t *vec_addr;
1.154 -
1.155 - pContext->LocalToPhysAddr(params[1], &vec_addr);
1.156 -
1.157 - Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
1.158 - Vector right, up;
1.159 -
1.160 - VectorVectors(vec, right, up);
1.161 -
1.162 - cell_t *addr_right, *addr_up;
1.163 - pContext->LocalToPhysAddr(params[2], &addr_right);
1.164 - pContext->LocalToPhysAddr(params[3], &addr_up);
1.165 -
1.166 - SET_VECTOR(addr_right, right);
1.167 - SET_VECTOR(addr_up, up);
1.168 -
1.169 - return 1;
1.170 -}
1.171 -
1.172 -static cell_t NormalizeVector(IPluginContext *pContext, const cell_t *params)
1.173 -{
1.174 - cell_t *addr;
1.175 -
1.176 - pContext->LocalToPhysAddr(params[1], &addr);
1.177 -
1.178 - Vector source(sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2]));
1.179 - float length = VectorNormalize(source);
1.180 -
1.181 - pContext->LocalToPhysAddr(params[2], &addr);
1.182 - SET_VECTOR(addr, source);
1.183 -
1.184 - return sp_ftoc(length);
1.185 -}
1.186 -
1.187 -//:TODO: OMG remove this when we get the OB SDK!!1
1.188 -// as well as bitbuf.cpp (i write it here just to remind it)
1.189 -#if defined ORANGEBOX_BUILD && !defined __linux__
1.190 -float ham(float _X)
1.191 -{
1.192 - return sqrt(_X);
1.193 -}
1.194 -float (*pfSqrt)(float x) = ham;
1.195 -#endif
1.196 -
1.197 -REGISTER_NATIVES(vectorNatives)
1.198 -{
1.199 - {"GetAngleVectors", GetAngleVectors},
1.200 - {"GetVectorAngles", GetVectorAngles},
1.201 - {"GetVectorCrossProduct", GetVectorCrossProduct},
1.202 - {"GetVectorDistance", GetVectorDistance},
1.203 - {"GetVectorDotProduct", GetVectorDotProduct},
1.204 - {"GetVectorLength", GetVectorLength},
1.205 - {"GetVectorVectors", GetVectorVectors},
1.206 - {"NormalizeVector", NormalizeVector},
1.207 - {NULL, NULL}
1.208 -};