2014-07-13 10:14:12 +00:00
|
|
|
|
|
|
|
// Matrix class based on code from VSML:
|
|
|
|
|
|
|
|
/** ----------------------------------------------------------
|
|
|
|
* \class VSMathLib
|
|
|
|
*
|
|
|
|
* Lighthouse3D
|
|
|
|
*
|
|
|
|
* VSMathLib - Very Simple Matrix Library
|
|
|
|
*
|
|
|
|
* Full documentation at
|
|
|
|
* http://www.lighthouse3d.com/very-simple-libs
|
|
|
|
*
|
|
|
|
* This class aims at easing geometric transforms, camera
|
|
|
|
* placement and projection definition for programmers
|
|
|
|
* working with OpenGL core versions.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
---------------------------------------------------------------*/
|
|
|
|
#ifndef __VSMatrix__
|
|
|
|
#define __VSMatrix__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
#ifdef USE_DOUBLE
|
|
|
|
typedef double FLOATTYPE;
|
|
|
|
#else
|
|
|
|
typedef float FLOATTYPE;
|
|
|
|
#endif
|
|
|
|
|
2014-07-13 10:14:12 +00:00
|
|
|
class VSMatrix {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
VSMatrix()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VSMatrix(int)
|
|
|
|
{
|
|
|
|
loadIdentity();
|
|
|
|
}
|
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
void translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
|
|
|
void scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
|
|
|
void rotate(FLOATTYPE angle, FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
2014-07-13 10:14:12 +00:00
|
|
|
void loadIdentity();
|
2014-07-13 18:41:20 +00:00
|
|
|
#ifdef USE_DOUBLE
|
2014-07-13 10:14:12 +00:00
|
|
|
void multMatrix(const float *aMatrix);
|
2014-07-13 18:41:20 +00:00
|
|
|
#endif
|
|
|
|
void multMatrix(const FLOATTYPE *aMatrix);
|
2014-07-13 10:14:12 +00:00
|
|
|
void multMatrix(const VSMatrix &aMatrix)
|
|
|
|
{
|
|
|
|
multMatrix(aMatrix.mMatrix);
|
|
|
|
}
|
2014-07-13 18:41:20 +00:00
|
|
|
void loadMatrix(const FLOATTYPE *aMatrix);
|
|
|
|
#ifdef USE_DOUBLE
|
2014-07-13 10:14:12 +00:00
|
|
|
void loadMatrix(const float *aMatrix);
|
2014-07-13 18:41:20 +00:00
|
|
|
#endif
|
|
|
|
void lookAt(FLOATTYPE xPos, FLOATTYPE yPos, FLOATTYPE zPos, FLOATTYPE xLook, FLOATTYPE yLook, FLOATTYPE zLook, FLOATTYPE xUp, FLOATTYPE yUp, FLOATTYPE zUp);
|
|
|
|
void perspective(FLOATTYPE fov, FLOATTYPE ratio, FLOATTYPE nearp, FLOATTYPE farp);
|
|
|
|
void ortho(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp=-1.0f, FLOATTYPE farp=1.0f);
|
|
|
|
void frustum(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp, FLOATTYPE farp);
|
|
|
|
void copy(FLOATTYPE * pDest)
|
2014-07-13 10:14:12 +00:00
|
|
|
{
|
2014-07-13 18:41:20 +00:00
|
|
|
memcpy(pDest, mMatrix, 16 * sizeof(FLOATTYPE));
|
2014-07-13 10:14:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
#ifdef USE_DOUBLE
|
2014-07-13 10:14:12 +00:00
|
|
|
void copy(float * pDest)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
pDest[i] = (float)mMatrix[i];
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 18:41:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const FLOATTYPE *get() const
|
|
|
|
{
|
|
|
|
return mMatrix;
|
|
|
|
}
|
2014-07-13 10:14:12 +00:00
|
|
|
|
|
|
|
void matrixToGL(int location);
|
2014-07-13 18:41:20 +00:00
|
|
|
void multMatrixPoint(const FLOATTYPE *point, FLOATTYPE *res);
|
2014-07-13 10:14:12 +00:00
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
#ifdef USE_DOUBLE
|
2014-07-13 10:14:12 +00:00
|
|
|
void computeNormalMatrix(const float *aMatrix);
|
2014-07-13 18:41:20 +00:00
|
|
|
#endif
|
|
|
|
void computeNormalMatrix(const FLOATTYPE *aMatrix);
|
2014-07-13 10:14:12 +00:00
|
|
|
void computeNormalMatrix(const VSMatrix &aMatrix)
|
|
|
|
{
|
|
|
|
computeNormalMatrix(aMatrix.mMatrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-13 18:41:20 +00:00
|
|
|
static void crossProduct(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
|
|
|
static FLOATTYPE dotProduct(const FLOATTYPE *a, const FLOATTYPE * b);
|
|
|
|
static void normalize(FLOATTYPE *a);
|
|
|
|
static void subtract(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
|
|
|
static void add(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
|
|
|
static FLOATTYPE length(const FLOATTYPE *a);
|
|
|
|
static void multMatrix(FLOATTYPE *resMatrix, const FLOATTYPE *aMatrix);
|
2014-07-13 10:14:12 +00:00
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
static void setIdentityMatrix(FLOATTYPE *mat, int size = 4);
|
2014-07-13 10:14:12 +00:00
|
|
|
|
|
|
|
/// The storage for matrices
|
2014-07-13 18:41:20 +00:00
|
|
|
FLOATTYPE mMatrix[16];
|
2014-07-13 10:14:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|