vance00

11-01-2008, 01:53 PM

Hello

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:

// Set viewport

glViewport( 0, 0, width, height );

// Clear color and depht buffers

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

// 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 );

glEnd();

}

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? (I am not that great with matrices)

Tnx

-vance

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:

// Set viewport

glViewport( 0, 0, width, height );

// Clear color and depht buffers

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

// 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 );

glEnd();

}

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? (I am not that great with matrices)

Tnx

-vance