X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=a29089a7162daf5f4ac3cbdc8807cd56d9d8a743;hp=909dc101a0afbc5fb48cf2711a085c422daac0d2;hb=c81a502b726ff9f61d9661979cef0a5d5efadb22;hpb=31a835d9aebd8acb367a033cc92efb4c944a7b4d diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index 909dc10..a29089a 100644 --- a/src/graph3dview.cpp +++ b/src/graph3dview.cpp @@ -9,7 +9,7 @@ ** 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.3 2001/01/30 13:47:46 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 @@ -118,7 +118,8 @@ Graph3dFileView::Graph3dFileView () m_bDoubleBuffer = GL_TRUE; m_bSmooth = GL_TRUE; m_bLighting = GL_TRUE; - + m_dXRotate = 0; + m_dYRotate = 0; } Graph3dFileView::~Graph3dFileView() @@ -196,36 +197,42 @@ Graph3dFileView::DrawSurface() } 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(nx) / 2, -static_cast(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]); @@ -240,8 +247,7 @@ Graph3dFileView::DrawSurface() } glEndList(); - -#endif + #ifdef GL_EXT_vertex_array } #endif @@ -276,9 +282,6 @@ Graph3dFileView::Draw () { 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(); @@ -336,11 +339,10 @@ Graph3dFileView::InitGL () 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 @@ -544,8 +546,6 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) return; switch(event.KeyCode()) { - case WXK_ESCAPE: - exit(0); case WXK_LEFT: m_pView->m_dYRotate -= 15.0; break; @@ -581,13 +581,13 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) } } - 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); }