0

Hello, I am writing a OpenGL program, but I can't get the mouse to do what I want.

The code looks like this

main()
[INDENT]init OpenGL stuff
display function1[/INDENT]

Function1
[INDENT]Start graphCalculation[/INDENT]

graphCalculation
[INDENT]plot graph in OpenGL[/INDENT]

What I've tried to do, is to add a "zoom" function, so the mouse looks like this:

mouseFunction
[INDENT]if button down
[INDENT]if left button, zoom in (get new coordinates), and execute graphCalculation
if right button, zoom out (get new coordinates), and execute graphCalculation
[/INDENT][/INDENT]

the C code looks like this:

void processMouse(int button, int state, int x, int y){
        if(state == GLUT_DOWN){
                if(button == GLUT_LEFT_BUTTON){
//passing new x,y coordinates to calculate new axis and redisplaying them
                        graphCalculation(x,y,0);
                }
                if(button == GLUT_RIGHT_BUTTON){
//passing new x,y coordinates to calculate new axis and redisplaying the
                        graphCalculation(x,y,1);
                }
        }
        glutPostRedisplay();
}

This doesn't work, can anyone help me?

I know it's fairly long, but thanks :)

P.s The graph function works..

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by fpsasm
0

Have you converted the x and y variable into world coordinates? Does graphCalculation
takes the mouse coordinate in world space? Or does it want to raw pixel points?
Can you show how the graphCalculation function looks like? Can't really help
without more info.

0

Have you converted the x and y variable into world coordinates? Does graphCalculation
takes the mouse coordinate in world space? Or does it want to raw pixel points?
Can you show how the graphCalculation function looks like? Can't really help
without more info.

The problem is, when I try to zoom in, it will not zoom in where the mouse actually is..

when my mouse function returns a x,y coordinates, is that the x,y coordinates in the window, or on the screen? if so, how do you relate the mouse location in the window pixel.

0

Before anything, I need to see the graphCalculation code. Or at least how it treats
the x and y passed in.

It takes the x,y coordinate passed to it, and it then converts that x,y position into a value on the axis. It calculates the axis values (left right top bottom)

When I hard-code x,y to be a static value( like x=200,y=100 where the res is 900x600 (for example)), then the function works, however it seems that the x,y position of the mouse, it doesn't seem to be the x,y position in the window..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.