** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: graph3dview.cpp,v 1.2 2001/01/30 10:58:13 kevin Exp $
+** $Id: graph3dview.cpp,v 1.4 2001/01/31 01:01:22 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
-
#ifdef __GNUG__
#pragma implementation
#pragma interface
#include "wx/wx.h"
#endif
+#if wxUSE_GLCANVAS
+
#if !wxUSE_GLCANVAS
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
#endif
m_bDoubleBuffer = GL_TRUE;
m_bSmooth = GL_TRUE;
m_bLighting = GL_TRUE;
-
+ m_dXRotate = 0;
+ m_dYRotate = 0;
}
Graph3dFileView::~Graph3dFileView()
}
else {
#endif
-#if 0
-// glBegin( GL_TRIANGLE_STRIP );
- //glBegin (GL_QUADS);
- //glNormal3f (0.0, 0.0, 1.0); glVertex3f (-1.0, -1.0, 0.0); glVertex3f (0.0, -1.0, 0.0); glVertex3f (0.0, 0.0, 0.0); glVertex3f (-1.0, 0.0, 0.0); glNormal3f (0.0, 0.0, 1.0); glVertex3f (0.0, -1.0, 0.0); glVertex3f (1.0, -1.0, 0.0); glVertex3f (1.0, 0.0, 0.0); glVertex3f (0.0, 0.0, 0.0); glNormal3f (0.0, 0.0, 1.0); glVertex3f (0.0, 0.0, 0.0); glVertex3f (1.0, 0.0, 0.0); glVertex3f (1.0, 1.0, 0.0); glVertex3f (0.0, 1.0, 0.0); glNormal3f (0.0, 0.0, 1.0); glVertex3f (0.0, 0.0, 0.0); glVertex3f (0.0, 1.0, 0.0); glVertex3f (-1.0, 1.0, 0.0); glVertex3f (-1.0, 0.0, 0.0);
- glColor3f(1.0,1.0,1.0);
- glBegin (GL_POINTS);
- for (GLint i = 0;i < nVertices; i++) {
- // glNormal3fv( &pNormals[i] );
- glVertex3fv( pVertices[i] );
- }
- glEnd();
-#else
double edge = 1.;
unsigned int nx = GetDocument()->m_nx;
unsigned int ny = GetDocument()->m_ny;
const ImageFileArray v = GetDocument()->m_array;
- double actOffset = 0;
+ if (nx == 0 || ny == 0 || ! v)
+ return;
+
+ double dMin = v[0][0];
+ double dMax = dMin;
+ unsigned int ix;
+ for (ix = 0; ix < nx; ix++)
+ for (unsigned int iy = 0; iy < ny; iy++)
+ if (v[ix][iy] < dMin)
+ dMin = v[ix][iy];
+ else if (v[ix][iy] > dMax)
+ dMax = v[ix][iy];
+
+ double actOffset = dMin;
+ double actScale = 0.3 * sqrt(nx*nx+ny*ny) / (dMax - dMin);
+
+ glRotatef( m_dYRotate, 0.0, 0.0, 1.0 );
+ glRotatef( m_dXRotate, 1.0, 0.0, 0.0 );
+ glTranslatef (-static_cast<double>(nx) / 2, -static_cast<double>(ny) / 2, 0);
// glNewList(opnListNum++,GL_COMPILE);
- for(int ix = 0; ix < nx-1; ix++){
- for(int iy = 0; iy < ny-1; iy++){
+ for (ix = 0; ix < nx-1; ix++) {
+ for (unsigned int iy = 0; iy < ny-1; iy++) {
float p1[3], p2[3], p3[3], p4[3];
float n1[3], n2[3], n3[3], n4[3];
glBegin(GL_LINE_LOOP);
- p1[0] = edge*(iy); p1[1] = v[ix][iy] + actOffset; p1[2] = edge*(ix);
- p2[0] = edge*(iy+1); p2[1] = v[ix+1][iy] + actOffset; p2[2] = edge*(ix );
- p3[0] = edge*(iy+1); p3[1] = v[ix+1][iy] + actOffset; p3[2] = edge*(ix +1);
- p4[0] = edge*(iy); p4[1] = v[ix][iy] + actOffset; p4[2] = edge*(ix +1);
+ p1[0] = ix; p1[1] = actScale * (v[ix][iy] + actOffset); p1[2] = iy;
+ p2[0] = ix+1; p2[1] = actScale * (v[ix+1][iy] + actOffset); p2[2] = iy;
+ p3[0] = ix+1; p3[1] = actScale * (v[ix+1][iy+1] + actOffset); p3[2] = iy;
+ p4[0] = ix; p4[1] = actScale * (v[ix][iy+1] + actOffset); p4[2] = iy;
n1[0] = -(p2[1] - p1[1])*(p3[2] - p1[2]) + (p2[2] - p1[2])*(p3[1] - p2[1]);
n1[1] = -(p2[2] - p1[2])*(p3[0] - p2[0]) + (p2[0] - p1[0])*(p3[2] - p2[2]);
}
glEndList();
-
-#endif
+
#ifdef GL_EXT_vertex_array
}
#endif
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
- glRotatef( m_dYRotate, 0.0, 1.0, 0.0 );
- glRotatef( m_dXRotate, 1.0, 0.0, 0.0 );
-
DrawSurface();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho (-100, 100, -100, 100, -500, 500);
+ glOrtho (-300, 300, -300, 300, 200, -200);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- glTranslatef( 100, -6, 100 );
-
+
}
void
return;
switch(event.KeyCode()) {
- case WXK_ESCAPE:
- exit(0);
case WXK_LEFT:
m_pView->m_dYRotate -= 15.0;
break;
}
}
- Refresh(FALSE);
+ Refresh (false);
}
void
Graph3dFileCanvas::Reshape (int width, int height)
{
- glViewport(0, 0, (GLint)width, (GLint)height);
+ glViewport (0, 0, (GLint)width, (GLint)height);
}
+#endif // wxUSE_GLCANVAS