Results 1 to 2 of 2

Thread: Hi guys + newbie issue with dragging 2d points

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    1

    Hi guys + newbie issue with dragging 2d points

    Hi everybody,
    this is my first post, even if I read in the forum for a while,

    I'm a webdeveloper, but I'm studing the OpenGL libraries for a school project,
    I'm really a newbie, so this problem could sounds stupid to you... anyway
    I would like to istance some point in a 2D canvas and then I would like
    to be able to move them by click, drag and release, you know...

    This is how I manage the points know, just hardcoded values,
    and then I use them to generate a spline, but this is another story.. so please, help

    [CODE]
    GLfloat ctrlpoints[4][3] = {
    {0.0,0.0,0.0},
    {100.0,400.0,0.0},
    {300.0,0.0,0.0},
    {400.0,400.0,0.0} };
    [CODE]

  2. #2
    Member Contributor
    Join Date
    Jan 2010
    Posts
    82

    Re: Hi guys + newbie issue with dragging 2d points

    a easy way of dragging the points with the mouse would be to color code each point with a unique color.

    if you do so you can read a pixel depending on where the mouse is positioned which will then give you the color of that point if it matches the point that was created color key then you would now that you mean to change that point's position when you drag the mouse.

    create a unique color for each point before hand that should be stored beside it or at least share the same index.

    - left click (or whatever)
    - render each point on the screen with a that unique color
    - read the pixel value where you had clicked -> look at glReadPixels
    - compare the clicked value with all the points
    - check if that clicked pixel value matches the points color key value when iterating through them

    - honestly I can't remember what I did after that without looking at my code since I haven't touched in a bit and I don't have access to it atm but that was the general idea and works well.

    It's happens behind the scenes so when you render the actual scene it should just draw over it. Just make sure to make the points big enough to easily click.

    look up color picking for opengl. It works really well.


Similar Threads

  1. dragging a 2d object
    By rohit_static in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-20-2010, 09:07 AM
  2. dragging an object in 3d - I got it!!!!
    By DalTXColtsFan in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-02-2003, 10:21 AM
  3. Dragging NURBS Control Points
    By Elmoe in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-23-2002, 11:28 PM
  4. mouse dragging - help
    By fox in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-26-2001, 12:35 AM
  5. mouse dragging
    By fox in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-03-2000, 06:24 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