Get coordinates

Started by
0 comments, last by hury 15 years, 9 months ago
Hi, i draw 3 triangles, which are my mousepointer:
Quote: void Cursor::draw() { glLoadIdentity(); glTranslatef(x , y, z); glRotatef(-120, 0, 1, 0); glRotatef(-25, 1, 0, 0); glRotatef(cursorRotator, 0, 0, 1); glScalef(0.1f, 0.1f, 0.1f); glEnable(GL_BLEND); glEnable (GL_SMOOTH); glBegin(GL_TRIANGLES); // Fange an Dreiecke zu zeichnen glColor3f(0, 0.5f, 0); glVertex3f(0, 0 , 0); glColor3f(0, 0.5f, 0.5f); glVertex3f(0, 1 , -2); glColor3f(0, 0.5f, 1); glVertex3f(1, 0 , -2); glColor3f(0.5f, 0, 0); glVertex3f(0, 0 , 0); glColor3f(0.5f, 0.5f, 0); glVertex3f(0, -1, -2); glColor3f(0.5f, 1, 0); glVertex3f(1, 0 ,-2); glColor3f(0, 0, 0.5f); glVertex3f(0, 0, 0); glColor3f(0, 0.5f, 0.5f); glVertex3f(-1, 0, -2); glColor3f(0, 1, 0.5f); glVertex3f(0, -1, -2); glColor3f(0.5f, 0, 0); glVertex3f(0, 0 , 0); glColor3f(0.5f, 0.5f, 0); glVertex3f(-1, 0 , -2); glColor3f(0.5f, 1, 0); glVertex3f(0, 1 , -2); glEnd(); }
How is it possible to get the (real) x, y, z Coordinates, after my triangles has been rotated with glRotatef(-120, 0, 1, 0); and glRotatef(-25, 1, 0, 0); ? Best regards Alex
Advertisement
Solved it that way:

GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];

glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
glGetIntegerv(GL_VIEWPORT, viewport);

GLdouble xi ,yi ,zi ;
GLdouble ix ,iy ,iz ;
gluProject(xPointer, yPointer, zPointer, modelMatrix, projMatrix, viewport, ξ, &yi, &zi);
gluProject(ico.getIconVector().at(x)->getX(), ico.getIconVector().at(x)->getY(), ico.getIconVector().at(x)->getZ(), modelMatrix, projMatrix, viewport, &ix, &iy, &iz);
cout << "Pointer Xi: " << xi << "\n";
cout << "Icon Xi: " << ix << "\n";

This topic is closed to new replies.

Advertisement