⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orbmath.inl

📁 matrix code
💻 INL
📖 第 1 页 / 共 2 页
字号:
#ifndef __ORB_MATH_INL__
#define __ORB_MATH_INL__

//================================================
// VECTOR2 inline implement
//================================================
inline 
VECTOR2::VECTOR2():x(0), y(0)
{
}
inline 
VECTOR2::VECTOR2(float _x, float _y):x(_x), y(_y)
{
}
inline 
bool VECTOR2::operator==(const VECTOR2& other) const
{
	return x == other.x && y == other.y;
}
inline
bool VECTOR2::operator!=(const VECTOR2& other) const
{
	return !operator==(other);
}
inline
VECTOR2 VECTOR2 ::operator+() const
{
	return *this;
}
inline
VECTOR2 VECTOR2 ::operator-() const
{
	return VECTOR2(-x, -y);
}
inline
float VECTOR2::Length() const
{
	return sqrtf(x * x + y * y);
}
inline
VECTOR2 VECTOR2::GetNormalized() const
{
	VECTOR2 v = *this;
	v.Normalize();
	return v;
}
inline
const VECTOR2& VECTOR2::operator +=(const VECTOR2& other)
{
	x += other.x;
	y += other.y;
	return *this;
}
inline
const VECTOR2& VECTOR2::operator -=(const VECTOR2& other)
{
	x -= other.x;
	y -= other.y;
	return *this;
}
inline
const VECTOR2& VECTOR2::operator *=(float s)
{
	x *= s;
	y *= s;
	return *this;
}
inline
const VECTOR2& VECTOR2::operator /=(float s)
{
	x /= s;
	y /= s;
	return *this;
}
//================================================

//================================================
// VECTOR3 inline implement
//================================================
inline
VECTOR3::VECTOR3():x(0), y(0), z(0)
{
}
inline
VECTOR3::VECTOR3(float _x, float _y, float _z):x(_x), y(_y), z(_z)
{
}
inline
bool VECTOR3::operator==(const VECTOR3& other) const
{
	return x == other.x && y == other.y && z == other.z;
}
inline
bool VECTOR3::operator!=(const VECTOR3& other) const 
{
	return !operator==(other);
}
inline 
VECTOR3 VECTOR3::operator+() const
{
	return *this;
}
inline
VECTOR3 VECTOR3::operator-() const
{
	return VECTOR3(-x, -y, -z);
}
inline
float VECTOR3::Length() const
{
	return sqrtf(x * x + y * y + z * z);
}
inline
VECTOR3 VECTOR3::GetNormalized() const
{
	VECTOR3 v = *this;
	v.Normalize();
	return v;
}
inline
const VECTOR3& VECTOR3::operator +=(const VECTOR3& other)
{
	x += other.x;
	y += other.y;
	z += other.z;
	return *this;
}
inline
const VECTOR3& VECTOR3::operator -=(const VECTOR3& other)
{
	x -= other.x;
	y -= other.y;
	z -= other.z;
	return *this;
}
inline
const VECTOR3& VECTOR3::operator *=(float s)
{
	x *= s;
	y *= s;
	z *= s;
	return *this;
}
inline
const VECTOR3& VECTOR3::operator /=(float s)
{
	x /= s;
	y /= s;
	z /= s;
	return *this;
}
//================================================

