PDA

View Full Version : How I can draw line by drag



MOON-GIRL
12-29-2002, 02:36 AM
Hi http://www.opengl.org/discussion_boards/ubb/smile.gif


i want design program to draw line

the user must specify the start point and end point
the we draw the line

i Know do that

but

the problem with me

i want when user choose the start point
if he think what the end point he choose the
line show
no really line but to help user
like drag

i know we must use function motion
but i don't know the header and how i can use it


best regards
Moon_Girl

nexusone
12-29-2002, 05:08 AM
Here a simple example, say that right mouse button down starts line and button up ends line:

typedef struct LINE
{
float x1,y1, x2,y2;
}Line;

Line lines[100];


mouse()
{

if (Right_mouse_down)
{
lines[i].x1 = mouse_x;
lines[i].y1 = mouse_y;
}

if (Right_mouse_down)
{
lines[i].x2 = mouse_x;
lines[i].x2 = mouse_y;
i++; // point to next array to store a line
}

Very simple example, but maybe gives you an idea.



Originally posted by MOON-GIRL:
Hi http://www.opengl.org/discussion_boards/ubb/smile.gif


i want design program to draw line

the user must specify the start point and end point
the we draw the line

i Know do that

but

the problem with me

i want when user choose the start point
if he think what the end point he choose the
line show
no really line but to help user
like drag

i know we must use function motion
but i don't know the header and how i can use it


best regards
Moon_Girl

MOON-GIRL
12-29-2002, 08:12 AM
HI http://www.opengl.org/discussion_boards/ubb/smile.gif

thank you

but i mean motionmousfunction()

best regards
Moon_Girl

nexusone
12-29-2002, 06:02 PM
I was short on time, but let me expand on the line.


typedef struct LINE
{
float x1,y1, x2,y2;
}Line;

Line lines[100];

Line temp_line;
int line_draw; // Flag to tell us that a line has been started.

mouse()
{

if (Right_mouse_down)
{
temp_line.x1 = mouse_x; // Line
temp_line.y1 = mouse_y;
line_draw = 1; // start drawing drag line
}

if (Right_mouse_down)
{
temp_line.x2 = mouse_x;
temp_line.x2 = mouse_y;
line_draw = 0; // stop drawing drag line
// Store our new line
lines[i].x1 = temp_line.x1;
lines[i].y1 = temp_line.y1;
lines[i].x2 = temp_line.x2;
lines[i].y2 = temp_line.y2;
i++; // point to next array to store a line
}


mouse_motion()
{

if (line_draw)
{
temp_line.x2 = mouse.x;
temp_line.y2 = mouse.y;
}

}


display()
{
int u

// Draw drag line, until user releases button

if( line_draw )
{
glBegin(GL_LINES);
glVertex2d(temp_line.x1,temp_line.x1 );
glVertex2d(temp_line.x2,temp_line.x2 );
glEnd();
}

// Draw lines draw by user
for( u = 0; u < i; u++)
{
glBegin(GL_LINES);
glVertex2d(lines[u].x1,lines[u].x1 );
glVertex2d(lines[u].x2,lines[u].x2 );
glEnd();
}

}


As you know I have left out setup code and other stuff, but should give you an idea of how to do it.



Originally posted by MOON-GIRL:
HI http://www.opengl.org/discussion_boards/ubb/smile.gif

thank you

but i mean motionmousfunction()

best regards
Moon_Girl

MOON-GIRL
12-31-2002, 10:37 AM
THANKS FOR YOU ITS WORK WITH ME http://www.opengl.org/discussion_boards/ubb/smile.gif