AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] Vector helpers (https://forums.alliedmods.net/showthread.php?t=307906)

xXDeathreusXx 05-29-2018 20:03

[INC] Vector helpers
 
1 Attachment(s)
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

xXDeathreusXx 08-24-2018 20:08

Re: [INC] Vector helpers
 
New file uploaded, added:
VectorsEqual
VectorIsZero
VectorRotateOnAxis
VectorMatrix
MatrixVectors
MatrixAngles

mug1wara 08-25-2018 13:11

Re: [INC] Vector helpers
 
Saves me lots of time, thanks.

Grzyboo 04-14-2019 08:02

Re: [INC] Vector helpers
 
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.

xXDeathreusXx 04-15-2019 03:36

Re: [INC] Vector helpers
 
Just copy pasted what was in mathlib, only thing I wrote myself which could be completely wrong is VectorRotateOnAxis

Grey83 05-01-2019 18:19

Re: [INC] Vector helpers
 
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 05-01-2019 19:51

Re: [INC] Vector helpers
 
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

?


All times are GMT -4. The time now is 20:28.

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