2014-09-27 18:03:51 +00:00
|
|
|
/*
|
2014-10-08 04:59:21 +00:00
|
|
|
* Apple // emulator for *nix
|
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
|
|
|
* version 2 or later (your choice) as published by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* THERE ARE NO WARRANTIES WHATSOEVER.
|
|
|
|
*
|
2014-09-27 18:03:51 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-08 04:59:21 +00:00
|
|
|
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
|
|
|
|
2014-09-27 18:03:51 +00:00
|
|
|
#ifndef __MATRIX_UTIL_H__
|
|
|
|
#define __MATRIX_UTIL_H__
|
|
|
|
|
|
|
|
// Matrix is a column major floating point array
|
|
|
|
|
|
|
|
// All matrices are 4x4 by unless the mtx3x3 prefix is specified in the function name
|
|
|
|
|
|
|
|
// [ 0 4 8 12 ]
|
|
|
|
// [ 1 5 9 13 ]
|
|
|
|
// [ 2 6 10 14 ]
|
|
|
|
// [ 3 7 11 15 ]
|
|
|
|
|
|
|
|
// MTX = LeftHandSideMatrix * RightHandSideMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxMultiply(float *ret, const float *lhs, const float *rhs);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = IdentityMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadIdentity(float *mtx);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = Transpos(SRC)
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxTranspose(float *mtx, const float *src);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = src^-1
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxInvert(float *mtx, const float *src);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = PerspectiveProjectionMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadPerspective(float *mtx, float fov, float aspect, float nearZ, float farZ);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = OrthographicProjectionMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadOrthographic(float *mtx, float left, float right, float bottom, float top, float nearZ, float farZ);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = ObliqueProjectionMatrix(src, clipPlane)
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxModifyObliqueProjection(float *mtx, const float *src, const float *plane);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = TranlationMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadTranslate(float *mtx, float xTrans, float yTrans, float zTrans);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = ScaleMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadScale(float *mtx, float xScale, float yScale, float zScale);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateXYZMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadRotate(float *mtx, float deg, float xAxis, float , float zAxis);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateXMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadRotateX(float *mtx, float deg);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateYMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadRotateY(float *mtx, float deg);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateZMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxLoadRotateZ(float *mtx, float deg);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * TranslationMatrix - Similar to glTranslate
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxTranslateApply(float *mtx, float xTrans, float yTrans, float zTrans);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * ScaleMatrix - Similar to glScale
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxScaleApply(float *mtx, float xScale, float yScale, float zScale);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * RotateXYZMatrix - Similar to glRotate
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateApply(float *mtx, float deg, float xAxis, float yAxis, float zAxis);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * RotateXMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateXApply(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * RotateYMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateYApply(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = MTX * RotateZMatrix
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateZApply(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = TranslationMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxTranslateMatrix(float *mtx, float xTrans, float yTrans, float zTrans);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = ScaleMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxScaleMatrix(float *mtx, float xScale, float yScale, float zScale);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateXYZMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateMatrix(float *mtx, float rad, float xAxis, float yAxis, float zAxis);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateXMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateXMatrix(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateYMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateYMatrix(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// MTX = RotateZMatrix * MTX
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtxRotateZMatrix(float *mtx, float rad);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
2014-10-08 04:59:21 +00:00
|
|
|
// 3x3 MTX = 3x3 IdentityMatrix
|
|
|
|
void mtx3x3LoadIdentity(float *mtx);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// 3x3 MTX = 3x3 LHS x 3x3 RHS
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtx3x3Multiply(float *mtx, const float *lhs, const float *rhs);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
2014-10-08 04:59:21 +00:00
|
|
|
// 3x3 MTX = TopLeft of MTX
|
|
|
|
void mtx3x3FromTopLeftOf4x4(float *mtx, const float *src);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// 3x3 MTX = Transpose(3x3 SRC)
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtx3x3Transpose(float *mtx, const float *src);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
// 3x3 MTX = 3x3 SRC^-1
|
2014-10-08 04:59:21 +00:00
|
|
|
void mtx3x3Invert(float *mtx, const float *src);
|
2014-09-27 18:03:51 +00:00
|
|
|
|
|
|
|
#endif //__MATRIX_UTIL_H__
|
|
|
|
|