TINYGL: Added a first draft of the maths classes.

This commit is contained in:
Stefano Musumeci 2014-05-23 15:38:18 +01:00
parent 6951b5c0ee
commit 16ba2a7aee
3 changed files with 53 additions and 1 deletions

View file

@ -28,7 +28,7 @@ void glopArrayElement(GLContext *c, GLParam *param) {
c->current_normal.X = c->normal_array[i];
c->current_normal.Y = c->normal_array[i + 1];
c->current_normal.Z = c->normal_array[i + 2];
c->current_normal.Z = 0.0f;
c->current_normal.W = 0.0f;
}
if (states & TEXCOORD_ARRAY) {
int size = c->texcoord_array_size;

View file

@ -214,6 +214,7 @@ void gl_M4_Rotate(M4 *a, float t, int u) {
a->m[w][w] = c;
}
/*
// inverse of a 3x3 matrix
void gl_M3_Inv(M3 *a, const M3 *m) {
float det;
@ -234,6 +235,7 @@ void gl_M3_Inv(M3 *a, const M3 *m) {
a->m[2][1] = -(m->m[0][0] * m->m[2][1] - m->m[0][1] * m->m[2][0]) / det;
a->m[2][2] = (m->m[0][0] * m->m[1][1] - m->m[0][1] * m->m[1][0]) / det;
}
*/
// vector arithmetic

View file

@ -5,10 +5,60 @@ namespace TinyGL {
// Matrix & Vertex
class Vector3
{
public:
Vector3();
Vector3(float x, float y, float z);
Vector3 operator*(float value);
Vector3 operator+(const Vector3& other);
Vector3 operator-(const Vector3& other);
private:
float v[3];
};
class Vector4
{
public:
Vector4();
Vector4(float x, float y, float z, float w);
Vector4 operator*(float value);
Vector4 operator+(const Vector4& other);
Vector4 operator-(const Vector4& other);
private:
float v[4];
};
class Matrix4
{
public:
Matrix4();
Matrix4(const Matrix4& other);
Matrix4 operator=(const Matrix4& other);
Matrix4 operator*(const Matrix4& b);
static Matrix4 identity();
Matrix4 transpose() const;
Matrix4 inverseOrtho() const;
Matrix4 inverse() const;
Matrix4 rotation() const;
Vector3 transform(const Vector3& vector);
Vector4 transform(const Vector4& vector);
private:
float m[4][4];
};
struct M4 {
float m[4][4];
};
struct M3 {
float m[3][3];
};