Results 1 to 5 of 5

Thread: How I can draw line by drag

  1. #1
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    How I can draw line by drag

    Hi


    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
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How I can draw line by drag

    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


    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

  3. #3
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: How I can draw line by drag

    HI

    thank you

    but i mean motionmousfunction()

    best regards
    Moon_Girl
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How I can draw line by drag

    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

    thank you

    but i mean motionmousfunction()

    best regards
    Moon_Girl

  5. #5
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: How I can draw line by drag

    THANKS FOR YOU ITS WORK WITH ME
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

Similar Threads

  1. draw line, line-size ... opengl 3.3 ?
    By CarstenT in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-28-2014, 08:19 AM
  2. How to drag the line segment by selecting the vert
    By Sean06 in forum OpenGL: User Software
    Replies: 3
    Last Post: 08-30-2011, 05:48 PM
  3. Draw Shapes With Mouse Drag
    By Usman in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-18-2010, 03:26 PM
  4. How to select a line point to drag it ? (newbie question)
    By Sickboy in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 10-21-2003, 04:43 AM
  5. how can I draw more than one line??
    By MOON-GIRL in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 12-04-2002, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean