Raised This Month: $12 Target: $400
 3% 

[INC] Vector helpers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 05-29-2018 , 20:03   [INC] Vector helpers
Reply With Quote #1

Extends functionality of SourceMod vectors so you don't have to iterate through array blocks every time you want to do a simple operation on a vector. More or less self explanatory what each of them do, but there is some documentation in there

Included:
  • VectorCopy
  • VectorLerp
  • VectorMulAdd
  • VectorMin
  • VectorMax
  • VectorRand
  • VectorRotate

Some helper functions
  • AnglesNormalize - ensures an angle is within Valves tolerance
  • AngleNormalize - same, but for a single value
  • SinCos - fills in 2 floats with the sin and cosine of the provided radian
  • AngleMatrix - Given an angle, creates a rotation matrix; to be used with VectorRotate
Attached Files
File Type: inc vector_helpers.inc (5.2 KB, 290 views)
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it

Last edited by xXDeathreusXx; 08-24-2018 at 20:09. Reason: New file
xXDeathreusXx is offline
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 08-24-2018 , 20:08   Re: [INC] Vector helpers
Reply With Quote #2

New file uploaded, added:
VectorsEqual
VectorIsZero
VectorRotateOnAxis
VectorMatrix
MatrixVectors
MatrixAngles
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it

Last edited by xXDeathreusXx; 08-24-2018 at 20:09.
xXDeathreusXx is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-25-2018 , 13:11   Re: [INC] Vector helpers
Reply With Quote #3

Saves me lots of time, thanks.
mug1wara is offline
Grzyboo
Junior Member
Join Date: Apr 2011
Old 04-14-2019 , 08:02   Re: [INC] Vector helpers
Reply With Quote #4

Code:
stock void VectorRotate(float vec[3], const float matrix[3][3])
{
	vec[0] = GetVectorDotProduct(vec, matrix[0]);
	vec[1] = GetVectorDotProduct(vec, matrix[1]);
	vec[2] = GetVectorDotProduct(vec, matrix[2]);
}
This is fundamentally wrong. You are using already rotated vector values when rotating in next axes.
The rotation matrix values don't seem to be correct either.

Basically, you shouldn't use this .inc file, unless you want to face bugs that are really hard to debug.

Last edited by Grzyboo; 04-14-2019 at 08:07.
Grzyboo is offline
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 04-15-2019 , 03:36   Re: [INC] Vector helpers
Reply With Quote #5

Just copy pasted what was in mathlib, only thing I wrote myself which could be completely wrong is VectorRotateOnAxis
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it
xXDeathreusXx is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 05-01-2019 , 18:19   Re: [INC] Vector helpers
Reply With Quote #6

PHP Code:
stock void VectorCopy(const float vIn[3], float vOut[3])
{
    
vOut[0] = vIn[0];
    
vOut[1] = vIn[1];
    
vOut[2] = vIn[2];

is equival to vOut = vIn;
LOL
__________________
Grey83 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 05-01-2019 , 19:51   Re: [INC] Vector helpers
Reply With Quote #7

PHP Code:
    while(ang[1] > 180.0ang[1]-=360.0;
    while(
ang[1] <-180.0ang[1]+=360.0
maybe better use this:
PHP Code:
ang FloatFraction(ang) + RoundToFloor(ang) % 360
?
__________________
Grey83 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode