📄 orbmath.h
字号:
#ifndef __ORBMATH__HEADER
#define __ORBMATH__HEADER
#include <cmath>
#include <limits>
#include <memory.h>
#include <iostream>
#include <OrbPlatForm.h>
//! namespace orb
/*!
namespace orb is used throughout engine orb, as a subset of engine orb, this lib uses
namespace orb,too.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
namespace orb
{
// foward declare
struct MATRIX44;
struct MATRIX33;
//! Orb vector2
/*!
This struct implemented a 2 dimension vector, with some member fucntions to
simplize vector operation.
@warning This struct does not have a virtual destructor, so don't derive from this struct
unless you know exactly what you are doing.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
struct ORB_EXPORT VECTOR2
{
//! Default Constructor
/*!
This function set all the member value to default value 0.0f.
@return no return
*/
VECTOR2();
//! Constructor
/*!
This function assign x and y value to the vector
@param _x x value of the vector
@param _y y value of the vector
@return no return
*/
VECTOR2(float _x, float _y);
//! Operator ==
/*! @return if the vector is equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator==(const VECTOR2& other) const;
//! Operator !=
/*! @return if the vector is not equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator!=(const VECTOR2& other) const;
//! operator +
/*!
Unary operator
@return the positive vector value
*/
VECTOR2 operator+() const;
//! operator -
/*!
Unary operator
@return the negative vector value
*/
VECTOR2 operator-() const;
//! Vector length
/*!
@return the module of the vector
*/
float Length() const;
//! Normalize operation
/*!
This funtction normalize the vector
@return the const reference of the vector
*/
const VECTOR2& Normalize();
//! GetNormalized operation
/*!
@return a normalized vector of the vector
*/
VECTOR2 GetNormalized() const;
const VECTOR2& operator +=(const VECTOR2& other);
const VECTOR2& operator -=(const VECTOR2& other);
const VECTOR2& operator *=(float s);
const VECTOR2& operator /=(float s);
// data member
float x; /*!< x member of the vector */
float y; /*!< y member of the vector */
};
//! Orb vector3
/*!
This struct implemented a 3 dimension vector, with some member fucntions to
simplize vector operation.
@warning This struct does not have a virtual destructor, so don't derive from this struct
unless you know exactly what you are doing.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
struct ORB_EXPORT VECTOR3
{
//! Default Constructor
/*!
This function set all the member value to default value 0.0f.
@return no return
*/
VECTOR3();
//! Constructor
/*!
This function assign x, y and z value to the vector
@param _x x value of the vector
@param _y y value of the vector
@param _z z value of the vector
@return no return
*/
VECTOR3(float _x, float _y, float _z);
//! Operator ==
/*! @return if the vector is equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator==(const VECTOR3& other) const;
//! Operator !=
/*! @return if the vector is not equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator!=(const VECTOR3& other) const;
//! operator +
/*!
Unary operator
Sign operation, return the positive vector value
@return the positive vector value
*/
VECTOR3 operator+() const;
//! operator -
/*!
Unary operator
Sign operation, return the negative vector value
@return the negative vector value
*/
VECTOR3 operator-() const;
//! Vector length
/*!
@return the module of the vector
*/
float Length() const;
//! Normalize operation
/*!
This funtction normalize the vector
@return the const refernce of the vector.
*/
const VECTOR3& Normalize();
//! GetNormalized operation
/*!
@return the normalized vector
*/
VECTOR3 GetNormalized() const;
const VECTOR3& operator +=(const VECTOR3& other);
const VECTOR3& operator -=(const VECTOR3& other);
const VECTOR3& operator *=(float s);
const VECTOR3& operator /=(float s);
// data member
float x; /*!< x member of the vector */
float y; /*!< y member of the vector */
float z; /*!< z member of the vector */
};
//! Orb vector4
/*!
This struct implemented a 4 dimension vector, with some member fucntions to
simplize vector operation.
@warning This struct does not have a virtual destructor, so don't derive from this struct
unless you know exactly what you are doing.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
struct ORB_EXPORT VECTOR4
{
//! Default Constructor
/*!
This function set all the member value to default value 0.0f.
@return no return.
*/
VECTOR4();
//! Constructor
/*!
This function assign x, y, z and w value to the vector
@param _x x value of the vector
@param _y y value of the vector
@param _z z value of the vector
@param _w w value of the vector
@return no return
*/
VECTOR4(float _x, float _y, float _z, float _w);
//! Operator ==
/*! @return if the vector is equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator==(const VECTOR4& other) const;
//! Operator !=
/*! @return if the vector is not equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator!=(const VECTOR4& other) const;
//! operator +
/*!
Unary operator
Sign operation, return the positive vector value
@return the positive vector value
*/
VECTOR4 operator+() const;
//! operator -
/*!
Unary operator
Sign operation, return the negative vector value
@return the negative vector value
*/
VECTOR4 operator-() const;
//! Vector length
/*!
@return the module of the vector
*/
float Length() const;
//! Normalize operation
/*!
This funtction normalize the vector
@return the const reference of the vector.
*/
const VECTOR4& Normalize();
//! GetNormalized operation
/*!
@return the normalized vecor
*/
VECTOR4 GetNormalized() const;
const VECTOR4& operator +=(const VECTOR4& other);
const VECTOR4& operator -=(const VECTOR4& other);
const VECTOR4& operator *=(float s);
const VECTOR4& operator /=(float s);
// data member
float x; /*!< x member of the vector */
float y; /*!< y member of the vector */
float z; /*!< z member of the vector */
float w; /*!< w member of the vector */
};
//! Orb quaternion
/*!
This struct implemented a quaternion, with some member fucntions to
simplize quaternion operation.
@warning This struct does not have a virtual destructor, so don't derive from this struct
unless you know exactly what you are doing.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
struct ORB_EXPORT QUATERNION
{
//! Default Constructor
/*!
This function set all the member value to default value 0.0f.
@return no return.
*/
QUATERNION();
//! Constructor
/*!
This function assign x, y, z and w value to the quaternion
@param _x x value of the quaternion
@param _y y value of the quaternion
@param _z z value of the quaternion
@param _w w value of the quaternion
@return no return.
*/
QUATERNION(float _x, float _y, float _z, float _w);
//! Constructor
/*!
This function construct a quaternion from a MATRIX33
@param mat matrix to construct quaternion
@return no return.
*/
explicit QUATERNION(const MATRIX33& mat);
//! Constructor
/*!
This function construct a quaternion from a MATRIX44
@param mat matrix to construct quaternion
@return no return.
*/
explicit QUATERNION(const MATRIX44& mat);
//! Operator ==
/*! @return if the vector is equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator == (const QUATERNION& other) const;
//! Operator !=
/*! @return if the vector is not equal to parameter @b other, the function
returns @b true, otherwise, it returns @b false.
*/
bool operator != (const QUATERNION& other) const;
//! operator +
/*!
Unary operator
Sign operation, return the negative quaternion value
@return the negative quaternion value
*/
QUATERNION operator + () const;
//! operator -
/*!
Unary operator
Sign operation, return the negative quaternion value
@return the negative quaternion value
*/
QUATERNION operator - () const;
//! operator +=
/*!
This operator add another quaternion to itself.
@return the reference of *this.
*/
QUATERNION& operator += (const QUATERNION& other);
//! operator +=
/*!
This operator subtract another quaternion from itself.
@return the reference of *this.
*/
QUATERNION& operator -= (const QUATERNION& other);
//! operator *=
/*!
This operator multiply another quaternion to itself.
@return the reference of *this.
*/
QUATERNION& operator *= (const QUATERNION& other);
//! operator *=
/*!
This operator multiply a float to itself.
@return the reference of *this.
*/
QUATERNION& operator *= (float f);
//! operator /=
/*!
This operator divide a float from itself.
@return the reference of *this.
*/
QUATERNION& operator /= ( float f );
//! Quaternion length
/*!
@return the module of the quaternion
*/
float Length() const;
//! IsIdentity
/*!
@return If the quaternion is a identity one, this function returns @b true.
Otherwise, it returns @b false.
*/
bool IsIdentity() const;
//! SetIdentity
/*!
This function initialize the quaternion with identity value
@return the const reference of the quaternion.
*/
const QUATERNION& SetIdentity();
//! Normalize operation
/*!
This funtction normalize the quaternion
@return the const reference of the quaternion.
*/
const QUATERNION& Normalize();
//! Normalize operation
/*!
@return the normalized quaternion
*/
QUATERNION GetNormalize() const;
// data member
float x; /*!< x member of the quaternion */
float y; /*!< y member of the quaternion */
float z; /*!< z member of the quaternion */
float w; /*!< w member of the quaternion */
};
//! Orb 3x3 rotation Matrix
/*!
This struct implemented a 3x3 matrix, with some member fucntions to
simplize matrix operation.
@warning This struct does not have a virtual destructor, so don't derive from this struct
unless you know exactly what you are doing.
@date 05/12/2003
@version 1.0
@author Dan Tong
@author mail: Lythm@citiz.net
*/
struct ORB_EXPORT MATRIX33
{
//! Default Constructor
/*!
This function set all the member value to default value 0.0f.
@return no return.
*/
MATRIX33();
//! Constructor
/*!
This function construct the matrix with a float[9] array.
@return no return.
*/
explicit MATRIX33(float _m[9]);
//! Constructor
/*!
This function construct the matrix with 9 float parameters
@return no return.
*/
MATRIX33( float _m11, float _m12, float _m13,
float _m21, float _m22, float _m23,
float _m31, float _m32, float _m33);
//! Constructor
/*!
This function construct the matrix with quaternion.
@param quat the unit quaternion to construct the matrix
@return no return.
@warning the quaternion must be a unit one
*/
explicit MATRIX33(const QUATERNION& quat);
//! float* extractor
/*!
This function turn the matrix to a quaternion.
@return the quaternion value of this matrix.
*/
operator float*() const;
//! Operator()
/*!
This function return the reference to the sub value of the matrix,
which locate at [row, col].
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -