CMath: Difference between revisions
Jump to navigation
Jump to search
Outerbeast (talk | contribs) Created page with "This class contains math operation methods. A single global instance exists: <code>CMath Math</code> The AngelScript standard library also contains math functions such as tri..." |
Outerbeast (talk | contribs) mNo edit summary |
||
| Line 10: | Line 10: | ||
! Description | ! Description | ||
|- | |- | ||
| int32 RandomLong(int32 low, int32 high) | | <code>int32 RandomLong(int32 low, int32 high) | ||
| style="vertical-align:middle;" | Returns a random integer between low and high | | style="vertical-align:middle;" | Returns a random integer between low and high | ||
|- | |- | ||
| float RandomFloat(float low, float high) | | <code>float RandomFloat(float low, float high) | ||
| style="vertical-align:middle;" | Returns a random float between low and high | | style="vertical-align:middle;" | Returns a random float between low and high | ||
|- | |- | ||
| void MakeVectors(const Vector& in vecAngles) | | <code>void MakeVectors(const Vector& in vecAngles) | ||
| style="vertical-align:middle;" | Makes vectors | | style="vertical-align:middle;" | Makes vectors | ||
|- | |- | ||
| Vector RotateVector(Vector& in vecToRotate,const Vector& in vecAngles, const Vector& in vecOffset) | | <code>Vector RotateVector(Vector& in vecToRotate,const Vector& in vecAngles, const Vector& in vecOffset) | ||
| style="vertical-align:middle;" | Rotate vector | | style="vertical-align:middle;" | Rotate vector | ||
|- | |- | ||
| void MakeAimVectors(const Vector& in vecAngles) | | <code>void MakeAimVectors(const Vector& in vecAngles) | ||
| style="vertical-align:middle;" | Make aim vectors | | style="vertical-align:middle;" | Make aim vectors | ||
|- | |- | ||
| void MakeInvVectors(const Vector& in vecAngles) | | <code>void MakeInvVectors(const Vector& in vecAngles) | ||
| style="vertical-align:middle;" | Make inverted vectors | | style="vertical-align:middle;" | Make inverted vectors | ||
|- | |- | ||
| float VecToYaw(const Vector& in vec) | | <code>float VecToYaw(const Vector& in vec) | ||
| style="vertical-align:middle;" | Transforms a vector to a yaw value | | style="vertical-align:middle;" | Transforms a vector to a yaw value | ||
|- | |- | ||
| Vector VecToAngles(const Vector& in vec) | | <code>Vector VecToAngles(const Vector& in vec) | ||
| style="vertical-align:middle;" | Transforms a vector to an angle | | style="vertical-align:middle;" | Transforms a vector to an angle | ||
|- | |- | ||
| float AngleMod(float flAngle) | | <code>float AngleMod(float flAngle) | ||
| style="vertical-align:middle;" | Clamps the given angle between 0 and 360 | | style="vertical-align:middle;" | Clamps the given angle between 0 and 360 | ||
|- | |- | ||
| float AngleDiff(float flDestAngle, float flSrcAngle) | | <code>float AngleDiff(float flDestAngle, float flSrcAngle) | ||
| style="vertical-align:middle;" | Returns the difference between 2 angles | | style="vertical-align:middle;" | Returns the difference between 2 angles | ||
|- | |- | ||
| float ApproachAngle(float target, float value, float speed) | | <code>float ApproachAngle(float target, float value, float speed) | ||
| style="vertical-align:middle;" | Given a target and current angle value, and a rotation speed, all in degrees, returns a new angle that is either between value and target, or target, depending on whether the speed is high enough to reach that angle. | | style="vertical-align:middle;" | Given a target and current angle value, and a rotation speed, all in degrees, returns a new angle that is either between value and target, or target, depending on whether the speed is high enough to reach that angle. | ||
|- | |- | ||
| float AngleDistance(float flNext, float flCur) | | <code>float AngleDistance(float flNext, float flCur) | ||
| style="vertical-align:middle;" | Returns the distance between 2 angles | | style="vertical-align:middle;" | Returns the distance between 2 angles | ||
|- | |- | ||
| uint64 min(uint64 lhs, uint64 rhs) const | | <code>uint64 min(uint64 lhs, uint64 rhs) const | ||
| style="vertical-align:middle;" | Returns the smaller of the two values | | style="vertical-align:middle;" | Returns the smaller of the two values | ||
|- | |- | ||
| int64 min(int64 lhs, int64 rhs) const | | <code>int64 min(int64 lhs, int64 rhs) const | ||
| style="vertical-align:middle;" | Returns the smaller of the two values | | style="vertical-align:middle;" | Returns the smaller of the two values | ||
|- | |- | ||
| float min(float lhs, float rhs) const | | <code>float min(float lhs, float rhs) const | ||
| style="vertical-align:middle;" | Returns the smaller of the two values | | style="vertical-align:middle;" | Returns the smaller of the two values | ||
|- | |- | ||
| uint64 max(uint64 lhs, uint64 rhs) const | | <code>uint64 max(uint64 lhs, uint64 rhs) const | ||
| style="vertical-align:middle;" | Returns the larger of the two values | | style="vertical-align:middle;" | Returns the larger of the two values | ||
|- | |- | ||
| int64 max(int64 lhs, int64 rhs) const | | <code>int64 max(int64 lhs, int64 rhs) const | ||
| style="vertical-align:middle;" | Returns the larger of the two values | | style="vertical-align:middle;" | Returns the larger of the two values | ||
|- | |- | ||
| float max(float lhs, float rhs) const | | <code>float max(float lhs, float rhs) const | ||
| style="vertical-align:middle;" | Returns the larger of the two values | | style="vertical-align:middle;" | Returns the larger of the two values | ||
|- | |- | ||
| int clamp(int min, int max, int value) const | | <code>int clamp(int min, int max, int value) const | ||
| style="vertical-align:middle;" | Clamps a value between a range | | style="vertical-align:middle;" | Clamps a value between a range | ||
|- | |- | ||
| float clamp(float min, float max, float value) const | | <code>float clamp(float min, float max, float value) const | ||
| style="vertical-align:middle;" | Clamps a value between a range | | style="vertical-align:middle;" | Clamps a value between a range | ||
|- | |- | ||
| float DegreesToRadians(float flDegrees) const | | <code>float DegreesToRadians(float flDegrees) const | ||
| style="vertical-align:middle;" | Returns the given value in degrees as radians | | style="vertical-align:middle;" | Returns the given value in degrees as radians | ||
|- | |- | ||
| float RadiansToDegrees(float flRadians) const | | <code>float RadiansToDegrees(float flRadians) const | ||
| style="vertical-align:middle;" | Returns the given value in radians as degrees | | style="vertical-align:middle;" | Returns the given value in radians as degrees | ||
|- | |- | ||
| bool Compare(float flLhs, float flRhs, float flEpsilon) const | | <code>bool Compare(float flLhs, float flRhs, float flEpsilon) const | ||
| style="vertical-align:middle;" | Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. | | style="vertical-align:middle;" | Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. | ||
|- | |- | ||
| bool Compare(double flLhs, double flRhs, double flEpsilon) const | | <code>bool Compare(double flLhs, double flRhs, double flEpsilon) const | ||
| style="vertical-align:middle;" | Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. | | style="vertical-align:middle;" | Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. | ||
|} | |} | ||
| Line 90: | Line 90: | ||
! Description | ! Description | ||
|- | |- | ||
| const int8 INT8_MIN | | <code>const int8 INT8_MIN | ||
| style="vertical-align:middle;" | Int8 minimum value | | style="vertical-align:middle;" | Int8 minimum value | ||
|- | |- | ||
| const int16 INT16_MIN | | <code>const int16 INT16_MIN | ||
| style="vertical-align:middle;" | Int16 minimum value | | style="vertical-align:middle;" | Int16 minimum value | ||
|- | |- | ||
| const int32 INT32_MIN | | <code>const int32 INT32_MIN | ||
| style="vertical-align:middle;" | Int32 minimum value | | style="vertical-align:middle;" | Int32 minimum value | ||
|- | |- | ||
| const int64 INT64_MIN | | <code>const int64 INT64_MIN | ||
| style="vertical-align:middle;" | Int64 minimum value | | style="vertical-align:middle;" | Int64 minimum value | ||
|- | |- | ||
| const int8 INT8_MAX | | <code>const int8 INT8_MAX | ||
| style="vertical-align:middle;" | Int8 maximum value | | style="vertical-align:middle;" | Int8 maximum value | ||
|- | |- | ||
| const int16 INT16_MAX | | <code>const int16 INT16_MAX | ||
| style="vertical-align:middle;" | Int16 maximum value | | style="vertical-align:middle;" | Int16 maximum value | ||
|- | |- | ||
| const int32 INT32_MAX | | <code>const int32 INT32_MAX | ||
| style="vertical-align:middle;" | Int32 maximum value | | style="vertical-align:middle;" | Int32 maximum value | ||
|- | |- | ||
| const int64 INT64_MAX | | <code>const int64 INT64_MAX | ||
| style="vertical-align:middle;" | Int64 maximum value | | style="vertical-align:middle;" | Int64 maximum value | ||
|- | |- | ||
| const uint8 UINT8_MAX | | <code>const uint8 UINT8_MAX | ||
| style="vertical-align:middle;" | Uint8 maximum value | | style="vertical-align:middle;" | Uint8 maximum value | ||
|- | |- | ||
| const uint16 UINT16_MAX | | <code>const uint16 UINT16_MAX | ||
| style="vertical-align:middle;" | Uint16 maximum value | | style="vertical-align:middle;" | Uint16 maximum value | ||
|- | |- | ||
| const uint32 UINT32_MAX | | <code>const uint32 UINT32_MAX | ||
| style="vertical-align:middle;" | Uint32 maximum value | | style="vertical-align:middle;" | Uint32 maximum value | ||
|- | |- | ||
| const uint64 UINT64_MAX | | <code>const uint64 UINT64_MAX | ||
| style="vertical-align:middle;" | Uint64 maximum value | | style="vertical-align:middle;" | Uint64 maximum value | ||
|- | |- | ||
| const size_t SIZE_MAX | | <code>const size_t SIZE_MAX | ||
| style="vertical-align:middle;" | Size_t maximum value | | style="vertical-align:middle;" | Size_t maximum value | ||
|- | |- | ||
| const float FLOAT_MIN | | <code>const float FLOAT_MIN | ||
| style="vertical-align:middle;" | Float minimum positive value | | style="vertical-align:middle;" | Float minimum positive value | ||
|- | |- | ||
| const double DOUBLE_MIN | | <code>const double DOUBLE_MIN | ||
| style="vertical-align:middle;" | Double minimum positive value | | style="vertical-align:middle;" | Double minimum positive value | ||
|- | |- | ||
| const float FLOAT_MAX | | <code>const float FLOAT_MAX | ||
| style="vertical-align:middle;" | Float maximum positive value | | style="vertical-align:middle;" | Float maximum positive value | ||
|- | |- | ||
| const double DOUBLE_MAX | | <code>const double DOUBLE_MAX | ||
| style="vertical-align:middle;" | Double maximum positive value | | style="vertical-align:middle;" | Double maximum positive value | ||
|- | |- | ||
| const double PI | | <code>const double PI | ||
| style="vertical-align:middle;" | PI | | style="vertical-align:middle;" | PI | ||
|} | |} | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
Latest revision as of 20:53, 13 March 2025
This class contains math operation methods.
A single global instance exists: CMath Math
The AngelScript standard library also contains math functions such as trigonometric, exponential, logarithmic and others. They can be found here.
Methods
| Declaration | Description |
|---|---|
int32 RandomLong(int32 low, int32 high)
|
Returns a random integer between low and high |
float RandomFloat(float low, float high)
|
Returns a random float between low and high |
void MakeVectors(const Vector& in vecAngles)
|
Makes vectors |
Vector RotateVector(Vector& in vecToRotate,const Vector& in vecAngles, const Vector& in vecOffset)
|
Rotate vector |
void MakeAimVectors(const Vector& in vecAngles)
|
Make aim vectors |
void MakeInvVectors(const Vector& in vecAngles)
|
Make inverted vectors |
float VecToYaw(const Vector& in vec)
|
Transforms a vector to a yaw value |
Vector VecToAngles(const Vector& in vec)
|
Transforms a vector to an angle |
float AngleMod(float flAngle)
|
Clamps the given angle between 0 and 360 |
float AngleDiff(float flDestAngle, float flSrcAngle)
|
Returns the difference between 2 angles |
float ApproachAngle(float target, float value, float speed)
|
Given a target and current angle value, and a rotation speed, all in degrees, returns a new angle that is either between value and target, or target, depending on whether the speed is high enough to reach that angle. |
float AngleDistance(float flNext, float flCur)
|
Returns the distance between 2 angles |
uint64 min(uint64 lhs, uint64 rhs) const
|
Returns the smaller of the two values |
int64 min(int64 lhs, int64 rhs) const
|
Returns the smaller of the two values |
float min(float lhs, float rhs) const
|
Returns the smaller of the two values |
uint64 max(uint64 lhs, uint64 rhs) const
|
Returns the larger of the two values |
int64 max(int64 lhs, int64 rhs) const
|
Returns the larger of the two values |
float max(float lhs, float rhs) const
|
Returns the larger of the two values |
int clamp(int min, int max, int value) const
|
Clamps a value between a range |
float clamp(float min, float max, float value) const
|
Clamps a value between a range |
float DegreesToRadians(float flDegrees) const
|
Returns the given value in degrees as radians |
float RadiansToDegrees(float flRadians) const
|
Returns the given value in radians as degrees |
bool Compare(float flLhs, float flRhs, float flEpsilon) const
|
Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. |
bool Compare(double flLhs, double flRhs, double flEpsilon) const
|
Compares the given floating point variables and returns whether they are equal, considering certain variance (epsilon) between them. |
Properties
| Declaration | Description |
|---|---|
const int8 INT8_MIN
|
Int8 minimum value |
const int16 INT16_MIN
|
Int16 minimum value |
const int32 INT32_MIN
|
Int32 minimum value |
const int64 INT64_MIN
|
Int64 minimum value |
const int8 INT8_MAX
|
Int8 maximum value |
const int16 INT16_MAX
|
Int16 maximum value |
const int32 INT32_MAX
|
Int32 maximum value |
const int64 INT64_MAX
|
Int64 maximum value |
const uint8 UINT8_MAX
|
Uint8 maximum value |
const uint16 UINT16_MAX
|
Uint16 maximum value |
const uint32 UINT32_MAX
|
Uint32 maximum value |
const uint64 UINT64_MAX
|
Uint64 maximum value |
const size_t SIZE_MAX
|
Size_t maximum value |
const float FLOAT_MIN
|
Float minimum positive value |
const double DOUBLE_MIN
|
Double minimum positive value |
const float FLOAT_MAX
|
Float maximum positive value |
const double DOUBLE_MAX
|
Double maximum positive value |
const double PI
|
PI |