diff --git a/graphics/tinygl/arrays.cpp b/graphics/tinygl/arrays.cpp index 0026237a37c..d1c8e109e88 100644 --- a/graphics/tinygl/arrays.cpp +++ b/graphics/tinygl/arrays.cpp @@ -25,18 +25,18 @@ void glopArrayElement(GLContext *c, GLParam *param) { } if (states & NORMAL_ARRAY) { i = idx * (3 + c->normal_array_stride); - 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.W = (0.0f); // NOTE: this used to be Z but assigning Z again seemed like a bug... + 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.W = 0.0f; // NOTE: this used to be Z but assigning Z again seemed like a bug... } if (states & TEXCOORD_ARRAY) { int size = c->texcoord_array_size; i = idx * (size + c->texcoord_array_stride); - c->current_tex_coord.X = (c->texcoord_array[i]); - c->current_tex_coord.Y = (c->texcoord_array[i + 1]); - c->current_tex_coord.Z = (size > 2 ? c->texcoord_array[i + 2] : 0.0f); - c->current_tex_coord.W = (size > 3 ? c->texcoord_array[i + 3] : 1.0f); + c->current_tex_coord.X = c->texcoord_array[i]; + c->current_tex_coord.Y = c->texcoord_array[i + 1]; + c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f; + c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f; } if (states & VERTEX_ARRAY) { GLParam p[5]; diff --git a/graphics/tinygl/clip.cpp b/graphics/tinygl/clip.cpp index 3049e5dae1b..4bf4e3f100d 100644 --- a/graphics/tinygl/clip.cpp +++ b/graphics/tinygl/clip.cpp @@ -175,8 +175,8 @@ static float name(Vector4 *c, Vector4 *a, Vector4 *b) { \ t = 0; \ else \ t = (sign a->dir - a->W) / den; \ - c-> dir1 = (a-> dir1 + t * d ## dir1); \ - c-> dir2 = (a-> dir2 + t * d ## dir2); \ + c-> dir1 = (a->dir1 + t * d ## dir1); \ + c-> dir2 = (a->dir2 + t * d ## dir2); \ c->W = (a->W + t * dW); \ c-> dir = (sign c->W); \ return t; \ @@ -205,7 +205,6 @@ static inline void updateTmp(GLContext *c, GLVertex *q, q->color.X = (p0->color.X); q->color.Y = (p0->color.Y); q->color.Z = (p0->color.Z); - //q->color = p0->color; } if (c->texture_2d_enabled) { diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp index 8edc0ec3548..23597262037 100644 --- a/graphics/tinygl/init.cpp +++ b/graphics/tinygl/init.cpp @@ -134,7 +134,7 @@ void glInit(void *zbuffer1) { c->matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH; for (int i = 0; i < 3; i++) { - c->matrix_stack[i] = (Matrix4*)gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(Matrix4)); + c->matrix_stack[i] = (Matrix4 *)gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(Matrix4)); c->matrix_stack_ptr[i] = c->matrix_stack[i]; } diff --git a/graphics/tinygl/light.cpp b/graphics/tinygl/light.cpp index 58eaa670d4a..41f7747ce26 100644 --- a/graphics/tinygl/light.cpp +++ b/graphics/tinygl/light.cpp @@ -214,7 +214,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) { att = 1.0f / (l->attenuation[0] + dist * (l->attenuation[1] + dist * l->attenuation[2])); } - dot = Vector3::dot(d, n); + dot = d.X * n.X + d.Y * n.Y + d.Z * n.Z;//Vector3::dot(d, n); if (twoside && dot < 0) dot = -dot; if (dot > 0) { @@ -225,7 +225,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) { // spot light if (l->spot_cutoff != 180) { - dot_spot = -Vector3::dot(d, l->norm_spot_direction); + dot_spot = -( d.X * l->norm_spot_direction.X + d.Y * l->norm_spot_direction.Y + d.Z * l->norm_spot_direction.Z); //Vector3::dot(d, l->norm_spot_direction); if (twoside && dot_spot < 0) dot_spot = -dot_spot; if (dot_spot < l->cos_spot_cutoff) { @@ -255,7 +255,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) { s = d; s.Z = (s.Z + 1.0); } - dot_spec = Vector3::dot(n, s); + dot_spec = n.X * s.X + n.Y + s.Y + n.Z * s.Z; //Vector3::dot(n, s); if (twoside && dot_spec < 0) dot_spec = -dot_spec; if (dot_spec > 0) { diff --git a/graphics/tinygl/matrix.cpp b/graphics/tinygl/matrix.cpp index 5be3da21c20..171a6018a07 100644 --- a/graphics/tinygl/matrix.cpp +++ b/graphics/tinygl/matrix.cpp @@ -168,12 +168,12 @@ void glopRotate(GLContext *c, GLParam *p) { } void glopScale(GLContext *c, GLParam *p) { - c->matrix_stack_ptr[c->matrix_mode]->scale(p[1].f,p[2].f,p[3].f); + c->matrix_stack_ptr[c->matrix_mode]->scale(p[1].f, p[2].f, p[3].f); gl_matrix_update(c); } void glopTranslate(GLContext *c, GLParam *p) { - c->matrix_stack_ptr[c->matrix_mode]->translate(p[1].f,p[2].f,p[3].f); + c->matrix_stack_ptr[c->matrix_mode]->translate(p[1].f, p[2].f, p[3].f); gl_matrix_update(c); } @@ -184,7 +184,7 @@ void glopFrustum(GLContext *c, GLParam *p) { float top = p[4].f; float nearp = p[5].f; float farp = p[6].f; - Matrix4 m = Matrix4::frustrum(left,right,bottom,top,nearp,farp); + Matrix4 m = Matrix4::frustrum(left, right, bottom, top, nearp, farp); *c->matrix_stack_ptr[c->matrix_mode] *= m; diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp index 3c17c58c94c..a2596fb69cc 100644 --- a/graphics/tinygl/vertex.cpp +++ b/graphics/tinygl/vertex.cpp @@ -141,14 +141,6 @@ static inline void gl_vertex_transform(GLContext *c, GLVertex *v) { m = c->matrix_stack_ptr[1]; v->pc = m->transform(v->ec); - /* - // NOTE: this transformation is not an ordinary matrix vector multiplication. - v->pc = Vector4(v->ec.getX() * m->get(0, 0) + v->ec.getY() * m->get(1, 0) + v->ec.getZ() * m->get(2, 0) + v->ec.getW() * m->get(3, 0), - v->ec.getX() * m->get(0, 1) + v->ec.getY() * m->get(1, 1) + v->ec.getZ() * m->get(2, 1) + v->ec.getW() * m->get(3, 1), - v->ec.getX() * m->get(0, 2) + v->ec.getY() * m->get(1, 2) + v->ec.getZ() * m->get(2, 2) + v->ec.getW() * m->get(3, 2), - v->ec.getX() * m->get(0, 3) + v->ec.getY() * m->get(1, 3) + v->ec.getZ() * m->get(2, 3) + v->ec.getW() * m->get(3, 3)); - */ - m = &c->matrix_model_view_inv; n = &c->current_normal; diff --git a/graphics/tinygl/zmath.cpp b/graphics/tinygl/zmath.cpp index 9511dec9fde..6ea4306908e 100644 --- a/graphics/tinygl/zmath.cpp +++ b/graphics/tinygl/zmath.cpp @@ -135,12 +135,6 @@ int Matrix_Inv(float *r, float *m, int n) { return true; } -Vector3::Vector3(float x, float y, float z) { - _v[0] = x; - _v[1] = y; - _v[2] = z; -} - void Vector3::normalize() { float n; n = sqrt(_v[0] * _v[0] + _v[1] * _v[1] + _v[2] * _v[2]); @@ -151,13 +145,6 @@ void Vector3::normalize() { } } -Vector4::Vector4(float x, float y, float z, float w) { - _v[0] = x; - _v[1] = y; - _v[2] = z; - _v[3] = w; -} - Vector4::Vector4(const Vector3 &vec, float w) { _v[0] = vec.X; _v[1] = vec.Y; @@ -276,10 +263,12 @@ bool Matrix4::IsIdentity() const { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i == j) { - if (_m[i][j] != 1.0) + if (_m[i][j] != 1.0) { return false; - } else if (_m[i][j] != 0.0) + } + } else if (_m[i][j] != 0.0) { return false; + } } } return true; diff --git a/graphics/tinygl/zmath.h b/graphics/tinygl/zmath.h index cc218ce2bce..cf46ebc76f1 100644 --- a/graphics/tinygl/zmath.h +++ b/graphics/tinygl/zmath.h @@ -12,16 +12,16 @@ namespace TinyGL { class Vector3 { public: Vector3() { } - Vector3(float x, float y, float z); + Vector3(float x, float y, float z) { + X = x; + Y = y; + Z = z; + } void normalize(); float getLength() const { return sqrt(_v[0] * _v[0] + _v[1] * _v[1] + _v[2] * _v[2]); } - static float dot(const Vector3 &a, const Vector3 &b) { - return a._v[0] * b._v[0] + a._v[1] * b._v[1] + a._v[2] * b._v[2]; - } - bool operator==(const Vector3 &other) const { return _v[0] == other._v[0] && _v[1] == other._v[1] && _v[2] == other._v[2]; } @@ -74,7 +74,13 @@ class Vector4 { public: Vector4() { } Vector4(const Vector3 &vec, float w); - Vector4(float x, float y, float z, float w); + + Vector4(float x, float y, float z, float w) { + X = x; + Y = y; + Z = z; + W = w; + } bool operator==(const Vector4 &other) const { return _v[0] == other._v[0] && _v[1] == other._v[1] && _v[2] == other._v[2] && _v[3] == other._v[3];