mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
various stuff in opengl demos such as a better model,
stable trackball for the fly navigation mode, and started to put some GUI elements...
This commit is contained in:
@@ -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)
|
||||
void GpuHelper::drawUnitSphere(int level)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user