diff options
author | Gael Guennebaud <g.gael@free.fr> | 2008-09-09 18:50:45 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2008-09-09 18:50:45 +0000 |
commit | 146c9e449443453f3932b60cd1bab47f688403e7 (patch) | |
tree | f7f18d29a7a7755515db377b5de9658899de66bb /demos/opengl/gpuhelper.cpp | |
parent | d3a70b7facea2919b5ee0451d3c639dedb00ea30 (diff) |
various stuff in opengl demos such as a better model,
stable trackball for the fly navigation mode, and started
to put some GUI elements...
Diffstat (limited to 'demos/opengl/gpuhelper.cpp')
-rw-r--r-- | demos/opengl/gpuhelper.cpp | 78 |
1 files changed, 4 insertions, 74 deletions
diff --git a/demos/opengl/gpuhelper.cpp b/demos/opengl/gpuhelper.cpp index 71348737c..921c95f04 100644 --- a/demos/opengl/gpuhelper.cpp +++ b/demos/opengl/gpuhelper.cpp @@ -23,6 +23,7 @@ // Eigen. If not, see <http://www.gnu.org/licenses/>. #include "gpuhelper.h" +#include "icosphere.h" #include <GL/glu.h> // PLEASE don't look at this old code... ;) @@ -31,26 +32,6 @@ GpuHelper gpu; -//-------------------------------------------------------------------------------- -// icosahedron -//-------------------------------------------------------------------------------- -#define X .525731112119133606 -#define Z .850650808352039932 - -static GLfloat vdata[12][3] = { - {-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z}, - {0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X}, - {Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0} -}; - -static GLint tindices[20][3] = { - {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1}, - {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3}, - {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, - {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} }; -//-------------------------------------------------------------------------------- - - GpuHelper::GpuHelper() { mVpWidth = mVpHeight = 0; @@ -151,61 +132,10 @@ void GpuHelper::drawUnitCube(void) glEnd(); } -void _normalize(float* v) -{ - float s = 1.f/ei_sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); - for (uint k=0; k<3; ++k) - v[k] *= s; -} - -void _subdivide(float *v1, float *v2, float *v3, long depth) +void GpuHelper::drawUnitSphere(int level) { - GLfloat v12[3], v23[3], v31[3]; - GLint i; - - if (depth == 0) { - //drawtriangle(v1, v2, v3); - glNormal3fv(v1); - glVertex3fv(v1); - - glNormal3fv(v3); - glVertex3fv(v3); - - glNormal3fv(v2); - glVertex3fv(v2); - - return; - } - for (i = 0; i < 3; i++) { - v12[i] = v1[i]+v2[i]; - v23[i] = v2[i]+v3[i]; - v31[i] = v3[i]+v1[i]; - } - _normalize(v12); - _normalize(v23); - _normalize(v31); - _subdivide(v1, v12, v31, depth-1); - _subdivide(v2, v23, v12, depth-1); - _subdivide(v3, v31, v23, depth-1); - _subdivide(v12, v23, v31, depth-1); -} - -void GpuHelper::drawUnitLightSphere(int level) -{ - static int dlId = 0; - if (!dlId) - { - dlId = glGenLists(1); - glNewList(dlId, GL_COMPILE); - glBegin(GL_TRIANGLES); - for (int i = 0; i < 20; i++) - { - _subdivide(&vdata[tindices[i][0]][0], &vdata[tindices[i][1]][0], &vdata[tindices[i][2]][0], 1); - } - glEnd(); - glEndList(); - } - glCallList(dlId); + static IcoSphere sphere; + sphere.draw(level); } |