GetChangedPosition

From NWN Lexicon
Jump to navigationJump to search

GetChangedPosition(vector, float, float)

Convenience function that returns a vector that is fDistance away in fAngle direction

vector GetChangedPosition(
    vector vOriginal,
    float fDistance,
    float fAngle
);

Parameters

vOriginal

Original Position as a Vector

fDistance

Distance to new location

fAngle

Direction to new location


Description

This is a convenience function that returns a vector representing the position that is (fDistance:float*meters) at fAngle:float from vOriginal:vector. The function does not calculate any change in the Z-axis, instead assigning the current Z-axis to the new position. If a negative coordinate is generated, the absolute value will be used instead.


Calls
float GetChangeInX(float fDistance, float fAngle)
float GetChangeInY(float fDistance, float fAngle)



Remarks

This writer has to wonder why the author of this function didn’t simply write it as follows:
vector vChanged;
vChanged.z = vOriginal.z;
vChanged.x = vOriginal.x + (fDistance* Cos(fAngle));
if (vChanged.x < 0.0)
vChanged.x = - vChanged.x;
vChanged.y = vOriginal.y + (fDistance* Sin(fAngle));
if (vChanged.y < 0.0)
vChanged.y = - vChanged.y;

return vChanged;
This would have avoided the cognitive overhead of two extra functions (GetChangeInX, and GetChangeInY). Although I can see the need for a AbsFloat(fNum:Float):float that returns the absolute value of a float (since the Abs function takes an int)...


Requirements

#include " x0_i0_position "

Version

1.61

See Also

functions: 

GetChangeInY



 author: Michael Nork