//================================================
// VECTOR4 inline implement
//================================================
inline 
VECTOR4::VECTOR4():x(0), y(0), z(0), w(0)
{
}
inline
VECTOR4::VECTOR4(float _x, float _y, float _z, float _w):x(_x), y(_y), z(_z), w(_w)
{
}
inline
bool VECTOR4::operator==(const VECTOR4& other) const
{
	return x == other.x && y == other.y && z == other.z && w == other.w;
}
inline
bool VECTOR4::operator!=(const VECTOR4& other) const
{
	return !operator==(other);
}
inline
VECTOR4 VECTOR4::operator+() const
{
	return *this;
}
inline
VECTOR4 VECTOR4::operator-() const
{
	return VECTOR4(-x, -y, -z, -w);
}
inline
float VECTOR4::Length() const
{
	return sqrtf(x * x + y * y + z * z + w * w);
}
inline 
VECTOR4 VECTOR4 ::GetNormalized() const
{
	VECTOR4 v = *this;
	v.Normalize();
	return v;
}
inline
const VECTOR4& VECTOR4::operator +=(const VECTOR4& other)
{
	x += other.x;
	y += other.y;
	z += other.z;
	w += other.w;
	return *this;
}
inline
const VECTOR4& VECTOR4::operator -=(const VECTOR4& other)
{
	x -= other.x;
	y -= other.y;
	z -= other.z;
	w -= other.w;
	return *this;
}
inline
const VECTOR4& VECTOR4::operator *=(float s)
{
	x *= s;
	y *= s;
	z *= s;
	w *= s;
	return *this;
}
inline
const VECTOR4& VECTOR4::operator /=(float s)
{
	x /= s;
	y /= s;
	z /= s;
	w /= s;
	return *this;
}
//================================================


//================================================
// QUATERNION inline implement
//================================================
inline
QUATERNION::QUATERNION():x(0), y(0), z(0), w(0)
{
}

inline
QUATERNION::QUATERNION(float _x, float _y, float _z, float _w)
		:x(_x), y(_y), z(_z), w(_w)
{
}

inline
bool QUATERNION::operator == (const QUATERNION& other) const
{
	return x == other.x && y == other.y && z == other.z && w == other.w;
}

inline
bool QUATERNION::operator != (const QUATERNION& other) const
{
	return !operator==(other);
}

inline
QUATERNION QUATERNION::operator + () const
{
	return *this;
}

inline
QUATERNION QUATERNION::operator - () const
{
	return QUATERNION(-x, -y, -z, -w);
}

inline
QUATERNION& QUATERNION::operator += (const QUATERNION& other)
{
	x += other.x;
	y += other.y;
	z += other.z;
	w += other.w;
	return *this;
}

inline
QUATERNION& QUATERNION::operator -= (const QUATERNION& other)
{
	x -= other.x;
	y -= other.y;
	z -= other.z;
	w -= other.w;
	return *this;
}

inline
QUATERNION& QUATERNION::operator *= (float f)
{
	x *= f;
	y *= f;
	z *= f;
	w *= f;
	return *this;
}

inline
QUATERNION& QUATERNION::operator /= ( float f )
{
	float fInv = 1.0f / f;
	x *= fInv;
	y *= fInv;
	z *= fInv;
	w *= fInv;
	return *this;
}

inline
float QUATERNION::Length() const
{
	return sqrtf(x * x + y * y + z * z + w * w);
}

inline
bool QUATERNION::IsIdentity() const
{
	return x == 0.0f && y == 0.0f && z == 0.0f && w == 1.0f;
}
inline
const QUATERNION& QUATERNION::SetIdentity()
{
	x = y = z = 0.0f;
	w = 1.0f;
	return *this;
}
inline
QUATERNION QUATERNION ::GetNormalize() const
{
	QUATERNION q = *this;
	q.Normalize();
	return q;
}
//================================================


//================================================
// MATRIX33 inline implement
//================================================
inline
MATRIX33::MATRIX33()
{
	memset(this, 0, sizeof(MATRIX33));
}
inline
MATRIX33::MATRIX33(float _m[9])
{
	memcpy(m, _m, 9 * sizeof(float));
}

inline
MATRIX33::MATRIX33(	float _m11, float _m12, float _m13,
	float _m21, float _m22, float _m23,
	float _m31, float _m32, float _m33)
	
{
	m11 = _m11, m12 = _m12, m13 = _m13, 
	m21 = _m21, m22 = _m22, m23 = _m23, 
	m31 = _m31, m32 = _m32, m33 = _m33;
		
}

inline
float& MATRIX33::operator()(int row, int col)
{
	return m[3 * (row) + col ];
}

