drag and drop

http://www.mfcogl.com/Drag%20&%20Drop%20-%20MFC%20&%20OpenGL%20Page.htm has an example of a drag and drop method but it appears very complicated with setCapture calls and translating the mouse point to window coordinates. i thought something like:

static void mouse (int button, int state, int x, int y )
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
x=startx;
y=starty;
}

if(button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
ot->object[obj].x1=ot->object[obj].x1+(x-startx);
ot->object[obj].y1=ot->object[obj].y1+(y-starty);
ot->object[obj].x2=ot->object[obj].x2+(x-startx);
ot->object[obj].y2=ot->object[obj].y2+(y-starty);
ot->object[obj].x3=ot->object[obj].x3+(x-startx);
ot->object[obj].y3=ot->object[obj].y3+(y-starty);
ot->object[obj].x4=ot->object[obj].x4+(x-startx);
ot->object[obj].y4=ot->object[obj].y4+(y-starty);

}

this however does not work. the file menu on my user interface pops down and then the object disappears(dont ask me how). it seems straight enough but obviously not. any help would be great.
ps the drag is not important once it ends up translating from one point to the other

In this piece of code are you trying to move an object or draw it… not very clear.

if you are moving a object, all you need it the point in which to place it when the button is released. And until the button is released just have the object follow your mouse.

Now if you are drawing, the mouse down is the start of your object, the mouse up is end.

if button_down
x1 = x;
y1 = y;

if button_up
x2 = x;
y2 = y;

x1, y1


  •      *
    
  •      *
    
  •      *
    

************ x2, y2

Hope this helps

Originally posted by likeit:
[b] http://www.mfcogl.com/Drag%20&%20Drop%20-%20MFC%20&%20OpenGL%20Page.htm has an example of a drag and drop method but it appears very complicated with setCapture calls and translating the mouse point to window coordinates. i thought something like:

static void mouse (int button, int state, int x, int y )
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
x=startx;
y=starty;
}

if(button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
ot->object[obj].x1=ot->object[obj].x1+(x-startx);
ot->object[obj].y1=ot->object[obj].y1+(y-starty);
ot->object[obj].x2=ot->object[obj].x2+(x-startx);
ot->object[obj].y2=ot->object[obj].y2+(y-starty);
ot->object[obj].x3=ot->object[obj].x3+(x-startx);
ot->object[obj].y3=ot->object[obj].y3+(y-starty);
ot->object[obj].x4=ot->object[obj].x4+(x-startx);
ot->object[obj].y4=ot->object[obj].y4+(y-starty);

}

this however does not work. the file menu on my user interface pops down and then the object disappears(dont ask me how). it seems straight enough but obviously not. any help would be great.
ps the drag is not important once it ends up translating from one point to the other[/b]

[This message has been edited by nexusone (edited 04-08-2002).]

im trying to move it, do i just have an empty motion method then as well as the code posted earlier for the left mouse button down and up.

Why all of this just to move it?

ot->object[obj].y4=ot->object[obj].y4+(y-starty);

How about this:

ot->object[obj].y1 = y; Is y not the new point?

Originally posted by likeit:
im trying to move it, do i just have an empty motion method then as well as the code posted earlier for the left mouse button down and up.