1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| ///Création de la display list de point 3D disposer sur une grille rectangulaire avec un échantillonnage de 1 sur nSample.
void CreateListPoints();
if (!glIsList(m_nPointsList))
{
POINT3D pt;
int il;
int ic;
int nLi = m_pPt3D.m_nLi;
int nCo = m_pPt3D.m_nCo;
m_nPointsList = glGenLists(1);
glNewList(m_nPointsList, GL_COMPILE);
glBegin(GL_POINTS);
for (il = 0; il<nLi-1; il+=nSample)
for (ic = 0; ic<nCo-1; ic+=nSample)
{
pt = m_pPt3D(il, ic);
int iColor = (NUMBER_OF_COLOR-1)*(pt.z-m_fZmin)/(m_fZmax-m_fZmin);
if (iColor >= 0 && iColor < NUMBER_OF_COLOR)
{
float r = m_ColorMap(iColor, 0)/float(NUMBER_OF_COLOR-1);
float g = m_ColorMap(iColor, 1)/float(NUMBER_OF_COLOR-1);
float b = m_ColorMap(iColor, 2)/float(NUMBER_OF_COLOR-1);
glColor4f(r, g, b, m_fAlpha);
glVertex3f(pt.x,pt.y,pt.z);
}
}
glEnd();
glEndList();
}
///Suppression de la displaylist
void DeleteListPoints()
GLboolean bIsList = glIsList(m_nPointsList);
if (bIsList)
{
glDeleteLists(m_nPointsList, 1);
m_nPointsList = 0;
}
///Affichage de la displaylist
void DrawAsPoints()
{
GLboolean bIsList = glIsList(m_nPointsList);
if(!bIsList)
CreateListPoints();
glCallList(m_nPointsList);
}
///Affichage OPENGL
void RenderScene()
{
wglMakeCurrent(m_hDC, m_hGLContext);
glClearColor(0.0, 0.0, 0.0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
///Cette partie est propre à mon code. Elle a pour but de centrer l'affichage
/// et utilise certaines variables déclarées plus loin et dont le nom est explicite
int cx = m_nWidth;
int cy = m_nHeight;
if (cy == 0)
cy = 1;
if (cx == 0)
cx = 1;
float xc = (m_fXmax+m_fXmin)/2.0f;
float yc = (m_fYmax+m_fYmin)/2.0f;
float zc = (m_fZmax+m_fZmin)/2.0f;
float xw = (m_fXmax-m_fXmin);
float yw = (m_fYmax-m_fYmin);
float zw = (m_fZmax-m_fZmin);
m_fSceneRay = sqrt(xw*xw+yw*yw+zw*zw);
float x1 = xc-m_fSceneRay;
float x2 = xc+m_fSceneRay;
float y1 = yc-m_fSceneRay;
float y2 = yc+m_fSceneRay;
float z1 = zc-m_fSceneRay;
float z2 = zc+m_fSceneRay;
float ratio;
ratio = (float)cy/(float)cx;
if (ratio > 1)
{
x1 = -m_fSceneRay/ratio;
x2 = m_fSceneRay/ratio;
}
else
{
y1 = m_fSceneRay*ratio;
y2 = m_fSceneRay*ratio;
}
glPushMatrix();
glViewport(0, 0, cx, cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-m_fSceneRay, m_fSceneRay, -m_fSceneRay*ratio, m_fSceneRay*ratio, -m_fSceneRay*m_fSceneRay, m_fSceneRay*m_fSceneRay);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-xc, -yc, -zc);
///ICI les transformation géométrique du nuage de points
glRotatef(m_fxRotat, 1.0f, 0.0f, 0.0f);
glRotatef(m_fyRotat, 0.0f, 1.0f, 0.0f);
glRotatef(m_fzRotat, 0.0f, 0.0f, 1.0f);
glScalef(m_fxScale, m_fyScale, m_fzScale);
glTranslatef(m_fxTrans, m_fyTrans, m_fzTrans);
///Affichage du nuage dans le nouveau repère
DrawAsPoints();
glTranslatef(xc, yc, zc);
glPopMatrix();
glFinish();
SwapBuffers(wglGetCurrentDC());
} |
Partager