inline
const float& MATRIX33::operator()(int row, int col) const
{
	return m[3 * (row) + col];
}
inline
float& MATRIX33::operator[](int nIndex)
{
	return m[nIndex];
}
inline
const float& MATRIX33::operator[](int nIndex) const
{
	return m[nIndex];
}
inline
const MATRIX33& MATRIX33::operator+=(const MATRIX33& other)
{
	for(int i = 0; i < 9; ++i)
	{
		m[i] += other.m[i];
	}
	return *this;
}

inline
const MATRIX33& MATRIX33::operator-=(const MATRIX33& other)
{
	for(int i = 0; i < 9; ++i)
	{
		m[i] -= other.m[i];
	}
	return *this;
}

inline
bool MATRIX33::operator==(const MATRIX33& other) const
{
	for(int i = 0; i < 9; ++i)
	{
		if(m[i] != other.m[i])
			return false;
	}
	return true;
}

inline
bool MATRIX33::operator!=(const MATRIX33& other) const
{
	return !operator==(other);
}

inline
const MATRIX33& MATRIX33::SetIdentity()
{
	memset(this, 0, sizeof(MATRIX33));
	m11 = m22 = m33;
	return *this;
}

inline
bool MATRIX33::isIdentity() const
{
	return	m11 == 1.0f && m12 == 0.0f && m13 == 0.0f && 
			m21 == 0.0f && m22 == 1.0f && m23 == 0.0f && 
			m31 == 0.0f && m32 == 0.0f && m33 == 1.0f;
			
}
inline
float MATRIX33::Determinant() const
{
	return ((m11 * ((m22 * m33) - (m23 * m32))) -
            (m12 * ((m21 * m33) - (m23 * m31))) +
            (m13 * ((m21 * m32) - (m22 * m31))));
}
inline 
MATRIX33 MATRIX33::GetTranspose() const
{
	MATRIX33 ret = *this;
	ret.Transpose();
	return ret;
}
inline 
MATRIX33 MATRIX33::GetInverse() const
{
	MATRIX33 ret = *this;
	ret.Invert();
	return ret;
}
inline
MATRIX33::operator float*() const
{
	return (float*)m;
}
inline
MATRIX33::MATRIX33(const QUATERNION& quat)
{
	float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;

	x2 = quat.x + quat.x;
	y2 = quat.y + quat.y;
	z2 = quat.z + quat.z;
	xx = quat.x * x2;
	xy = quat.x * y2;
	xz = quat.x * z2;
	yy = quat.y * y2;
	yz = quat.y * z2;
	zz = quat.z * z2;
	wx = quat.w * x2;
	wy = quat.w * y2;
	wz = quat.w * z2;

	m11 = 1.0f - (yy + zz);
	m21 = xy - wz;
	m31 = xz + wy;
	
	m12 = xy + wz;
	m22 = 1.0f - (xx + zz);
	m32 = yz - wx;
	
	m13 = xz - wy;
	m23 = yz + wx;
	m33 = 1.0f - (xx + yy);
}
inline
VECTOR3 MATRIX33::GetRow(int row) const
{
	VECTOR3 v;
	v.x = (*this)(0, row);
	v.y = (*this)(1, row);
	v.z = (*this)(2, row);
	return v;
}
inline
VECTOR3 MATRIX33::GetLine(int line) const
{
	VECTOR3 v;
	v.x = (*this)(line, 0);
	v.y = (*this)(line, 1);
	v.z = (*this)(line, 2);
	return v;
}
inline
void MATRIX33::SetLine(int line, const VECTOR3& v)
{
	(*this)(line, 0) = v.x;
	(*this)(line, 1) = v.y;
	(*this)(line, 2) = v.z;
}
inline
void MATRIX33::SetRow(int row, const VECTOR3& v)
{
	(*this)(0, row) = v.x;
	(*this)(1, row) = v.y;
	(*this)(2, row) = v.z;
}
//================================================


//================================================
// MATRIX44 inline implement
//================================================
inline
MATRIX44::MATRIX44()
{
	memset(this, 0, sizeof(MATRIX44));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -