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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
void COpenGL::Mouse(int button, int state, int x, int y)
{
_mouseX = x;
_mouseY = y;
if (state==GLUT_UP)
{
switch (button)
{
case GLUT_WHEEL_UP: {if(!shift_pressed && !ctrl_pressed){Zoom(1); glutPostRedisplay();} break;}
case GLUT_WHEEL_DOWN: {if(!shift_pressed && !ctrl_pressed){Zoom(-1); glutPostRedisplay();} break;}
case GLUT_LEFT_BUTTON: _mouseLeft = false; break;
}
}
void COpenGL::Motion(int x, int y)
{
const int dx = x - _mouseX;
const int dy = y - _mouseY;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
if (dx==0 && dy==0)
return;
else
{
if (_mouseLeft)
{
Rotation(dx, dy, viewport);
GetMatrix();
glutPostRedisplay();
}
else
{
if (_mouseRight)
{
Translation(x, y);
glutPostRedisplay();
}
}
}
}
_mouseX = x;
_mouseY = y;
}
void COpenGL::Display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Display Axis
DrawAxis();
// Display objects
DrawObject();
//Actions sur le nuage
if(isPropertiescheked) GetFilesProperties();
DrawMessage();
glutSwapBuffers();
//glFlush(); // Finish rendering
}
void COpenGL::Reshape(int x, int y)
{
new_x = x;
new_y = y;
glViewport (0, 0, (GLsizei) new_x, (GLsizei) new_y); // Set the viewport
glMatrixMode (GL_PROJECTION); // Set the Matrix mode
glLoadIdentity ();
double absMaxValue = abs(xyzMax);
if (absMaxValue < abs(xyzMin))
absMaxValue = abs(xyzMin);
double ratio = (double) new_x / (double) new_y;
if (ratio > 1.0)
{
glOrtho(-1.1*absMaxValue*ratio, 1.1*absMaxValue*ratio, -1.1*absMaxValue, 1.1*absMaxValue, -new_x*absMaxValue, new_x*absMaxValue);
}
else
{
glOrtho(-1.1*absMaxValue, 1.1*absMaxValue, -1.1*absMaxValue/ratio, 1.1*absMaxValue/ratio, -new_x*absMaxValue, new_x*absMaxValue);
}
glMatrixMode(GL_MODELVIEW);
}
void GetFilesProperties()
{
GLdouble xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner;
char pos[100];
GLint viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
Transform2Dto3D (10, viewPort[3]-20, xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
glRasterPos3d(xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
//Supprimer le chemin du fichier
strFileCaracteristics = " ";
DrawString(strFileCaracteristics);
for(int i=0; i<files.size(); i++)
{
pos[0] = 0;
Transform2Dto3D (25, viewPort[3]-20*(i+1), xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
glRasterPos3d(xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
glColor3f(1.0f, 1.0f, 1.0f);
strcpy(pos, files.at(i).name.c_str());
glRasterPos3d(xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
DrawString((char *)files.at(i).name.c_str());
//
GLdouble modelView[16];
glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);
GLint viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
glLineWidth(7.0);
glColor3f(files.at(i).r, files.at(i).g, files.at(i).b);
GLdouble /*tmpWinX, tmpWinY, tmpWinZ, */posX, posY, posZ;
//gluProject(xLowerLeftCorner,yLowerLeftCorner,zLowerLeftCorner, modelView, projection, viewPort,&tmpWinX, &tmpWinY, &tmpWinZ);
glBegin(GL_LINES);
gluUnProject(10, 20*(i+1)+3, 0, modelView, projection, viewPort, &posX, &posY, &posZ);
//Transform2Dto3D (20, viewPort[3]-20*(i+1), xLowerLeftCorner, yLowerLeftCorner, zLowerLeftCorner);
glVertex3f(posX, posY, posZ);
gluUnProject(17, 20*(i+1)+3, 0, modelView, projection, viewPort, &posX, &posY, &posZ);
glVertex3f(posX, posY, posZ);
glEnd();
glLineWidth(1.0);
}
} |
Partager