summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2009-07-28 16:31:37 -0700
committerIan Romanick <ian.d.romanick@intel.com>2009-07-28 16:31:37 -0700
commit2d8b927979d360b51d8c22ebcb3b89e4edf1d7d8 (patch)
tree6390bb7f9f4870b8d5228fc8fe12a05225d80079
parent12ecec6e0fe5ac971b9291d6e1e2c1064dfb7469 (diff)
Pass pointer to result instead of returning a structure
Functions that used to return either GLUvec4 or GLUmat4 have been modified to take a pointer to the location to store the result. Any functions where the result pointer could also be a source pointer are coded to calculate to a temporary and copy the result, if necessary.
-rw-r--r--include/glu3.h62
-rw-r--r--include/glu3_scalar.h269
-rw-r--r--src/matrix.c169
3 files changed, 232 insertions, 268 deletions
diff --git a/include/glu3.h b/include/glu3.h
index 68bf7ef..7760744 100644
--- a/include/glu3.h
+++ b/include/glu3.h
@@ -128,39 +128,39 @@ GLfloat gluDot4_4v(const GLUvec4 *, const GLUvec4 *);
GLfloat gluDot3_4v(const GLUvec4 *, const GLUvec4 *);
GLfloat gluDot2_4v(const GLUvec4 *, const GLUvec4 *);
-GLUvec4 gluCross4v(const GLUvec4 *, const GLUvec4 *);
-GLUvec4 gluNormalize4v(const GLUvec4 *);
+void gluCross4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
+void gluNormalize4v(GLUvec4 *result, const GLUvec4 *);
GLfloat gluLength4v(const GLUvec4 *);
GLfloat gluLengthSqr4v(const GLUvec4 *);
-GLUmat4 gluOuter4v(const GLUvec4 *, const GLUvec4 *);
-
-
-GLUvec4 gluMult4v_4v(const GLUvec4 *, const GLUvec4 *);
-GLUvec4 gluDiv4v_4v(const GLUvec4 *, const GLUvec4 *);
-GLUvec4 gluAdd4v_4v(const GLUvec4 *, const GLUvec4 *);
-GLUvec4 gluSub4v_4v(const GLUvec4 *, const GLUvec4 *);
-
-GLUvec4 gluMult4v_f(const GLUvec4 *, GLfloat);
-GLUvec4 gluDiv4v_f(const GLUvec4 *, GLfloat);
-GLUvec4 gluAdd4v_f(const GLUvec4 *, GLfloat);
-GLUvec4 gluSub4v_f(const GLUvec4 *, GLfloat);
-
-GLUmat4 gluMult4m_4m(const GLUmat4 *, const GLUmat4 *);
-GLUmat4 gluAdd4m_4m(const GLUmat4 *, const GLUmat4 *);
-GLUmat4 gluSub4m_4m(const GLUmat4 *, const GLUmat4 *);
-GLUvec4 gluMult4m_4v(const GLUmat4 *m, const GLUvec4 *v);
-
-GLUmat4 gluMult4m_f(const GLUmat4 *, GLfloat);
-
-GLUmat4 gluScale4v(const GLUvec4 *);
-GLUmat4 gluTranslate3(GLfloat x, GLfloat y, GLfloat z);
-GLUmat4 gluTranslate4v(const GLUvec4 *);
-GLUmat4 gluRotate4v(const GLUvec4 *axis, GLfloat angle);
-GLUmat4 gluLookAt4v(const GLUvec4 *eye, const GLUvec4 *center,
- const GLUvec4 *up);
-GLUmat4 gluPerspective4(GLfloat fovy, GLfloat aspect, GLfloat near,
- GLfloat far);
-GLUmat4 gluTranspose4(const GLUmat4 *m);
+void gluOuter4v(GLUmat4 *result, const GLUvec4 *, const GLUvec4 *);
+
+
+void gluMult4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
+void gluDiv4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
+void gluAdd4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
+void gluSub4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
+
+void gluMult4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
+void gluDiv4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
+void gluAdd4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
+void gluSub4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
+
+void gluMult4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
+void gluAdd4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
+void gluSub4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
+void gluMult4m_4v(GLUvec4 *result, const GLUmat4 *m, const GLUvec4 *v);
+
+void gluMult4m_f(GLUmat4 *result, const GLUmat4 *, GLfloat);
+
+void gluScale4v(GLUmat4 *result, const GLUvec4 *);
+void gluTranslate3(GLUmat4 *result, GLfloat x, GLfloat y, GLfloat z);
+void gluTranslate4v(GLUmat4 *result, const GLUvec4 *);
+void gluRotate4v(GLUmat4 *result, const GLUvec4 *axis, GLfloat angle);
+void gluLookAt4v(GLUmat4 *result, const GLUvec4 *eye, const GLUvec4 *center,
+ const GLUvec4 *up);
+void gluPerspective4(GLUmat4 *result, GLfloat fovy, GLfloat aspect,
+ GLfloat near, GLfloat far);
+void gluTranspose4(GLUmat4 *result, const GLUmat4 *m);
extern const GLUmat4 gluIdentityMatrix;
diff --git a/include/glu3_scalar.h b/include/glu3_scalar.h
index eadc6d4..74359b8 100644
--- a/include/glu3_scalar.h
+++ b/include/glu3_scalar.h
@@ -1,158 +1,136 @@
#include <math.h>
-extern inline GLUvec4 gluMult4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluMult4v_4v(GLUvec4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] * v2->values[0];
- result.values[1] = v1->values[1] * v2->values[1];
- result.values[2] = v1->values[2] * v2->values[2];
- result.values[3] = v1->values[3] * v2->values[3];
-
- return result;
+ result->values[0] = v1->values[0] * v2->values[0];
+ result->values[1] = v1->values[1] * v2->values[1];
+ result->values[2] = v1->values[2] * v2->values[2];
+ result->values[3] = v1->values[3] * v2->values[3];
}
-extern inline GLUvec4 gluDiv4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluDiv4v_4v(GLUvec4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] / v2->values[0];
- result.values[1] = v1->values[1] / v2->values[1];
- result.values[2] = v1->values[2] / v2->values[2];
- result.values[3] = v1->values[3] / v2->values[3];
-
- return result;
+ result->values[0] = v1->values[0] / v2->values[0];
+ result->values[1] = v1->values[1] / v2->values[1];
+ result->values[2] = v1->values[2] / v2->values[2];
+ result->values[3] = v1->values[3] / v2->values[3];
}
-extern inline GLUvec4 gluAdd4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluAdd4v_4v(GLUvec4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] + v2->values[0];
- result.values[1] = v1->values[1] + v2->values[1];
- result.values[2] = v1->values[2] + v2->values[2];
- result.values[3] = v1->values[3] + v2->values[3];
-
- return result;
+ result->values[0] = v1->values[0] + v2->values[0];
+ result->values[1] = v1->values[1] + v2->values[1];
+ result->values[2] = v1->values[2] + v2->values[2];
+ result->values[3] = v1->values[3] + v2->values[3];
}
-extern inline GLUvec4 gluSub4v_4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluSub4v_4v(GLUvec4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] - v2->values[0];
- result.values[1] = v1->values[1] - v2->values[1];
- result.values[2] = v1->values[2] - v2->values[2];
- result.values[3] = v1->values[3] - v2->values[3];
-
- return result;
+ result->values[0] = v1->values[0] - v2->values[0];
+ result->values[1] = v1->values[1] - v2->values[1];
+ result->values[2] = v1->values[2] - v2->values[2];
+ result->values[3] = v1->values[3] - v2->values[3];
}
-extern inline GLUvec4 gluMult4v_f(const GLUvec4 *v1, GLfloat f)
+extern inline void gluMult4v_f(GLUvec4 *result,
+ const GLUvec4 *v1, GLfloat f)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] * f;
- result.values[1] = v1->values[1] * f;
- result.values[2] = v1->values[2] * f;
- result.values[3] = v1->values[3] * f;
-
- return result;
+ result->values[0] = v1->values[0] * f;
+ result->values[1] = v1->values[1] * f;
+ result->values[2] = v1->values[2] * f;
+ result->values[3] = v1->values[3] * f;
}
-extern inline GLUvec4 gluDiv4v_f(const GLUvec4 *v1, GLfloat f)
+extern inline void gluDiv4v_f(GLUvec4 *result,
+ const GLUvec4 *v1, GLfloat f)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] / f;
- result.values[1] = v1->values[1] / f;
- result.values[2] = v1->values[2] / f;
- result.values[3] = v1->values[3] / f;
-
- return result;
+ result->values[0] = v1->values[0] / f;
+ result->values[1] = v1->values[1] / f;
+ result->values[2] = v1->values[2] / f;
+ result->values[3] = v1->values[3] / f;
}
-extern inline GLUvec4 gluAdd4v_f(const GLUvec4 *v1, GLfloat f)
+extern inline void gluAdd4v_f(GLUvec4 *result,
+ const GLUvec4 *v1, GLfloat f)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] + f;
- result.values[1] = v1->values[1] + f;
- result.values[2] = v1->values[2] + f;
- result.values[3] = v1->values[3] + f;
-
- return result;
+ result->values[0] = v1->values[0] + f;
+ result->values[1] = v1->values[1] + f;
+ result->values[2] = v1->values[2] + f;
+ result->values[3] = v1->values[3] + f;
}
-extern inline GLUvec4 gluSub4v_f(const GLUvec4 *v1, GLfloat f)
+extern inline void gluSub4v_f(GLUvec4 *result,
+ const GLUvec4 *v1, GLfloat f)
{
- GLUvec4 result;
-
- result.values[0] = v1->values[0] - f;
- result.values[1] = v1->values[1] - f;
- result.values[2] = v1->values[2] - f;
- result.values[3] = v1->values[3] - f;
-
- return result;
+ result->values[0] = v1->values[0] - f;
+ result->values[1] = v1->values[1] - f;
+ result->values[2] = v1->values[2] - f;
+ result->values[3] = v1->values[3] - f;
}
-extern inline GLUmat4 gluMult4m_f(const GLUmat4 *m, GLfloat f)
+extern inline void gluMult4m_f(GLUmat4 *result,
+ const GLUmat4 *m, GLfloat f)
{
- GLUmat4 result;
-
- result.col[0] = gluMult4v_f(& m->col[0], f);
- result.col[1] = gluMult4v_f(& m->col[1], f);
- result.col[2] = gluMult4v_f(& m->col[2], f);
- result.col[3] = gluMult4v_f(& m->col[3], f);
+ GLUmat4 temp;
- return result;
+ gluMult4v_f(& temp.col[0], & m->col[0], f);
+ gluMult4v_f(& temp.col[1], & m->col[1], f);
+ gluMult4v_f(& temp.col[2], & m->col[2], f);
+ gluMult4v_f(& temp.col[3], & m->col[3], f);
+ *result = temp;
}
-extern inline GLUvec4 gluMult4m_4v(const GLUmat4 *m, const GLUvec4 *v)
+extern inline void gluMult4m_4v(GLUvec4 *result,
+ const GLUmat4 *m, const GLUvec4 *v)
{
- GLUvec4 a = gluMult4v_f(& m->col[0], v->values[0]);
- GLUvec4 b = gluMult4v_f(& m->col[1], v->values[1]);
- GLUvec4 c = gluMult4v_f(& m->col[2], v->values[2]);
- GLUvec4 d = gluMult4v_f(& m->col[3], v->values[3]);
+ GLUvec4 temp[6];
+ unsigned i;
- a = gluAdd4v_4v(&a, &b);
- c = gluAdd4v_4v(&c, &d);
+ for (i = 0; i < 4; i++) {
+ gluMult4v_f(& temp[i], & m->col[i], v->values[i]);
+ }
- return gluAdd4v_4v(&a, &c);
+ gluAdd4v_4v(& temp[4], & temp[0], & temp[1]);
+ gluAdd4v_4v(& temp[5], & temp[2], & temp[3]);
+ gluAdd4v_4v(result, & temp[4], & temp[5]);
}
-extern inline GLUmat4 gluAdd4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
+extern inline void gluAdd4m_4m(GLUmat4 *result,
+ const GLUmat4 *m1, const GLUmat4 *m2)
{
- GLUmat4 result;
-
- result.col[0] = gluAdd4v_4v(& m1->col[0], & m2->col[0]);
- result.col[1] = gluAdd4v_4v(& m1->col[1], & m2->col[1]);
- result.col[2] = gluAdd4v_4v(& m1->col[2], & m2->col[2]);
- result.col[3] = gluAdd4v_4v(& m1->col[3], & m2->col[3]);
+ GLUmat4 temp;
- return result;
+ gluAdd4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
+ gluAdd4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
+ gluAdd4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
+ gluAdd4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
+ *result = temp;
}
-extern inline GLUmat4 gluSub4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
+extern inline void gluSub4m_4m(GLUmat4 *result,
+ const GLUmat4 *m1, const GLUmat4 *m2)
{
- GLUmat4 result;
-
- result.col[0] = gluSub4v_4v(& m1->col[0], & m2->col[0]);
- result.col[1] = gluSub4v_4v(& m1->col[1], & m2->col[1]);
- result.col[2] = gluSub4v_4v(& m1->col[2], & m2->col[2]);
- result.col[3] = gluSub4v_4v(& m1->col[3], & m2->col[3]);
+ GLUmat4 temp;
- return result;
+ gluSub4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
+ gluSub4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
+ gluSub4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
+ gluSub4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
+ *result = temp;
}
extern inline GLfloat gluDot4_4v(const GLUvec4 *v1, const GLUvec4 *v2)
@@ -179,32 +157,32 @@ extern inline GLfloat gluDot2_4v(const GLUvec4 *v1, const GLUvec4 *v2)
}
-extern inline GLUvec4 gluCross4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluCross4v(GLUvec4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUvec4 result;
+ GLUvec4 temp;
- result.values[0] = (v1->values[1] * v2->values[2])
+ temp.values[0] = (v1->values[1] * v2->values[2])
- (v1->values[2] * v2->values[1]);
- result.values[1] = (v1->values[2] * v2->values[0])
+ temp.values[1] = (v1->values[2] * v2->values[0])
- (v1->values[0] * v2->values[2]);
- result.values[2] = (v1->values[0] * v2->values[1])
+ temp.values[2] = (v1->values[0] * v2->values[1])
- (v1->values[1] * v2->values[0]);
- result.values[3] = 0.0;
-
- return result;
+ temp.values[3] = 0.0;
+ *result = temp;
}
-extern inline GLUmat4 gluOuter4v(const GLUvec4 *v1, const GLUvec4 *v2)
+extern inline void gluOuter4v(GLUmat4 *result,
+ const GLUvec4 *v1, const GLUvec4 *v2)
{
- GLUmat4 result;
-
- result.col[0] = gluMult4v_f(v1, v2->values[0]);
- result.col[1] = gluMult4v_f(v1, v2->values[1]);
- result.col[2] = gluMult4v_f(v1, v2->values[2]);
- result.col[3] = gluMult4v_f(v1, v2->values[3]);
+ GLUmat4 temp;
- return result;
+ gluMult4v_f(& temp.col[0], v1, v2->values[0]);
+ gluMult4v_f(& temp.col[1], v1, v2->values[1]);
+ gluMult4v_f(& temp.col[2], v1, v2->values[2]);
+ gluMult4v_f(& temp.col[3], v1, v2->values[3]);
+ *result = temp;
}
@@ -220,53 +198,51 @@ extern inline GLfloat gluLength4v(const GLUvec4 *v)
}
-extern inline GLUvec4 gluNormalize4v(const GLUvec4 *v)
+extern inline void gluNormalize4v(GLUvec4 *result, const GLUvec4 *v)
{
- return gluDiv4v_f(v, gluLength4v(v));
+ gluDiv4v_f(result, v, gluLength4v(v));
}
-extern inline GLUmat4 gluTranspose4(const GLUmat4 *m)
+extern inline void gluTranspose4(GLUmat4 *result, const GLUmat4 *m)
{
unsigned i;
unsigned j;
- GLUmat4 result;
+ GLUmat4 temp;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
- result.col[i].values[j] = m->col[j].values[i];
+ temp.col[i].values[j] = m->col[j].values[i];
}
}
- return result;
+ *result = temp;
}
-extern inline GLUmat4 gluMult4m_4m(const GLUmat4 *m1, const GLUmat4 *m2)
+extern inline void gluMult4m_4m(GLUmat4 *result,
+ const GLUmat4 *m1, const GLUmat4 *m2)
{
- GLUmat4 result;
+ GLUmat4 temp;
unsigned i;
for (i = 0; i < 4; i++) {
- result.col[i] = gluMult4m_4v(m1, & m2->col[i]);
+ gluMult4m_4v(& temp.col[i], m1, & m2->col[i]);
}
- return result;
+ *result = temp;
}
-extern inline GLUmat4 gluTranslate3(GLfloat x, GLfloat y, GLfloat z)
+extern inline void gluTranslate3(GLUmat4 *result,
+ GLfloat x, GLfloat y, GLfloat z)
{
- GLUmat4 result;
-
- memcpy(&result, & gluIdentityMatrix, sizeof(result));
- result.col[3].values[0] = x;
- result.col[3].values[1] = y;
- result.col[3].values[2] = z;
-
- return result;
+ memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
+ result->col[3].values[0] = x;
+ result->col[3].values[1] = y;
+ result->col[3].values[2] = z;
}
@@ -342,7 +318,10 @@ inline GLUvec4 GLUvec4::operator*(const GLUmat4 &m) const
inline GLUmat4 GLUmat4::operator+(const GLUmat4 &m) const
{
- return gluAdd4m_4m(this, &m);
+ GLUmat4 temp;
+
+ gluAdd4m_4m(& temp, this, &m);
+ return temp;
}
@@ -357,7 +336,10 @@ inline GLUmat4 GLUmat4::operator-(const GLUmat4 &m) const
inline GLUmat4 GLUmat4::operator*(GLfloat f) const
{
- return gluMult4m_f(this, f);
+ GLUmat4 temp;
+
+ gluMult4m_f(& temp, this, f);
+ return temp;
}
@@ -372,7 +354,10 @@ inline GLUvec4 GLUmat4::operator*(const GLUvec4 &v) const
inline GLUmat4 GLUmat4::operator*(const GLUmat4 &m) const
{
- return gluMult4m_4m(this, &m);
+ GLUmat4 temp;
+
+ gluMult4m_4m(& temp, this, &m);
+ return temp;
}
diff --git a/src/matrix.c b/src/matrix.c
index bf6a9df..48a862f 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -36,53 +36,47 @@ const GLUmat4 gluIdentityMatrix = {
};
-GLUmat4 gluTranslate4v(const GLUvec4 *t)
+void gluTranslate4v(GLUmat4 *result, const GLUvec4 *t)
{
- GLUmat4 result;
-
- memcpy(& result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
- result.col[3] = *t;
- result.col[3].values[3] = 1.0f;
-
- return result;
+ memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
+ result->col[3] = *t;
+ result->col[3].values[3] = 1.0f;
}
-GLUmat4 gluScale4v(const GLUvec4 *t)
+void gluScale4v(GLUmat4 *result, const GLUvec4 *t)
{
- GLUmat4 result;
-
- memcpy(& result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
- result.col[0].values[0] = t->values[0];
- result.col[1].values[1] = t->values[1];
- result.col[2].values[2] = t->values[2];
-
- return result;
+ memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
+ result->col[0].values[0] = t->values[0];
+ result->col[1].values[1] = t->values[1];
+ result->col[2].values[2] = t->values[2];
}
-GLUmat4 gluLookAt4v(const GLUvec4 *eye,
- const GLUvec4 *center,
- const GLUvec4 *up)
+void gluLookAt4v(GLUmat4 *result,
+ const GLUvec4 *eye,
+ const GLUvec4 *center,
+ const GLUvec4 *up)
{
static const GLUvec4 col3 = { { 0.0f, 0.0f, 0.0f, 1.0f } };
const GLUvec4 e = {
{ -eye->values[0], -eye->values[1], -eye->values[2], 0.0f }
};
- const GLUmat4 translate = gluTranslate4v(& e);
+ GLUmat4 translate;
GLUmat4 rotate;
+ GLUmat4 rotateT;
GLUvec4 f;
GLUvec4 s;
GLUvec4 u;
- f = gluSub4v_4v(center, eye);
- f = gluNormalize4v(& f);
+ gluSub4v_4v(& f, center, eye);
+ gluNormalize4v(& f, & f);
- u = gluNormalize4v(up);
+ gluNormalize4v(& u, up);
- s = gluCross4v(& f, & u);
- u = gluCross4v(& s, & f);
+ gluCross4v(& s, & f, & u);
+ gluCross4v(& u, & s, & f);
rotate.col[0] = s;
rotate.col[1] = u;
@@ -91,105 +85,90 @@ GLUmat4 gluLookAt4v(const GLUvec4 *eye,
rotate.col[2].values[2] = -f.values[2];
rotate.col[2].values[3] = 0.0f;
rotate.col[3] = col3;
- rotate = gluTranspose4(& rotate);
+ gluTranspose4(& rotateT, & rotate);
- return gluMult4m_4m(& rotate, & translate);
+ gluTranslate4v(& translate, & e);
+ gluMult4m_4m(result, & rotateT, & translate);
}
-GLUmat4 gluRotate4v(const GLUvec4 *_axis, GLfloat angle)
+void gluRotate4v(GLUmat4 *result, const GLUvec4 *_axis, GLfloat angle)
{
-#if 0
- GLUvec4 axis = gluNormalize4v(_axis);
- GLUmat4 E = {
- {
- { { 0.0f, -axis.values[2], axis.values[1], 0.0f } },
- { { axis.values[3], 0.0f, -axis.values[0], 0.0f } },
- { { -axis.values[1], axis.values[0], 0.0f, 0.0f } },
- { { 0.0f, 0.0f, 0.0f, 1.0f } }
- }
- };
-
- const GLfloat cos_a = cos(angle);
- const GLfloat sin_a = sin(angle);
+ GLUvec4 axis;
+ const float c = cos(angle);
+ const float s = sin(angle);
+ const float one_c = 1.0 - c;
- GLUmat4 O = gluOuter4v(&axis, &axis);
- const GLUmat4 I = gluMult4m_f(& gluIdentityMatrix, cos_a);
- GLUmat4 temp;
+ float xx;
+ float yy;
+ float zz;
+ float xs;
+ float ys;
+ float zs;
- E = gluMult4m_f(& E, -sin_a);
- O = gluMult4m_f(& O, 1.0f - cos_a);
+ float xy;
+ float xz;
+ float yz;
- temp = gluAdd4m_4m(& I, & O);
- return gluAdd4m_4m(& temp, & E);
-#else
- GLUvec4 axis = gluNormalize4v(_axis);
- GLUmat4 m;
- const float c = cos(angle);
- const float s = sin(angle);
- const float one_c = 1.0 - c;
- const float xx = axis.values[0] * axis.values[0];
- const float yy = axis.values[1] * axis.values[1];
- const float zz = axis.values[2] * axis.values[2];
+ gluNormalize4v(& axis, _axis);
- const float xs = axis.values[0] * s;
- const float ys = axis.values[1] * s;
- const float zs = axis.values[2] * s;
+ xx = axis.values[0] * axis.values[0];
+ yy = axis.values[1] * axis.values[1];
+ zz = axis.values[2] * axis.values[2];
- const float xy = axis.values[0] * axis.values[1];
- const float xz = axis.values[0] * axis.values[2];
- const float yz = axis.values[1] * axis.values[2];
+ xs = axis.values[0] * s;
+ ys = axis.values[1] * s;
+ zs = axis.values[2] * s;
+ xy = axis.values[0] * axis.values[1];
+ xz = axis.values[0] * axis.values[2];
+ yz = axis.values[1] * axis.values[2];
- m.col[0].values[0] = (one_c * xx) + c;
- m.col[0].values[1] = (one_c * xy) + zs;
- m.col[0].values[2] = (one_c * xz) - ys;
- m.col[0].values[3] = 0.0;
- m.col[1].values[0] = (one_c * xy) - zs;
- m.col[1].values[1] = (one_c * yy) + c;
- m.col[1].values[2] = (one_c * yz) + xs;
- m.col[1].values[3] = 0.0;
+ result->col[0].values[0] = (one_c * xx) + c;
+ result->col[0].values[1] = (one_c * xy) + zs;
+ result->col[0].values[2] = (one_c * xz) - ys;
+ result->col[0].values[3] = 0.0;
+ result->col[1].values[0] = (one_c * xy) - zs;
+ result->col[1].values[1] = (one_c * yy) + c;
+ result->col[1].values[2] = (one_c * yz) + xs;
+ result->col[1].values[3] = 0.0;
- m.col[2].values[0] = (one_c * xz) + ys;
- m.col[2].values[1] = (one_c * yz) - xs;
- m.col[2].values[2] = (one_c * zz) + c;
- m.col[2].values[3] = 0.0;
- m.col[3].values[0] = 0.0;
- m.col[3].values[1] = 0.0;
- m.col[3].values[2] = 0.0;
- m.col[3].values[3] = 1.0;
+ result->col[2].values[0] = (one_c * xz) + ys;
+ result->col[2].values[1] = (one_c * yz) - xs;
+ result->col[2].values[2] = (one_c * zz) + c;
+ result->col[2].values[3] = 0.0;
- return m;
-#endif
+ result->col[3].values[0] = 0.0;
+ result->col[3].values[1] = 0.0;
+ result->col[3].values[2] = 0.0;
+ result->col[3].values[3] = 1.0;
}
-GLUmat4
-gluPerspective4(GLfloat fovy, GLfloat aspect, GLfloat near, GLfloat far)
+void
+gluPerspective4(GLUmat4 *result,
+ GLfloat fovy, GLfloat aspect, GLfloat near, GLfloat far)
{
- GLUmat4 result;
const double sine = sin(DEG2RAD(fovy / 2.0));
const double cosine = cos(DEG2RAD(fovy / 2.0));
const double sine_aspect = sine * aspect;
const double dz = far - near;
- memcpy(&result, &gluIdentityMatrix, sizeof(result));
+ memcpy(result, &gluIdentityMatrix, sizeof(gluIdentityMatrix));
if ((sine == 0.0) || (dz == 0.0) || (sine_aspect == 0.0)) {
- return result;
+ return;
}
- result.col[0].values[0] = cosine / sine_aspect;
- result.col[1].values[1] = cosine / sine;
- result.col[2].values[2] = -(far + near) / dz;
- result.col[2].values[3] = -1.0;
- result.col[3].values[2] = -2.0 * near * far / dz;
- result.col[3].values[3] = 0.0;
-
- return result;
+ result->col[0].values[0] = cosine / sine_aspect;
+ result->col[1].values[1] = cosine / sine;
+ result->col[2].values[2] = -(far + near) / dz;
+ result->col[2].values[3] = -1.0;
+ result->col[3].values[2] = -2.0 * near * far / dz;
+ result->col[3].values[3] = 0.0;
}