1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/source/Base/Quaternion.hpp
Sandu Liviu Catalin 8088ba94c2 Updated the exception system in the main plugin to also include the location in the source files in debug builds.
Moved the functions that extract base types from strings as static functions under the associated type.
Revised some of the base shared code.
Fixed some of the functions in the String library that did not take into account the null terminator.
2016-03-21 22:37:58 +02:00

348 lines
13 KiB
C++

#ifndef _BASE_QUATERNION_HPP_
#define _BASE_QUATERNION_HPP_
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Quaternion type from a string.
*/
const Quaternion & GetQuaternion(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Quaternion class for representing rotations.
*/
struct Quaternion
{
/* --------------------------------------------------------------------------------------------
* The type of value used by components of type.
*/
typedef float Value;
/* --------------------------------------------------------------------------------------------
* Helper instances for common values mostly used as return types or comparison.
*/
static const Quaternion NIL;
static const Quaternion MIN;
static const Quaternion MAX;
/* --------------------------------------------------------------------------------------------
* The delimiter character to be used when extracting values from strings.
*/
static SQChar Delim;
/* --------------------------------------------------------------------------------------------
* The x, y, z and w components of this type.
*/
Value x, y, z, w;
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Quaternion();
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(Value sv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(Value xv, Value yv, Value zv);
/* --------------------------------------------------------------------------------------------
* ...
*/
Quaternion(Value xv, Value yv, Value zv, Value wv);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Quaternion(const Quaternion & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Quaternion(Quaternion && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Quaternion() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Quaternion & operator = (const Quaternion & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Quaternion & operator = (Quaternion && o) = default;
/* --------------------------------------------------------------------------------------------
* Scalar value assignment operator.
*/
Quaternion & operator = (Value s);
/* --------------------------------------------------------------------------------------------
* Euler assignment operator.
*/
Quaternion & operator = (const Vector3 & q);
/* --------------------------------------------------------------------------------------------
* Four-dimensional vector assignment operator threated as a three-dimensional vector.
*/
Quaternion & operator = (const Vector4 & q);
/* --------------------------------------------------------------------------------------------
* Addition assignment operator.
*/
Quaternion & operator += (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Subtraction assignment operator.
*/
Quaternion & operator -= (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Multiplication assignment operator.
*/
Quaternion & operator *= (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Division assignment operator.
*/
Quaternion & operator /= (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Modulo assignment operator.
*/
Quaternion & operator %= (const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Scalar value addition assignment operator.
*/
Quaternion & operator += (Value s);
/* --------------------------------------------------------------------------------------------
* Scalar value subtraction assignment operator.
*/
Quaternion & operator -= (Value s);
/* --------------------------------------------------------------------------------------------
* Scalar value multiplication assignment operator.
*/
Quaternion & operator *= (Value s);
/* --------------------------------------------------------------------------------------------
* Scalar value division assignment operator.
*/
Quaternion & operator /= (Value s);
/* --------------------------------------------------------------------------------------------
* Scalar value modulo assignment operator.
*/
Quaternion & operator %= (Value s);
/* --------------------------------------------------------------------------------------------
* Pre-increment operator.
*/
Quaternion & operator ++ ();
/* --------------------------------------------------------------------------------------------
* Pre-decrement operator.
*/
Quaternion & operator -- ();
/* --------------------------------------------------------------------------------------------
* Post-increment operator.
*/
Quaternion operator ++ (int);
/* --------------------------------------------------------------------------------------------
* Post-decrement operator.
*/
Quaternion operator -- (int);
/* --------------------------------------------------------------------------------------------
* Addition operator.
*/
Quaternion operator + (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Subtraction operator.
*/
Quaternion operator - (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Multiplication operator.
*/
Quaternion operator * (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Division operator.
*/
Quaternion operator / (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Modulo operator.
*/
Quaternion operator % (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Scalar value addition operator.
*/
Quaternion operator + (Value s) const;
/* --------------------------------------------------------------------------------------------
* Scalar value subtraction operator.
*/
Quaternion operator - (Value s) const;
/* --------------------------------------------------------------------------------------------
* Scalar value multiplication operator.
*/
Quaternion operator * (Value s) const;
/* --------------------------------------------------------------------------------------------
* Scalar value division operator.
*/
Quaternion operator / (Value s) const;
/* --------------------------------------------------------------------------------------------
* Scalar value modulo operator.
*/
Quaternion operator % (Value s) const;
/* --------------------------------------------------------------------------------------------
* Unary plus operator.
*/
Quaternion operator + () const;
/* --------------------------------------------------------------------------------------------
* Unary minus operator.
*/
Quaternion operator - () const;
/* --------------------------------------------------------------------------------------------
* Equality comparison operator.
*/
bool operator == (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Inequality comparison operator.
*/
bool operator != (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Less than comparison operator.
*/
bool operator < (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Greater than comparison operator.
*/
bool operator > (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Less than or equal comparison operator.
*/
bool operator <= (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Greater than or equal comparison operator.
*/
bool operator >= (const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Quaternion & q) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Set all components to the specified scalar value.
*/
void Set(Value ns);
/* --------------------------------------------------------------------------------------------
* Set all components to the specified values.
*/
void Set(Value nx, Value ny, Value nz);
/* --------------------------------------------------------------------------------------------
* Set all components to the specified values.
*/
void Set(Value nx, Value ny, Value nz, Value nw);
/* --------------------------------------------------------------------------------------------
* Copy the values from another instance of this type.
*/
void Set(const Quaternion & q);
/* --------------------------------------------------------------------------------------------
* Copy the values from a three-dimensional vector as euler rotation.
*/
void Set(const Vector3 & v);
/* --------------------------------------------------------------------------------------------
* Copy the values from a four-dimensional vector.
*/
void Set(const Vector4 & v);
/* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter.
*/
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance.
*/
void Generate();
/* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance within the specified bounds.
*/
void Generate(Value min, Value max);
/* --------------------------------------------------------------------------------------------
* Generate random values for all components of this instance within the specified bounds.
*/
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value zmin, Value zmax, Value wmin, Value wmax);
/* --------------------------------------------------------------------------------------------
* Clear the component values to default.
*/
void Clear()
{
x = 0.0, y = 0.0, z = 0.0, w = 0.0;
}
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Quaternion Abs() const;
};
} // Namespace:: SqMod
#endif // _BASE_QUATERNION_HPP_