Jump to content
  • Advertisement
Sign in to follow this  

Show and Move mouse pointer

This topic is 3698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! How do you move the mouse. I have a camera looking straight down from the top and only zoom in/out is supported (2D game). This is how I setup the environment (The target is at 0,0,0 and the camera is at 0,0,200. The zoom does glTranslatef with variable Z before glBegin):
	// Set viewport
	glViewport( 0, 0, width, height );

	// Clear color and depht buffers
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

	// Set up projection matrix
	glMatrixMode( GL_PROJECTION );    // Select projection matrix
	glLoadIdentity();                 // Start with an identity matrix
	gluPerspective(                   // Set perspective view
		64.0,						  // 65.0 Field of view = 65 degrees
		(double)width/(double)height, // Window aspect (assumes square pixels)
		1.0,                          // Near Z clipping plane
		400.0                         // Far Z clippling plane

	// Set up modelview matrix
	glMatrixMode( GL_MODELVIEW );     // Select modelview matrix
	glLoadIdentity();                 // Start with an identity matrix
	gluLookAt(                        // Set camera position and orientation
		0.0, 0.0, 10.0,               // Camera position (x,y,z)
		0.0, 0.0, 0.0,                // View point (x,y,z)
		0.0, 1.0, 0.0                 // Up-vector (x,y,z)
Now every time I draw, I also call a function to draw the mouse pointer. This function looks like this:
void DrawMouse(
	int x, y;

	glfwGetMousePos(&x, &y);

	// Now draw the quad
	glBegin( GL_LINES );
	glColor3f( 1.0f, 0.431f, 0.647f );
	glVertex3f( x/1680.0, y/-1050.0, 0.0f );

	glColor3f( 1.0f, 0.431f, 0.647f );
	glVertex3f( (x/1680.0)+0.5f, (y/-1050.0)+0.5f, 0.0f );

Now, my question is: 1. Is this the right way to introduce mouse support? (If not how) 2. If this is the way to go, how do I solve the zoom problem. The further away I am zoomed out, the slower the mouse moves. What operations do I have to do to adjust for the zoom? Tnx -vance

Share this post

Link to post
Share on other sites
When drawing thing like the mouse cursor you probably want to set your projection matrix to orthographic projection(glOrtho).

Share this post

Link to post
Share on other sites
I did glOrtho(0,0,width,height, 1, 400);
in the beginning of DrawMouse() but that didn't do anything. The mouse still moves slower and slower as I zoom out. Am I missing some other calls to switch to orthographic projection?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!