apple2ix/src/video_util/matrixUtil.h
2015-10-22 21:09:13 -07:00

118 lines
3.4 KiB
C

/*
* Apple // emulator for *ix
*
* This software package is subject to the GNU General Public License
* version 3 or later (your choice) as published by the Free Software
* Foundation.
*
* Copyright 2013-2015 Aaron Culliney
*
*/
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
#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
void mtxMultiply(float *ret, const float *lhs, const float *rhs);
// MTX = IdentityMatrix
void mtxLoadIdentity(float *mtx);
// MTX = Transpos(SRC)
void mtxTranspose(float *mtx, const float *src);
// MTX = src^-1
void mtxInvert(float *mtx, const float *src);
// MTX = PerspectiveProjectionMatrix
void mtxLoadPerspective(float *mtx, float fov, float aspect, float nearZ, float farZ);
// MTX = OrthographicProjectionMatrix
void mtxLoadOrthographic(float *mtx, float left, float right, float bottom, float top, float nearZ, float farZ);
// MTX = ObliqueProjectionMatrix(src, clipPlane)
void mtxModifyObliqueProjection(float *mtx, const float *src, const float *plane);
// MTX = TranlationMatrix
void mtxLoadTranslate(float *mtx, float xTrans, float yTrans, float zTrans);
// MTX = ScaleMatrix
void mtxLoadScale(float *mtx, float xScale, float yScale, float zScale);
// MTX = RotateXYZMatrix
void mtxLoadRotate(float *mtx, float deg, float xAxis, float , float zAxis);
// MTX = RotateXMatrix
void mtxLoadRotateX(float *mtx, float deg);
// MTX = RotateYMatrix
void mtxLoadRotateY(float *mtx, float deg);
// MTX = RotateZMatrix
void mtxLoadRotateZ(float *mtx, float deg);
// MTX = MTX * TranslationMatrix - Similar to glTranslate
void mtxTranslateApply(float *mtx, float xTrans, float yTrans, float zTrans);
// MTX = MTX * ScaleMatrix - Similar to glScale
void mtxScaleApply(float *mtx, float xScale, float yScale, float zScale);
// MTX = MTX * RotateXYZMatrix - Similar to glRotate
void mtxRotateApply(float *mtx, float deg, float xAxis, float yAxis, float zAxis);
// MTX = MTX * RotateXMatrix
void mtxRotateXApply(float *mtx, float deg);
// MTX = MTX * RotateYMatrix
void mtxRotateYApply(float *mtx, float deg);
// MTX = MTX * RotateZMatrix
void mtxRotateZApply(float *mtx, float deg);
// MTX = TranslationMatrix * MTX
void mtxTranslateMatrix(float *mtx, float xTrans, float yTrans, float zTrans);
// MTX = ScaleMatrix * MTX
void mtxScaleMatrix(float *mtx, float xScale, float yScale, float zScale);
// MTX = RotateXYZMatrix * MTX
void mtxRotateMatrix(float *mtx, float rad, float xAxis, float yAxis, float zAxis);
// MTX = RotateXMatrix * MTX
void mtxRotateXMatrix(float *mtx, float rad);
// MTX = RotateYMatrix * MTX
void mtxRotateYMatrix(float *mtx, float rad);
// MTX = RotateZMatrix * MTX
void mtxRotateZMatrix(float *mtx, float rad);
// 3x3 MTX = 3x3 IdentityMatrix
void mtx3x3LoadIdentity(float *mtx);
// 3x3 MTX = 3x3 LHS x 3x3 RHS
void mtx3x3Multiply(float *mtx, const float *lhs, const float *rhs);
// 3x3 MTX = TopLeft of MTX
void mtx3x3FromTopLeftOf4x4(float *mtx, const float *src);
// 3x3 MTX = Transpose(3x3 SRC)
void mtx3x3Transpose(float *mtx, const float *src);
// 3x3 MTX = 3x3 SRC^-1
void mtx3x3Invert(float *mtx, const float *src);
#endif //__MATRIX_UTIL_H__