PDA

View Full Version : Hi guys + newbie issue with dragging 2d points



Kappa
01-14-2010, 04:35 PM
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]

ravage
01-14-2010, 11:30 PM
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.