Results 1 to 5 of 5

Thread: Opengl mouse interaction problem

  1. #1
    Junior Member Newbie
    Join Date
    May 2006

    Opengl mouse interaction problem

    Hi guys,
    I'm developing a c# app based upon opengl wrapping (from ogl dll) where I show a 3d surfaces (obtained from glquads that interpolates my control points).
    I want to select and move dinamically these controlpoints. The problem is that I get coordinates from mouse event handler especially from MouseEventArgs but these coords is completely unbounded from my view.
    There is a way to map current xy coords of my mouse on control up xyz of my ogl shene??
    Thankyou in advance.
    Mirko (buzzy84)

  2. #2

    Re: Opengl mouse interaction problem

    I also would be interested in learning how to do this. I am writing a game engine and for the level editor I want people to be able to select verticies in 3d space.. but i dont know where to even start in going from mouse cooords to 3d space coords

  3. #3
    Member Contributor
    Join Date
    Apr 2005

    Re: Opengl mouse interaction problem

    I would recommend gluUnproject. This method allows you transform a mouse coordinate into an object space coordinate, given the viewport, projection, and modelview matrices. gluProject does the opposite.

  4. #4
    Junior Member Newbie
    Join Date
    May 2006

    Re: Opengl mouse interaction problem

    I have the same problem as the TS and I also tried it with gluUnProject but didnt succeeded.
    I get strange values of which I know, they arent correct.
    Here is my code to do it:

    Code :
    			GLint viewport[4];					// Where The Viewport Values Will Be Stored
    			glGetIntegerv(GL_VIEWPORT, viewport);			// Retrieves The Viewport Values (X, Y, Width, Height)
    			GLdouble modelview[16];					// Where The 16 Doubles Of The Modelview Matrix Are To Be Stored
    			glGetDoublev(GL_MODELVIEW_MATRIX, modelview);		// Retrieve The Modelview Matrix
    			GLdouble projection[16];				// Where The 16 Doubles Of The Projection Matrix Are To Be Stored
    			glGetDoublev(GL_PROJECTION_MATRIX, projection);		// Retrieve The Projection Matrix
    			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);
    			GLfloat winX, winY, winZ;				// Holds Our X, Y and Z Coordinates
    			winX = (float)mouse.x;					// Holds The Mouse X Coordinate
    			winY = (float)mouse.y;					// Holds The Mouse Y Coordinate
    			winY = (float)viewport[3] - winY;			// Subtract The Current Mouse Y Coordinate From The Screen Height.
    			glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
    			GLdouble posX, posY, posZ;				// Hold The Final Values
    			gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    munich, germany

    Re: Opengl mouse interaction problem

    another approach would be using gluProject to calculate all vertices' window coordinates and thereby finding the vertex which is the closest to the mouse pointer's position. if you do it like this, you don't have to fight with the z-coordinate.

Similar Threads

  1. strange mouse interaction
    By yoseph in forum OpenGL: Windows
    Replies: 0
    Last Post: 12-08-2007, 08:01 PM
  2. Multiple glViewports and mouse interaction
    By Ramzy Darwish in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-18-2005, 11:15 AM
  3. Mouse Interaction
    By legendkiller in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-15-2004, 09:56 AM
  4. Mouse Interaction
    By melmiligui in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-28-2002, 02:28 AM
  5. mouse interaction
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-28-2001, 05:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean