Replaced ckmath with Eigen for linear algebra
This commit is contained in:
parent
ddb3b5efa3
commit
3845ede3b9
@ -1,20 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_H__
|
||||
#define __MATH_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_constants.h"
|
||||
#include "ckmath_types.h"
|
||||
#include "ckmath_geometry.h"
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_matrix.h"
|
||||
#include "ckmath_quaternion.h"
|
||||
|
||||
#endif
|
@ -1,17 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_CONSTANTS_H__
|
||||
#define __MATH_CONSTANTS_H__
|
||||
|
||||
// Math
|
||||
static const double s_kdTau = 6.2831853071795864769252867665590057683943387987502116;
|
||||
static const double s_kdPi = 3.1415926535897932384626433832795028841971693993751058;
|
||||
static const float s_kfTau = static_cast<const float>(s_kdTau);
|
||||
static const float s_kfPi = static_cast<const float>(s_kdPi);
|
||||
|
||||
#endif
|
@ -1,121 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_geometry.h"
|
||||
|
||||
const bool IsIntersection(const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC)
|
||||
{
|
||||
const TVector3d kNAxNB = CrossProduct(TVector3d(), _krA.m_Normal, _krB.m_Normal);
|
||||
return(Magnitude(DotProduct(kNAxNB, _krC.m_Normal)) > 0.0);
|
||||
}
|
||||
|
||||
const bool IsIntersection(const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC)
|
||||
{
|
||||
const TVector3f kNAxNB = CrossProduct(TVector3f(), _krA.m_Normal, _krB.m_Normal);
|
||||
return(Magnitude(DotProduct(kNAxNB, _krC.m_Normal)) > 0.0f);
|
||||
}
|
||||
|
||||
const TVector3d& GetIntersection( TVector3d& _rResult,
|
||||
const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC)
|
||||
{
|
||||
const TVector3d kNBxNC = CrossProduct(TVector3d(), _krB.m_Normal, _krC.m_Normal);
|
||||
const TVector3d kNCxNA = CrossProduct(TVector3d(), _krC.m_Normal, _krA.m_Normal);
|
||||
const TVector3d kNAxNB = CrossProduct(TVector3d(), _krA.m_Normal, _krB.m_Normal);
|
||||
|
||||
const double kdDistanceA = DotProduct(_krA.m_Normal, _krA.m_Point);
|
||||
const double kdDistanceB = DotProduct(_krB.m_Normal, _krB.m_Point);
|
||||
const double kdDistanceC = DotProduct(_krC.m_Normal, _krC.m_Point);
|
||||
|
||||
const TVector3d kDA_NBxNC = ScalarMultiply(TVector3d(), kNBxNC, kdDistanceA);
|
||||
const TVector3d kDB_NCxNA = ScalarMultiply(TVector3d(), kNCxNA, kdDistanceB);
|
||||
const TVector3d kDC_NAxNB = ScalarMultiply(TVector3d(), kNAxNB, kdDistanceC);
|
||||
|
||||
const double kdDenom = DotProduct(kNAxNB, _krC.m_Normal);
|
||||
|
||||
const TVector3d kNumer = Add(TVector3d(), Add(TVector3d(), kDA_NBxNC, kDB_NCxNA), kDC_NAxNB);
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, (1.0 / kdDenom));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& GetIntersection( TVector3f& _rResult,
|
||||
const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC)
|
||||
{
|
||||
const TVector3f kNBxNC = CrossProduct(TVector3f(), _krB.m_Normal, _krC.m_Normal);
|
||||
const TVector3f kNCxNA = CrossProduct(TVector3f(), _krC.m_Normal, _krA.m_Normal);
|
||||
const TVector3f kNAxNB = CrossProduct(TVector3f(), _krA.m_Normal, _krB.m_Normal);
|
||||
|
||||
const float kfDistanceA = DotProduct(_krA.m_Normal, _krA.m_Point);
|
||||
const float kfDistanceB = DotProduct(_krB.m_Normal, _krB.m_Point);
|
||||
const float kfDistanceC = DotProduct(_krC.m_Normal, _krC.m_Point);
|
||||
|
||||
const TVector3f kDA_NBxNC = ScalarMultiply(TVector3f(), kNBxNC, kfDistanceA);
|
||||
const TVector3f kDB_NCxNA = ScalarMultiply(TVector3f(), kNCxNA, kfDistanceB);
|
||||
const TVector3f kDC_NAxNB = ScalarMultiply(TVector3f(), kNAxNB, kfDistanceC);
|
||||
|
||||
const float kfDenom = DotProduct(kNAxNB, _krC.m_Normal);
|
||||
|
||||
const TVector3f kNumer = Add(TVector3f(), Add(TVector3f(), kDA_NBxNC, kDB_NCxNA), kDC_NAxNB);
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, (1.0f / kfDenom));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& GetPolygonNormal(TVector3d& _rResult, const TVector3d* _kpVertices, const size_t _kVertexCount)
|
||||
{
|
||||
_rResult = ZeroVector(TVector3d());
|
||||
|
||||
for(size_t i = 0; i < _kVertexCount; ++i)
|
||||
{
|
||||
const size_t kIndexA = ((_kVertexCount-1)+i)%_kVertexCount;
|
||||
const size_t kIndexB = i;
|
||||
|
||||
const TVector3d& krA = _kpVertices[kIndexA];
|
||||
const TVector3d& krB = _kpVertices[kIndexB];
|
||||
|
||||
const TVector3d kCrossProduct = CrossProduct(TVector3d(), krA, krB);
|
||||
|
||||
_rResult = Add(_rResult, _rResult, kCrossProduct);
|
||||
}
|
||||
|
||||
_rResult = Normalize(_rResult, _rResult);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& GetPolygonNormal(TVector3f& _rResult, const TVector3f* _kpVertices, const size_t _kVertexCount)
|
||||
{
|
||||
_rResult = ZeroVector(TVector3f());
|
||||
|
||||
for(size_t i = 0; i < _kVertexCount; ++i)
|
||||
{
|
||||
const size_t kIndexA = ((_kVertexCount-1)+i)%_kVertexCount;
|
||||
const size_t kIndexB = i;
|
||||
|
||||
const TVector3f& krA = _kpVertices[kIndexA];
|
||||
const TVector3f& krB = _kpVertices[kIndexB];
|
||||
|
||||
const TVector3f kCrossProduct = CrossProduct(TVector3f(), krA, krB);
|
||||
|
||||
_rResult = Add(_rResult, _rResult, kCrossProduct);
|
||||
}
|
||||
|
||||
_rResult = Normalize(_rResult, _rResult);
|
||||
|
||||
return(_rResult);
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_GEOMETRY_H__
|
||||
#define __MATH_GEOMETRY_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
|
||||
const bool IsIntersection( const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC);
|
||||
|
||||
const bool IsIntersection( const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC);
|
||||
|
||||
const TVector3d& GetIntersection( TVector3d& _rResult,
|
||||
const TPlane3d& _krA,
|
||||
const TPlane3d& _krB,
|
||||
const TPlane3d& _krC);
|
||||
|
||||
const TVector3f& GetIntersection( TVector3f& _rResult,
|
||||
const TPlane3f& _krA,
|
||||
const TPlane3f& _krB,
|
||||
const TPlane3f& _krC);
|
||||
|
||||
const TVector3d& GetPolygonNormal( TVector3d& _rResult,
|
||||
const TVector3d* _kpVertices,
|
||||
const size_t _kVertexCount);
|
||||
|
||||
const TVector3f& GetPolygonNormal( TVector3f& _rResult,
|
||||
const TVector3f* _kpVertices,
|
||||
const size_t _kVertexCount);
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,410 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_MATRIX_H__
|
||||
#define __MATH_MATRIX_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
//
|
||||
// Matrix 4
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix4d& _krA, const TMatrix4d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix4f& _krA, const TMatrix4f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix4d& ZeroMatrix(TMatrix4d& _rResult);
|
||||
|
||||
const TMatrix4f& ZeroMatrix(TMatrix4f& _rResult);
|
||||
|
||||
const TMatrix4d& IdentityMatrix(TMatrix4d& _rResult);
|
||||
|
||||
const TMatrix4f& IdentityMatrix(TMatrix4f& _rResult);
|
||||
|
||||
const TMatrix4d& Multiply( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TMatrix4d& _krB);
|
||||
|
||||
const TMatrix4f& Multiply( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TMatrix4f& _krB);
|
||||
|
||||
const TMatrix4d& ScalarMultiply(TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix4f& ScalarMultiply(TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector4d& VectorMultiply(TVector4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& VectorMultiply(TVector4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TMatrix4d& Add( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krA,
|
||||
const TMatrix4d& _krB);
|
||||
|
||||
const TMatrix4f& Add( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krA,
|
||||
const TMatrix4f& _krB);
|
||||
|
||||
const TMatrix4d& Transpose( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& Transpose( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix4d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix4f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix4d& SetElement( TMatrix4d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix4f& SetElement( TMatrix4f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix3d& Submatrix( TMatrix3d& _rResult,
|
||||
const TMatrix4d& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const TMatrix3f& Submatrix( TMatrix3f& _rResult,
|
||||
const TMatrix4f& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const double FirstMinor(const TMatrix4d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float FirstMinor( const TMatrix4f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix4d& MatrixOfMinors(TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& MatrixOfMinors(TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& MatrixOfCofactors( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& MatrixOfCofactors( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const double Determinant(const TMatrix4d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& Inverse( TMatrix4d& _rResult,
|
||||
const TMatrix4d& _krMatrix);
|
||||
|
||||
const TMatrix4f& Inverse( TMatrix4f& _rResult,
|
||||
const TMatrix4f& _krMatrix);
|
||||
|
||||
const TMatrix4d& TranslationMatrix( TMatrix4d& _rResult,
|
||||
const TVector3d& _krVector);
|
||||
|
||||
const TMatrix4f& TranslationMatrix( TMatrix4f& _rResult,
|
||||
const TVector3f& _krVector);
|
||||
|
||||
const TMatrix4d& ScalingMatrix( TMatrix4d& _rResult,
|
||||
const double _kdX,
|
||||
const double _kdY,
|
||||
const double _kdZ);
|
||||
|
||||
const TMatrix4f& ScalingMatrix( TMatrix4f& _rResult,
|
||||
const float _kfX,
|
||||
const float _kfY,
|
||||
const float _kfZ);
|
||||
|
||||
const TMatrix4d& TransformationMatrix( TMatrix4d& _rResult,
|
||||
const TVector3d& _krBasisX,
|
||||
const TVector3d& _krBasisY,
|
||||
const TVector3d& _krBasisZ,
|
||||
const TVector3d& _krTranslation);
|
||||
|
||||
const TMatrix4f& TransformationMatrix( TMatrix4f& _rResult,
|
||||
const TVector3f& _krBasisX,
|
||||
const TVector3f& _krBasisY,
|
||||
const TVector3f& _krBasisZ,
|
||||
const TVector3f& _krTranslation);
|
||||
|
||||
const TMatrix4d& RotationMatrix( TMatrix4d& _rResult,
|
||||
const TVector4d& _krQuaternion);
|
||||
|
||||
const TMatrix4f& RotationMatrix( TMatrix4f& _rResult,
|
||||
const TVector4f& _krQuaternion);
|
||||
|
||||
const TMatrix4d& AxisRotationXMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationXMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& AxisRotationYMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationYMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& AxisRotationZMatrix(TMatrix4d& _rResult,
|
||||
const double _kdAngle);
|
||||
|
||||
const TMatrix4f& AxisRotationZMatrix(TMatrix4f& _rResult,
|
||||
const float _kfAngle);
|
||||
|
||||
const TMatrix4d& PerspectiveMatrix( TMatrix4d& _rResult,
|
||||
const double _kdLeft, const double _kdRight,
|
||||
const double _kdBottom, const double _kdTop,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& PerspectiveMatrix( TMatrix4f& _rResult,
|
||||
const float _kfLeft, const float _kfRight,
|
||||
const float _kfBottom, const float _kfTop,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& PerspectiveMatrix( TMatrix4d& _rResult,
|
||||
const double _kdFovX, const double _kdFovY,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& PerspectiveMatrix( TMatrix4f& _rResult,
|
||||
const float _kfFovX, const float _kfFovY,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& OrthographicMatrix(TMatrix4d& _rResult,
|
||||
const double _kdLeft, const double _kdRight,
|
||||
const double _kdBottom, const double _kdTop,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& OrthographicMatrix(TMatrix4f& _rResult,
|
||||
const float _kfLeft, const float _kfRight,
|
||||
const float _kfBottom, const float _kfTop,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
const TMatrix4d& OrthographicMatrix(TMatrix4d& _rResult,
|
||||
const double _kdWidth, const double _kdHeight,
|
||||
const double _kdFar, const double _kdNear);
|
||||
|
||||
const TMatrix4f& OrthographicMatrix(TMatrix4f& _rResult,
|
||||
const float _kfWidth, const float _kfHeight,
|
||||
const float _kfFar, const float _kfNear);
|
||||
|
||||
//
|
||||
// Matrix 3
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix3d& _krA, const TMatrix3d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix3f& _krA, const TMatrix3f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix3d& ZeroMatrix(TMatrix3d& _rResult);
|
||||
|
||||
const TMatrix3f& ZeroMatrix(TMatrix3f& _rResult);
|
||||
|
||||
const TMatrix3d& IdentityMatrix(TMatrix3d& _rResult);
|
||||
|
||||
const TMatrix3f& IdentityMatrix(TMatrix3f& _rResult);
|
||||
|
||||
const TMatrix3d& Multiply( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TMatrix3d& _krB);
|
||||
|
||||
const TMatrix3f& Multiply( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TMatrix3f& _krB);
|
||||
|
||||
const TMatrix3d& ScalarMultiply(TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix3f& ScalarMultiply(TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector3d& VectorMultiply(TVector3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& VectorMultiply(TVector3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TMatrix3d& Add( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krA,
|
||||
const TMatrix3d& _krB);
|
||||
|
||||
const TMatrix3f& Add( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krA,
|
||||
const TMatrix3f& _krB);
|
||||
|
||||
const TMatrix3d& Transpose( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& Transpose( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix3d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix3f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix3d& SetElement( TMatrix3d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix3f& SetElement( TMatrix3f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix2d& Submatrix( TMatrix2d& _rResult,
|
||||
const TMatrix3d& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const TMatrix2f& Submatrix( TMatrix2f& _rResult,
|
||||
const TMatrix3f& _krMatrix,
|
||||
const size_t _kDeletedRow,
|
||||
const size_t _kDeletedColumn);
|
||||
|
||||
const double Determinant(const TMatrix3d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix3f& _krMatrix);
|
||||
|
||||
const double FirstMinor(const TMatrix3d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float FirstMinor( const TMatrix3f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix3d& MatrixOfMinors(TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& MatrixOfMinors(TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const TMatrix3d& MatrixOfCofactors( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& MatrixOfCofactors( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
const TMatrix3d& Inverse( TMatrix3d& _rResult,
|
||||
const TMatrix3d& _krMatrix);
|
||||
|
||||
const TMatrix3f& Inverse( TMatrix3f& _rResult,
|
||||
const TMatrix3f& _krMatrix);
|
||||
|
||||
//
|
||||
// Matrix 2
|
||||
//
|
||||
|
||||
const bool Equal(const TMatrix2d& _krA, const TMatrix2d& _krB, const double _kdEpsilon);
|
||||
|
||||
const bool Equal(const TMatrix2f& _krA, const TMatrix2f& _krB, const float _kfEpsilon);
|
||||
|
||||
const TMatrix2d& ZeroMatrix(TMatrix2d& _rResult);
|
||||
|
||||
const TMatrix2f& ZeroMatrix(TMatrix2f& _rResult);
|
||||
|
||||
const TMatrix2d& IdentityMatrix(TMatrix2d& _rResult);
|
||||
|
||||
const TMatrix2f& IdentityMatrix(TMatrix2f& _rResult);
|
||||
|
||||
const TMatrix2d& Multiply( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TMatrix2d& _krB);
|
||||
|
||||
const TMatrix2f& Multiply( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TMatrix2f& _krB);
|
||||
|
||||
const TMatrix2d& ScalarMultiply(TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix,
|
||||
const double _kdScalar);
|
||||
|
||||
const TMatrix2f& ScalarMultiply(TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix,
|
||||
const float _kfScalar);
|
||||
|
||||
const TVector2d& VectorMultiply(TVector2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& VectorMultiply(TVector2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TMatrix2d& Add( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krA,
|
||||
const TMatrix2d& _krB);
|
||||
|
||||
const TMatrix2f& Add( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krA,
|
||||
const TMatrix2f& _krB);
|
||||
|
||||
const TMatrix2d& Transpose( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix);
|
||||
|
||||
const TMatrix2f& Transpose( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix);
|
||||
|
||||
const double GetElement(const TMatrix2d& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const float GetElement(const TMatrix2f& _krMatrix,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix2d& SetElement( TMatrix2d& _rResult,
|
||||
const double _kdValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
TMatrix2f& SetElement( TMatrix2f& _rResult,
|
||||
const float _kfValue,
|
||||
const size_t _kRow,
|
||||
const size_t _kColumn);
|
||||
|
||||
const TMatrix2d& Inverse( TMatrix2d& _rResult,
|
||||
const TMatrix2d& _krMatrix);
|
||||
|
||||
const TMatrix2f& Inverse( TMatrix2f& _rResult,
|
||||
const TMatrix2f& _krMatrix);
|
||||
|
||||
const double Determinant(const TMatrix2d& _krMatrix);
|
||||
|
||||
const float Determinant(const TMatrix2f& _krMatrix);
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,236 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_quaternion.h"
|
||||
#include "ckmath_scalar.h"
|
||||
#include "ckmath_vector.h"
|
||||
|
||||
|
||||
//
|
||||
// Quaternion
|
||||
//
|
||||
|
||||
const TVector4d& IdentityQuaternion(TVector4d& _rResult)
|
||||
{
|
||||
_rResult.m_dW = 1.0;
|
||||
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& IdentityQuaternion(TVector4f& _rResult)
|
||||
{
|
||||
_rResult.m_fW = 1.0f;
|
||||
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& ConjugateQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult.m_dW = _krQuaternion.m_dW;
|
||||
|
||||
_rResult.m_dX = -_krQuaternion.m_dX;
|
||||
_rResult.m_dY = -_krQuaternion.m_dY;
|
||||
_rResult.m_dZ = -_krQuaternion.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ConjugateQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult.m_fW = _krQuaternion.m_fW;
|
||||
|
||||
_rResult.m_fX = -_krQuaternion.m_fX;
|
||||
_rResult.m_fY = -_krQuaternion.m_fY;
|
||||
_rResult.m_fZ = -_krQuaternion.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& InverseQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply(_rResult,
|
||||
ConjugateQuaternion(TVector4d(), _krQuaternion),
|
||||
(1.0 / Square(QuaternionMagnitude(_krQuaternion))));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& InverseQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply(_rResult,
|
||||
ConjugateQuaternion(TVector4f(), _krQuaternion),
|
||||
(1.0f / Square(QuaternionMagnitude(_krQuaternion))));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& UnitQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply( _rResult,
|
||||
_krQuaternion,
|
||||
(1.0 / QuaternionMagnitude(_krQuaternion)));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& UnitQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion)
|
||||
{
|
||||
_rResult = ScalarMultiply( _rResult,
|
||||
_krQuaternion,
|
||||
(1.0f / QuaternionMagnitude(_krQuaternion)));
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& AxisAngleQuaternion(TVector4d& _rResult, const TVector3d& _krAxis, const double _kdAngle)
|
||||
{
|
||||
_rResult.m_dW = Cosine(_kdAngle / 2.0);
|
||||
|
||||
_rResult.m_dX = _krAxis.m_dX * Sine(_kdAngle / 2.0);
|
||||
_rResult.m_dY = _krAxis.m_dY * Sine(_kdAngle / 2.0);
|
||||
_rResult.m_dZ = _krAxis.m_dZ * Sine(_kdAngle / 2.0);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& AxisAngleQuaternion(TVector4f& _rResult, const TVector3f& _krAxis, const float _kfAngle)
|
||||
{
|
||||
_rResult.m_fW = Cosine(_kfAngle / 2.0f);
|
||||
|
||||
_rResult.m_fX = _krAxis.m_fX * Sine(_kfAngle / 2.0f);
|
||||
_rResult.m_fY = _krAxis.m_fY * Sine(_kfAngle / 2.0f);
|
||||
_rResult.m_fZ = _krAxis.m_fZ * Sine(_kfAngle / 2.0f);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double QuaternionMagnitude(const TVector4d& _krQuaternion)
|
||||
{
|
||||
return(SquareRoot(QuaternionProduct(TVector4d(),
|
||||
ConjugateQuaternion( TVector4d(),
|
||||
_krQuaternion),
|
||||
_krQuaternion).m_dW));
|
||||
}
|
||||
|
||||
const float QuaternionMagnitude(const TVector4f& _krQuaternion)
|
||||
{
|
||||
return(SquareRoot(QuaternionProduct(TVector4f(),
|
||||
ConjugateQuaternion( TVector4f(),
|
||||
_krQuaternion),
|
||||
_krQuaternion).m_fW));
|
||||
}
|
||||
|
||||
const TVector4d& QuaternionProduct(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dW = (_krA.m_dW * _krB.m_dW) - (_krA.m_dX * _krB.m_dX) - (_krA.m_dY * _krB.m_dY) - (_krA.m_dZ * _krB.m_dZ);
|
||||
_rResult.m_dX = (_krA.m_dW * _krB.m_dX) + (_krA.m_dX * _krB.m_dW) + (_krA.m_dY * _krB.m_dZ) - (_krA.m_dZ * _krB.m_dY);
|
||||
_rResult.m_dY = (_krA.m_dW * _krB.m_dY) - (_krA.m_dX * _krB.m_dZ) + (_krA.m_dY * _krB.m_dW) + (_krA.m_dZ * _krB.m_dX);
|
||||
_rResult.m_dZ = (_krA.m_dW * _krB.m_dZ) + (_krA.m_dX * _krB.m_dY) - (_krA.m_dY * _krB.m_dX) + (_krA.m_dZ * _krB.m_dW);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& QuaternionProduct(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fW = (_krA.m_fW * _krB.m_fW) - (_krA.m_fX * _krB.m_fX) - (_krA.m_fY * _krB.m_fY) - (_krA.m_fZ * _krB.m_fZ);
|
||||
_rResult.m_fX = (_krA.m_fW * _krB.m_fX) + (_krA.m_fX * _krB.m_fW) + (_krA.m_fY * _krB.m_fZ) - (_krA.m_fZ * _krB.m_fY);
|
||||
_rResult.m_fY = (_krA.m_fW * _krB.m_fY) - (_krA.m_fX * _krB.m_fZ) + (_krA.m_fY * _krB.m_fW) + (_krA.m_fZ * _krB.m_fX);
|
||||
_rResult.m_fZ = (_krA.m_fW * _krB.m_fZ) + (_krA.m_fX * _krB.m_fY) - (_krA.m_fY * _krB.m_fX) + (_krA.m_fZ * _krB.m_fW);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& QuaternionRotate(TVector3d& _rResult, const TVector3d& _krVector, const TVector4d& _krQuaternion)
|
||||
{
|
||||
const TVector4d kVecAsQuat{_krVector.m_dX, _krVector.m_dY, _krVector.m_dZ, 0.0};
|
||||
|
||||
const TVector4d kResultAsQuat = QuaternionProduct(TVector4d(),
|
||||
QuaternionProduct(TVector4d(), _krQuaternion, kVecAsQuat),
|
||||
ConjugateQuaternion(TVector4d(), _krQuaternion));
|
||||
|
||||
_rResult.m_dX = kResultAsQuat.m_dX;
|
||||
_rResult.m_dY = kResultAsQuat.m_dY;
|
||||
_rResult.m_dZ = kResultAsQuat.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& QuaternionRotate(TVector3f& _rResult, const TVector3f& _krVector, const TVector4f& _krQuaternion)
|
||||
{
|
||||
const TVector4f kVecAsQuat{_krVector.m_fX, _krVector.m_fY, _krVector.m_fZ, 0.0f};
|
||||
|
||||
const TVector4f kResultAsQuat = QuaternionProduct(TVector4f(),
|
||||
QuaternionProduct(TVector4f(), _krQuaternion, kVecAsQuat),
|
||||
ConjugateQuaternion(TVector4f(), _krQuaternion));
|
||||
|
||||
_rResult.m_fX = kResultAsQuat.m_fX;
|
||||
_rResult.m_fY = kResultAsQuat.m_fY;
|
||||
_rResult.m_fZ = kResultAsQuat.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Slerp(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB, const double _kdT)
|
||||
{
|
||||
const double kdCosOmega = DotProduct(_krA, _krB);
|
||||
|
||||
double dK0, dK1;
|
||||
if(Magnitude(kdCosOmega) == 1.0) // Avoid divide by zero using lerp
|
||||
{
|
||||
dK0 = 1.0 - _kdT;
|
||||
dK1 = _kdT;
|
||||
}
|
||||
else
|
||||
{
|
||||
const double kdSinOmega = SquareRoot(1.0 - Square(kdCosOmega));
|
||||
const double kdOmega = ArcTan2(kdSinOmega, kdCosOmega);
|
||||
|
||||
dK0 = Sine((1.0 - _kdT) * kdOmega) * (1.0 / kdSinOmega);
|
||||
dK1 = Sine(_kdT * kdOmega) * (1.0 / kdSinOmega);
|
||||
}
|
||||
|
||||
_rResult.m_dW = (_krA.m_dW * dK0) + (_krB.m_dW * dK1);
|
||||
_rResult.m_dX = (_krA.m_dX * dK0) + (_krB.m_dX * dK1);
|
||||
_rResult.m_dY = (_krA.m_dY * dK0) + (_krB.m_dY * dK1);
|
||||
_rResult.m_dZ = (_krA.m_dZ * dK0) + (_krB.m_dZ * dK1);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Slerp(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB, const float _kfT)
|
||||
{
|
||||
const float kfCosOmega = DotProduct(_krA, _krB);
|
||||
|
||||
float fK0, fK1;
|
||||
if(Magnitude(kfCosOmega) == 1.0f) // Avoid divide by zero using lerp
|
||||
{
|
||||
fK0 = 1.0f - _kfT;
|
||||
fK1 = _kfT;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float kfSinOmega = SquareRoot(1.0f - Square(kfCosOmega));
|
||||
const float kfOmega = ArcTan2(kfSinOmega, kfCosOmega);
|
||||
|
||||
fK0 = Sine((1.0f - _kfT) * kfOmega) * (1.0f / kfSinOmega);
|
||||
fK1 = Sine(_kfT * kfOmega) * (1.0f / kfSinOmega);
|
||||
}
|
||||
|
||||
_rResult.m_fW = (_krA.m_fW * fK0) + (_krB.m_fW * fK1);
|
||||
_rResult.m_fX = (_krA.m_fX * fK0) + (_krB.m_fX * fK1);
|
||||
_rResult.m_fY = (_krA.m_fY * fK0) + (_krB.m_fY * fK1);
|
||||
_rResult.m_fZ = (_krA.m_fZ * fK0) + (_krB.m_fZ * fK1);
|
||||
|
||||
return(_rResult);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_QUATERNION_H__
|
||||
#define __MATH_QUATERNION_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
// Quaternion Function Prototypes
|
||||
|
||||
const TVector4d& IdentityQuaternion(TVector4d& _rResult);
|
||||
|
||||
const TVector4f& IdentityQuaternion(TVector4f& _rResult);
|
||||
|
||||
const TVector4d& ConjugateQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& ConjugateQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& InverseQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& InverseQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& UnitQuaternion(TVector4d& _rResult, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector4f& UnitQuaternion(TVector4f& _rResult, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& AxisAngleQuaternion(TVector4d& _rResult, const TVector3d& _krAxis, const double _kdAngle);
|
||||
|
||||
const TVector4f& AxisAngleQuaternion(TVector4f& _rResult, const TVector3f& _krAxis, const float _kfAngle);
|
||||
|
||||
const double QuaternionMagnitude(const TVector4d& _krQuaternion);
|
||||
|
||||
const float QuaternionMagnitude(const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& QuaternionProduct(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB);
|
||||
|
||||
const TVector4f& QuaternionProduct(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB);
|
||||
|
||||
const TVector3d& QuaternionRotate(TVector3d& _rResult, const TVector3d& _krVector, const TVector4d& _krQuaternion);
|
||||
|
||||
const TVector3f& QuaternionRotate(TVector3f& _rResult, const TVector3f& _krVector, const TVector4f& _krQuaternion);
|
||||
|
||||
const TVector4d& Slerp(TVector4d& _rResult, const TVector4d& _krA, const TVector4d& _krB, const double _kdT);
|
||||
|
||||
const TVector4f& Slerp(TVector4f& _rResult, const TVector4f& _krA, const TVector4f& _krB, const float _kfT);
|
||||
|
||||
|
||||
#endif
|
@ -1,109 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_SCALAR_H__
|
||||
#define __MATH_SCALAR_H__
|
||||
|
||||
// Library Includes
|
||||
#include <cmath>
|
||||
|
||||
// Scalar Function Prototypes
|
||||
|
||||
// double
|
||||
inline const double Square(const double _kdScalar)
|
||||
{
|
||||
return(_kdScalar * _kdScalar);
|
||||
}
|
||||
|
||||
inline const double Magnitude(const double _kdScalar)
|
||||
{
|
||||
return(abs(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double SquareRoot(const double _kdScalar)
|
||||
{
|
||||
return(sqrt(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcCos(const double _kdScalar)
|
||||
{
|
||||
return(acos(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcTan(const double _kdScalar)
|
||||
{
|
||||
return(atan(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double ArcTan2(const double _kdX, const double _kdY)
|
||||
{
|
||||
return(atan2(_kdX, _kdY));
|
||||
}
|
||||
|
||||
inline const double Sine(const double _kdScalar)
|
||||
{
|
||||
return(sin(_kdScalar));
|
||||
}
|
||||
|
||||
inline const double Cosine(const double _kdScalar)
|
||||
{
|
||||
return(cos(_kdScalar));
|
||||
}
|
||||
|
||||
inline const bool Equal(const double _kdA, const double _kdB, const double _kdEpsilon)
|
||||
{
|
||||
return((Magnitude(_kdA - _kdB) < _kdEpsilon));
|
||||
}
|
||||
|
||||
// float
|
||||
inline const float Square(const float _kfScalar)
|
||||
{
|
||||
return(_kfScalar * _kfScalar);
|
||||
}
|
||||
|
||||
inline const float Magnitude(const float _kfScalar)
|
||||
{
|
||||
return(fabsf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float SquareRoot(const float _kfScalar)
|
||||
{
|
||||
return(sqrtf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcCos(const float _kfScalar)
|
||||
{
|
||||
return(acosf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcTan(const float _kfScalar)
|
||||
{
|
||||
return(atanf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float ArcTan2(const float _kfX, const float _kfY)
|
||||
{
|
||||
return(atan2f(_kfX, _kfY));
|
||||
}
|
||||
|
||||
inline const float Sine(const float _kfScalar)
|
||||
{
|
||||
return(sinf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const float Cosine(const float _kfScalar)
|
||||
{
|
||||
return(cosf(_kfScalar));
|
||||
}
|
||||
|
||||
inline const bool Equal(const float _kfA, const float _kfB, const float _kfEpsilon)
|
||||
{
|
||||
return((Magnitude(_kfA - _kfB) < _kfEpsilon));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,306 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_TYPES_H__
|
||||
#define __MATH_TYPES_H__
|
||||
|
||||
//
|
||||
//
|
||||
// Struct Prototypes
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Vector
|
||||
//
|
||||
struct TVector4d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
double m_dZ;
|
||||
double m_dW;
|
||||
};
|
||||
|
||||
struct TVector4f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
float m_fZ;
|
||||
float m_fW;
|
||||
};
|
||||
|
||||
struct TVector3d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
double m_dZ;
|
||||
};
|
||||
|
||||
struct TVector3f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
float m_fZ;
|
||||
};
|
||||
|
||||
struct TVector2d
|
||||
{
|
||||
double m_dX;
|
||||
double m_dY;
|
||||
};
|
||||
|
||||
struct TVector2f
|
||||
{
|
||||
float m_fX;
|
||||
float m_fY;
|
||||
};
|
||||
|
||||
//
|
||||
// Matrix
|
||||
//
|
||||
struct TMatrix4d
|
||||
{
|
||||
double m_d11, m_d12, m_d13, m_d14;
|
||||
double m_d21, m_d22, m_d23, m_d24;
|
||||
double m_d31, m_d32, m_d33, m_d34;
|
||||
double m_d41, m_d42, m_d43, m_d44;
|
||||
};
|
||||
|
||||
struct TMatrix4f
|
||||
{
|
||||
float m_f11, m_f12, m_f13, m_f14;
|
||||
float m_f21, m_f22, m_f23, m_f24;
|
||||
float m_f31, m_f32, m_f33, m_f34;
|
||||
float m_f41, m_f42, m_f43, m_f44;
|
||||
};
|
||||
|
||||
struct TMatrix3d
|
||||
{
|
||||
double m_d11, m_d12, m_d13;
|
||||
double m_d21, m_d22, m_d23;
|
||||
double m_d31, m_d32, m_d33;
|
||||
};
|
||||
|
||||
struct TMatrix3f
|
||||
{
|
||||
float m_f11, m_f12, m_f13;
|
||||
float m_f21, m_f22, m_f23;
|
||||
float m_f31, m_f32, m_f33;
|
||||
};
|
||||
|
||||
struct TMatrix2d
|
||||
{
|
||||
double m_d11, m_d12;
|
||||
double m_d21, m_d22;
|
||||
};
|
||||
|
||||
struct TMatrix2f
|
||||
{
|
||||
float m_f11, m_f12;
|
||||
float m_f21, m_f22;
|
||||
};
|
||||
|
||||
//
|
||||
// Plane
|
||||
//
|
||||
struct TPlane3d
|
||||
{
|
||||
TVector3d m_Point;
|
||||
TVector3d m_Normal;
|
||||
};
|
||||
|
||||
struct TPlane3f
|
||||
{
|
||||
TVector3f m_Point;
|
||||
TVector3f m_Normal;
|
||||
|
||||
};
|
||||
|
||||
struct TPlane2d
|
||||
{
|
||||
TVector2d m_Point;
|
||||
TVector2d m_Normal;
|
||||
};
|
||||
|
||||
struct TPlane2f
|
||||
{
|
||||
TVector2f m_Point;
|
||||
TVector2f m_Normal;
|
||||
};
|
||||
|
||||
//
|
||||
// Triangle
|
||||
//
|
||||
struct TTriangle3d
|
||||
{
|
||||
TVector3d m_A;
|
||||
TVector3d m_B;
|
||||
TVector3d m_C;
|
||||
};
|
||||
|
||||
struct TTriangle3f
|
||||
{
|
||||
TVector3f m_A;
|
||||
TVector3f m_B;
|
||||
TVector3f m_C;
|
||||
};
|
||||
|
||||
struct TTriangle2d
|
||||
{
|
||||
TVector2d m_A;
|
||||
TVector2d m_B;
|
||||
TVector2d m_C;
|
||||
};
|
||||
|
||||
struct TTriangle2f
|
||||
{
|
||||
TVector2f m_A;
|
||||
TVector2f m_B;
|
||||
TVector2f m_C;
|
||||
};
|
||||
|
||||
//
|
||||
// Line
|
||||
//
|
||||
struct TLine3d
|
||||
{
|
||||
TVector3d m_A;
|
||||
TVector3d m_B;
|
||||
};
|
||||
|
||||
struct TLine3f
|
||||
{
|
||||
TVector3f m_A;
|
||||
TVector3f m_B;
|
||||
};
|
||||
|
||||
struct TLine2d
|
||||
{
|
||||
TVector2d m_A;
|
||||
TVector2d m_B;
|
||||
};
|
||||
|
||||
struct TLine2f
|
||||
{
|
||||
TVector2f m_A;
|
||||
TVector2f m_B;
|
||||
};
|
||||
|
||||
//
|
||||
// Ray
|
||||
//
|
||||
struct TRay3d
|
||||
{
|
||||
TVector3d m_Start;
|
||||
TVector3d m_Direction;
|
||||
};
|
||||
|
||||
struct TRay3f
|
||||
{
|
||||
TVector3f m_Start;
|
||||
TVector3f m_Direction;
|
||||
};
|
||||
|
||||
struct TRay2d
|
||||
{
|
||||
TVector2d m_Start;
|
||||
TVector2d m_Direction;
|
||||
};
|
||||
|
||||
struct TRay2f
|
||||
{
|
||||
TVector2f m_Start;
|
||||
TVector2f m_Direction;
|
||||
};
|
||||
|
||||
//
|
||||
// Sphere
|
||||
//
|
||||
struct TSphere3d
|
||||
{
|
||||
TVector3d m_Center;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TSphere3f
|
||||
{
|
||||
TVector3f m_Center;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// Circle
|
||||
//
|
||||
struct TCircle2d
|
||||
{
|
||||
TVector2d m_Center;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCircle2f
|
||||
{
|
||||
TVector2f m_Center;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// Capsule
|
||||
//
|
||||
struct TCapsule3d
|
||||
{
|
||||
TLine3d m_Line;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCapsule3f
|
||||
{
|
||||
TLine3f m_Line;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
struct TCapsule2d
|
||||
{
|
||||
TLine2d m_Line;
|
||||
double m_dRadius;
|
||||
};
|
||||
|
||||
struct TCapsule2f
|
||||
{
|
||||
TLine2f m_Line;
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
//
|
||||
// AABB
|
||||
//
|
||||
struct TAABB3d
|
||||
{
|
||||
TVector3d m_MinPoint;
|
||||
TVector3d m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB3f
|
||||
{
|
||||
TVector3f m_MinPoint;
|
||||
TVector3f m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB2d
|
||||
{
|
||||
TVector2d m_MinPoint;
|
||||
TVector2d m_MaxPoint;
|
||||
};
|
||||
|
||||
struct TAABB2f
|
||||
{
|
||||
TVector2f m_MinPoint;
|
||||
TVector2f m_MaxPoint;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,708 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_vector.h"
|
||||
#include "ckmath_scalar.h"
|
||||
|
||||
|
||||
//
|
||||
// Vector 4
|
||||
//
|
||||
|
||||
const TVector4d& ZeroVector(TVector4d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
_rResult.m_dW = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ZeroVector(TVector4f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
_rResult.m_fW = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector4d& _krA,
|
||||
const TVector4d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dZ - _krB.m_dZ) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dW - _krB.m_dW) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector4f& _krA,
|
||||
const TVector4f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fZ - _krB.m_fZ) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fW - _krB.m_fW) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector4d& Add( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ + _krB.m_dZ;
|
||||
_rResult.m_dW = _krA.m_dW + _krB.m_dW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Add( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ + _krB.m_fZ;
|
||||
_rResult.m_fW = _krA.m_fW + _krB.m_fW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Subtract(TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ - _krB.m_dZ;
|
||||
_rResult.m_dW = _krA.m_dW - _krB.m_dW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Subtract(TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ - _krB.m_fZ;
|
||||
_rResult.m_fW = _krA.m_fW - _krB.m_fW;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& ScalarMultiply( TVector4d& _rResult,
|
||||
const TVector4d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
_rResult.m_dZ = _krV.m_dZ * _kdS;
|
||||
_rResult.m_dW = _krV.m_dW * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& ScalarMultiply( TVector4f& _rResult,
|
||||
const TVector4f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
_rResult.m_fZ = _krV.m_fZ * _kfS;
|
||||
_rResult.m_fW = _krV.m_fW * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector4d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)
|
||||
+ Square(_krV.m_dZ)
|
||||
+ Square(_krV.m_dW)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector4f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)
|
||||
+ Square(_krV.m_fZ)
|
||||
+ Square(_krV.m_fW)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdResult = ( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY)
|
||||
+ (_krA.m_dZ * _krB.m_dZ)
|
||||
+ (_krA.m_dW * _krB.m_dW));
|
||||
|
||||
return(kdResult);
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfResult = ( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY)
|
||||
+ (_krA.m_fZ * _krB.m_fZ)
|
||||
+ (_krA.m_fW * _krB.m_fW));
|
||||
|
||||
return(kfResult);
|
||||
}
|
||||
|
||||
const TVector4d& Normalize( TVector4d& _rResult,
|
||||
const TVector4d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Normalize( TVector4f& _rResult,
|
||||
const TVector4f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4d& Projection( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector4d kNumer = ScalarMultiply(TVector4d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector4f& Projection( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector4f kNumer = ScalarMultiply(TVector4f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector4d& _krA,
|
||||
const TVector4d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector4d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector4f& _krA,
|
||||
const TVector4f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector4f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
||||
|
||||
//
|
||||
// Vector 3
|
||||
//
|
||||
|
||||
const TVector3d& ZeroVector(TVector3d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
_rResult.m_dZ = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& ZeroVector(TVector3f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
_rResult.m_fZ = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dZ - _krB.m_dZ) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fZ - _krB.m_fZ) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector3d& Add( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ + _krB.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Add( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ + _krB.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Subtract(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
_rResult.m_dZ = _krA.m_dZ - _krB.m_dZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Subtract(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
_rResult.m_fZ = _krA.m_fZ - _krB.m_fZ;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& ScalarMultiply( TVector3d& _rResult,
|
||||
const TVector3d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
_rResult.m_dZ = _krV.m_dZ * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& ScalarMultiply( TVector3f& _rResult,
|
||||
const TVector3f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
_rResult.m_fZ = _krV.m_fZ * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector3d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)
|
||||
+ Square(_krV.m_dZ)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector3f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)
|
||||
+ Square(_krV.m_fZ)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
return( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY)
|
||||
+ (_krA.m_dZ * _krB.m_dZ));
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
return( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY)
|
||||
+ (_krA.m_fZ * _krB.m_fZ));
|
||||
}
|
||||
|
||||
const TVector3d& CrossProduct(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
_rResult.m_dX = (_krA.m_dY * _krB.m_dZ) - ( _krA.m_dZ * _krB.m_dY);
|
||||
_rResult.m_dY = (_krA.m_dZ * _krB.m_dX) - ( _krA.m_dX * _krB.m_dZ);
|
||||
_rResult.m_dZ = (_krA.m_dX * _krB.m_dY) - ( _krA.m_dY * _krB.m_dX);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& CrossProduct(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
_rResult.m_fX = (_krA.m_fY * _krB.m_fZ) - ( _krA.m_fZ * _krB.m_fY);
|
||||
_rResult.m_fY = (_krA.m_fZ * _krB.m_fX) - ( _krA.m_fX * _krB.m_fZ);
|
||||
_rResult.m_fZ = (_krA.m_fX * _krB.m_fY) - ( _krA.m_fY * _krB.m_fX);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Normalize( TVector3d& _rResult,
|
||||
const TVector3d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Normalize( TVector3f& _rResult,
|
||||
const TVector3f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3d& Projection( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector3d kNumer = ScalarMultiply(TVector3d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector3f& Projection( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector3f kNumer = ScalarMultiply(TVector3f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector3d& _krA,
|
||||
const TVector3d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector3d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector3f& _krA,
|
||||
const TVector3f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector3f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
||||
|
||||
const double ScalarTripleProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC)
|
||||
{
|
||||
return(DotProduct(_krA, CrossProduct(TVector3d(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const float ScalarTripleProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC)
|
||||
{
|
||||
return(DotProduct(_krA, CrossProduct(TVector3f(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const TVector3d& VectorTripleProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC)
|
||||
{
|
||||
return(CrossProduct(_rResult, _krA, CrossProduct(TVector3d(), _krB, _krC)));
|
||||
}
|
||||
|
||||
const TVector3f& VectorTripleProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC)
|
||||
{
|
||||
return(CrossProduct(_rResult, _krA, CrossProduct(TVector3f(), _krB, _krC)));
|
||||
}
|
||||
|
||||
//
|
||||
// Vector 2
|
||||
//
|
||||
|
||||
const TVector2d& ZeroVector(TVector2d& _rResult)
|
||||
{
|
||||
_rResult.m_dX = 0.0;
|
||||
_rResult.m_dY = 0.0;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& ZeroVector(TVector2f& _rResult)
|
||||
{
|
||||
_rResult.m_fX = 0.0f;
|
||||
_rResult.m_fY = 0.0f;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector2d& _krA,
|
||||
const TVector2d& _krB,
|
||||
const double _kdEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_dX - _krB.m_dX) < _kdEpsilon)
|
||||
&& (Magnitude(_krA.m_dY - _krB.m_dY) < _kdEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const bool Equal( const TVector2f& _krA,
|
||||
const TVector2f& _krB,
|
||||
const float _kfEpsilon)
|
||||
{
|
||||
const bool kbEqual = (Magnitude(_krA.m_fX - _krB.m_fX) < _kfEpsilon)
|
||||
&& (Magnitude(_krA.m_fY - _krB.m_fY) < _kfEpsilon);
|
||||
|
||||
return(kbEqual);
|
||||
}
|
||||
|
||||
const TVector2d& Add( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX + _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY + _krB.m_dY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Add( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX + _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY + _krB.m_fY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& Subtract(TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
_rResult.m_dX = _krA.m_dX - _krB.m_dX;
|
||||
_rResult.m_dY = _krA.m_dY - _krB.m_dY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Subtract(TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
_rResult.m_fX = _krA.m_fX - _krB.m_fX;
|
||||
_rResult.m_fY = _krA.m_fY - _krB.m_fY;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& ScalarMultiply( TVector2d& _rResult,
|
||||
const TVector2d& _krV,
|
||||
const double _kdS)
|
||||
{
|
||||
_rResult.m_dX = _krV.m_dX * _kdS;
|
||||
_rResult.m_dY = _krV.m_dY * _kdS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& ScalarMultiply( TVector2f& _rResult,
|
||||
const TVector2f& _krV,
|
||||
const float _kfS)
|
||||
{
|
||||
_rResult.m_fX = _krV.m_fX * _kfS;
|
||||
_rResult.m_fY = _krV.m_fY * _kfS;
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double VectorMagnitude(const TVector2d& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_dX)
|
||||
+ Square(_krV.m_dY)));
|
||||
}
|
||||
|
||||
const float VectorMagnitude(const TVector2f& _krV)
|
||||
{
|
||||
return(SquareRoot( Square(_krV.m_fX)
|
||||
+ Square(_krV.m_fY)));
|
||||
}
|
||||
|
||||
const double DotProduct( const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
return( (_krA.m_dX * _krB.m_dX)
|
||||
+ (_krA.m_dY * _krB.m_dY));
|
||||
}
|
||||
|
||||
const float DotProduct( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
return( (_krA.m_fX * _krB.m_fX)
|
||||
+ (_krA.m_fY * _krB.m_fY));
|
||||
}
|
||||
|
||||
const TVector2d& Normalize( TVector2d& _rResult,
|
||||
const TVector2d& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0 / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Normalize( TVector2f& _rResult,
|
||||
const TVector2f& _krV)
|
||||
{
|
||||
ScalarMultiply(_rResult, _krV, (1.0f / VectorMagnitude(_krV)) );
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2d& Projection( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector2d kNumer = ScalarMultiply(TVector2d(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kdDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const TVector2f& Projection( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfDenom = Square(VectorMagnitude(_krB));
|
||||
|
||||
const TVector2f kNumer = ScalarMultiply(TVector2f(), _krB, DotProduct(_krA, _krB));
|
||||
|
||||
_rResult = ScalarMultiply(_rResult, kNumer, kfDenom);
|
||||
|
||||
return(_rResult);
|
||||
}
|
||||
|
||||
const double AngleBetween(const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kdAngle);
|
||||
}
|
||||
|
||||
const float AngleBetween( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfAngle = ArcCos( DotProduct(_krA, _krB)
|
||||
/ ( VectorMagnitude(_krA) * VectorMagnitude(_krB) ) );
|
||||
|
||||
return(kfAngle);
|
||||
}
|
||||
|
||||
const double Distance(const TVector2d& _krA,
|
||||
const TVector2d& _krB)
|
||||
{
|
||||
const double kdDistance = VectorMagnitude(Subtract(TVector2d(), _krA, _krB));
|
||||
|
||||
return(kdDistance);
|
||||
}
|
||||
|
||||
const float Distance( const TVector2f& _krA,
|
||||
const TVector2f& _krB)
|
||||
{
|
||||
const float kfDistance = VectorMagnitude(Subtract(TVector2f(), _krA, _krB));
|
||||
|
||||
return(kfDistance);
|
||||
}
|
@ -1,272 +0,0 @@
|
||||
//
|
||||
// Author: Michael Cameron
|
||||
// Email: chronokun@hotmail.com
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __MATH_VECTOR_H__
|
||||
#define __MATH_VECTOR_H__
|
||||
|
||||
// Local Includes
|
||||
#include "ckmath_types.h"
|
||||
|
||||
// Vector Function Prototypes
|
||||
|
||||
|
||||
//
|
||||
// Vector 4
|
||||
//
|
||||
|
||||
const TVector4d& ZeroVector(TVector4d& _rResult);
|
||||
|
||||
const TVector4f& ZeroVector(TVector4f& _rResult);
|
||||
|
||||
const bool Equal( const TVector4d& _krA,
|
||||
const TVector4d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector4f& _krA,
|
||||
const TVector4f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector4d& Add( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Add( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& Subtract( TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Subtract( TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& ScalarMultiply(TVector4d& _rResult,
|
||||
const TVector4d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector4f& ScalarMultiply(TVector4f& _rResult,
|
||||
const TVector4f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector4d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector4f& _krV);
|
||||
|
||||
const double DotProduct(const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float DotProduct( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const TVector4d& Normalize( TVector4d& _rResult,
|
||||
const TVector4d& _krV);
|
||||
|
||||
const TVector4f& Normalize( TVector4f& _rResult,
|
||||
const TVector4f& _krV);
|
||||
|
||||
const TVector4d& Projection(TVector4d& _rResult,
|
||||
const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const TVector4f& Projection(TVector4f& _rResult,
|
||||
const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
const double Distance( const TVector4d& _krA,
|
||||
const TVector4d& _krB);
|
||||
|
||||
const float Distance( const TVector4f& _krA,
|
||||
const TVector4f& _krB);
|
||||
|
||||
//
|
||||
// Vector 3
|
||||
//
|
||||
|
||||
const TVector3d& ZeroVector(TVector3d& _rResult);
|
||||
|
||||
const TVector3f& ZeroVector(TVector3f& _rResult);
|
||||
|
||||
const bool Equal( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector3d& Add( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Add( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& Subtract( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Subtract( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& ScalarMultiply(TVector3d& _rResult,
|
||||
const TVector3d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector3f& ScalarMultiply(TVector3f& _rResult,
|
||||
const TVector3f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector3d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector3f& _krV);
|
||||
|
||||
const double DotProduct(const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float DotProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& CrossProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& CrossProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const TVector3d& Normalize( TVector3d& _rResult,
|
||||
const TVector3d& _krV);
|
||||
|
||||
const TVector3f& Normalize( TVector3f& _rResult,
|
||||
const TVector3f& _krV);
|
||||
|
||||
const TVector3d& Projection(TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const TVector3f& Projection(TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double Distance( const TVector3d& _krA,
|
||||
const TVector3d& _krB);
|
||||
|
||||
const float Distance( const TVector3f& _krA,
|
||||
const TVector3f& _krB);
|
||||
|
||||
const double ScalarTripleProduct( const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC);
|
||||
|
||||
const float ScalarTripleProduct( const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC);
|
||||
|
||||
const TVector3d& VectorTripleProduct( TVector3d& _rResult,
|
||||
const TVector3d& _krA,
|
||||
const TVector3d& _krB,
|
||||
const TVector3d& _krC);
|
||||
|
||||
const TVector3f& VectorTripleProduct( TVector3f& _rResult,
|
||||
const TVector3f& _krA,
|
||||
const TVector3f& _krB,
|
||||
const TVector3f& _krC);
|
||||
|
||||
//
|
||||
// Vector 2
|
||||
//
|
||||
|
||||
const TVector2d& ZeroVector(TVector2d& _rResult);
|
||||
|
||||
const TVector2f& ZeroVector(TVector2f& _rResult);
|
||||
|
||||
const bool Equal( const TVector2d& _krA,
|
||||
const TVector2d& _krB,
|
||||
const double _kdEpsilon);
|
||||
|
||||
const bool Equal( const TVector2f& _krA,
|
||||
const TVector2f& _krB,
|
||||
const float _kfEpsilon);
|
||||
|
||||
const TVector2d& Add( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Add( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& Subtract( TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Subtract( TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& ScalarMultiply(TVector2d& _rResult,
|
||||
const TVector2d& _krV,
|
||||
const double _kdS);
|
||||
|
||||
const TVector2f& ScalarMultiply(TVector2f& _rResult,
|
||||
const TVector2f& _krV,
|
||||
const float _kfS);
|
||||
|
||||
const double VectorMagnitude(const TVector2d& _krV);
|
||||
|
||||
const float VectorMagnitude(const TVector2f& _krV);
|
||||
|
||||
const double DotProduct(const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float DotProduct( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const TVector2d& Normalize( TVector2d& _rResult,
|
||||
const TVector2d& _krV);
|
||||
|
||||
const TVector2f& Normalize( TVector2f& _rResult,
|
||||
const TVector2f& _krV);
|
||||
|
||||
const TVector2d& Projection(TVector2d& _rResult,
|
||||
const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const TVector2f& Projection(TVector2f& _rResult,
|
||||
const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const double AngleBetween( const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float AngleBetween( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
const double Distance( const TVector2d& _krA,
|
||||
const TVector2d& _krB);
|
||||
|
||||
const float Distance( const TVector2f& _krA,
|
||||
const TVector2f& _krB);
|
||||
|
||||
|
||||
#endif
|
@ -18,14 +18,18 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
// Chronokun Libraries
|
||||
#include "ckmath/ckmath.h"
|
||||
/* // Chronokun Libraries
|
||||
#include "ckmath/ckmath.h" */
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
|
||||
// C++ Libraries
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
|
Loading…
Reference in New Issue
Block a user