an easy way for dragging images

Hi, I’m making an image sorting app with which you can click an image and then drag it somewhere else. One picture was an easy job, but this ofcourse won’t work when i rotate the image… So my question is: is there an easy way to select and then drag an image? Or do i have to do some math? (no problem but i figured that there must be an more efficient method.

The way I did mine was; look if the mouse is clicking and dragging inside the boundaries if true then use the difference of mousemovement to move the image. But as said calculating the boundaries of an rotated picture is a bit harder.

Quick q: Are you rotating the image externally (e.g. photoshop) and then bringing it in, or are you rotating it in your code?

a rotate images this way:
glRotatef(60, 0, 0, 1);

where 60 is the degrees…

hi - nice question,

I’m sorry – it’s kind of a difficult problem but not impossible with the rotation. without rotation it’s very easy. we haven’t really implmented any kind of hit test system, but my guess is that there might be good opengl type ways to do this. my solution would be geometric -

you can easily do a point in polygon test, if you know those rotated points. For example, this function

int pnpoly(int npol, float *xp, float *yp, float x, float y) {  
      int i, j, c = 0;  
      for (i = 0, j = npol-1; i < npol; j = i++) {  
        if ((((yp[i] <= y) && (y < yp[j])) ||  
             ((yp[j] <= y) && (y < yp[i]))) &&  
            (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))  
          c = !c;  
      return c;  

tells you if the point is in the polygon or not.

this is a bit of effort, but you could do the following:

a) perform the rotation manually on 4 points
b) test for point inside polygon with those points using the above code

if you want to post some code i’d be happy to take a look at it –

take care!!

Hi thank you very much for the reply!

I’ll look into it and post some code when I tried something! Good pointer that polygon test!

yeah that point in polygon solution is pretty useful - I use it alot

another approach which might be easier would be to do the opengl selecting routine – I didn’t drink enough coffee to get my head around it this morning, but as I understand it, it’s useful for picking primives in opengl after translations, projection, etc:

there is some info here:…-ection.htm…-ection.asp…-t-805.html

maybe there is a good nehe example, I’ll look for one… I’d be curious to see how that works…

take care,

hehe cool :slight_smile: I just opened my OpenGL programming guide and stumbled across the select routine too, so I hope I can figure out the best solution!

and again lots thanks for the effort!