views:

77

answers:

1

To clarify things, what i am trying to do is to get the openGL coordinates and manipulate them in my mfc code. not to get an openGL object. i'm using the mfc to control the position of the objects in the openGL.

Hi, i'm trying to find the naswer on the web and can't find a full solution that i can use and that will work...

I'm developing a MFC project with static picture as the canvas for an openGL class that draw the grphics for my game.

On moush down, i need to retrive a shape coordinate from the openGL class.

I'm looking for a way to convert the openGL coordinates to MFC coordinates but no matter what i try i get junk after using the gluProject or gluUnProject (i've tried to do both ways but non is working)

GLdouble modelMatrix[16];
  glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
  GLdouble projMatrix[16];
  glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
  int viewport[4];
  glGetIntegerv(GL_VIEWPORT,viewport);

  POINT mouse;              // Stores The X And Y Coords For The Current Mouse Position
  GetCursorPos(&mouse);         // Gets The Current Cursor Coordinates (Mouse Coordinates)
  ScreenToClient(hWnd, &mouse);
  GLdouble winX, winY, winZ;        // Holds Our X, Y and Z Coordinates
  winX; = (float)point.x;     // Holds The Mouse X Coordinate
  winY; = (float)point.y;     // Holds The Mouse Y Coordinate
  winY = (float)viewport[3] - winY;
  glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
  GLdouble posX=s1->getPosX(), posY=s1->getPosY(), posZ=s1->getPosZ();    // Hold The Final Values
  gluUnProject( winX, winY, winZ, modelMatrix, projMatrix, viewport, &posX, &posY, &posZ);
  gluProject(posX, posY, posZ, modelMatrix, projMatrix, viewport, &winX, &winY, &winZ);

This is just part of the code i've tried. ofcourse not gluProject and gluUnProject together. just had them both here to show.....and i know there is lots of junk over there, its from some of my tries...

p.s. i've tried many many more combinations and examples from the web and nothing seem to work in my case....

Can any one show me what is the right way to do the transformation?

10x

A: 

It looks like you're trying to retrieve the object (or objects) that is/are at a particular point. If this is the case, gluProject and/or gluUnProject isn't really a very suitable tool for the task. OpenGL has a selection mode intended specifically for this kind of task.

In typical use, you specify a small square (e.g., 5x5 pixels) around the mouse click spot with gluPickMatrix, set selection mode with glRenderMode, set a buffer with glSwelectBuffer, and then draw your scene. The drawing doesn't go to the screen, but fills the buffer you specified wiyh records of what was drawn within the specified area.

Jerry Coffin