PDA

View Full Version : Mouse Event Question.



Antonio Gonzalez
12-14-2010, 09:17 PM
Second Newbie Question of the Day.

So I'm working with processMouseActiveMotion & processMouse.
I'm using a Method that is alike a Spray tool on any regular 'paint'. Paints Random Pixels around an Area.

The Problem is, I'm using ActiveMotion to activate such method, and when I Stop moving the mouse, the tool stops painting, even if the button is still pressed.

I've Tried several things, to no avail.

Am I missing something? What could I do here?

Arkaid D.
12-14-2010, 10:30 PM
I'm guessing that you're using GLUT and processMouseActiveMotion is the name of your callback.

If that's the case, tell me which glut function is it a callback of. Is it glutMotionFunc or glutMouseFunc?

Antonio Gonzalez
12-15-2010, 10:23 AM
Oh, yes, sorry. I forgot bout' that.

Here it is:
glutMouseFunc( processMouse );
glutMotionFunc( processMouseActiveMotion );

Now, On processMouse I got this:

if(b==GLUT_LEFT_BUTTON && s==GLUT_DOWN)
{
i=0;
im=0;
press=1;
y=winHeight-y;
xoo[i]=x;
yoo[i]=y;
}

And in processMouseActiveMotion I got this:

i++;
glDrawPixels(winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, colores);
xoo[i] = x;
yoo[i] = winHeight-y;
if(i==(im+10)){
pint(xoo,yoo,i,im);
im=i;
glFlush();
glReadPixels(0, 0,winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, colores);
}

xoo & yoo are arrays that follow the Starting Point and then the Mouse Movements.

pint is a Bresenham Algorithm that in place, calls one called spray That actually paints.

Now, I Imagine that I have to put such method in the processMouse, But When I do, nothing happens.
=/

Thanks in Advance.

_arts_
12-15-2010, 10:59 AM
glutPassiveMotionFunc ?

Antonio Gonzalez
12-15-2010, 11:30 AM
glutPassiveMotionFunc ?

No. PassiveMotion is for when you move the mouse and no buttons are pressed right? I need the Opposite. The Mouse is Static yet the Button is pressed.

Now, I can tell it's going to be:

processMouse from glutMouseFunc( processMouse );

But How Do I Implement it?

_arts_
12-15-2010, 12:49 PM
glutMouseFunc then ?

Do you want to do an action when the button of the mouse is pressed even if you don't move the mouse ? If so, this is the solution.

http://www.opengl.org/documentation/specs/glut/spec3/node50.html#SECTION00085000000000000000

Rosario Leonardi
12-15-2010, 01:38 PM
Usually is logically wrong draw object outside the draw function. I will do something like that.


onMouseButtonPressed(){
iHaveToDrawSomething = button1 is pressed;
}

onMouseMove(){
storeMouseTraiectory(newMousePos);
}

drawFunction(){
if(iHaveToDrawSomething)
drawMouseTraiectory();
}

Antonio Gonzalez
12-15-2010, 02:22 PM
I was using MouseFunc. And I thought it wasn't working.
It is.... it's just working REALLY slow. =/

I have it like this on MouseFunc

if(boton==GLUT_LEFT_BUTTON && estado==GLUT_DOWN)
{
spray(x,y);

}

and on spray

void spray(int x, int y)
{
int temp;
glColor3f(0.0, 0.0, 10.0);
glBegin(GL_POINTS);
glPointSize(10.0f); // determina el tamano del pixel
for(temp=0;temp<3;temp++){
sy = (rand() % 25);
sx = (rand() % 25);
glVertex2i(x-sx,sy+y);
}
glEnd();
}

It does paint, it just does it REALLY slow. Anyone knows why would that be?

ZbuffeR
12-15-2010, 02:31 PM
Ah in fact you need a "no event" event :)
Try this : glutIdleFunc