1

I'm working on a skeletal animation editor. Right now, each bone has a start and end point, when the mouse is under a point,subsequent dragging will cause the bone to rotate based on where the mouse is. To do this, I call atan2 and transform the mouse coordinates to local space where the local is where the mouse was pressed. Although this "works", it feels really wrong. The vector formed by the bone is not necessarily parallel to the mouse point, which it should be.

I feel like there is something about atan2 that I do not understand.

:

    if(boneUnderMouse)
    {
        boneUnderMouse->setAngle(startAngle + 
       (atan2((float)event.mouse.x - startX,event.mouse.y   - startY)));
    }

Thanks

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
jmasterx
  • 52,639
  • 96
  • 311
  • 557

1 Answers1

6

atan2 has order of arguments y, x. Thus you need

 atan2((float)event.mouse.y - startY, (float)event.mouse.x - startX)
Howard
  • 38,639
  • 9
  • 64
  • 83
  • There's something more to this, when the start angle is > pi or something, it rotates in the opposite direction. – jmasterx May 23 '11 at 18:31
  • @Milo: this gives you the angle between end point and start point. Thus if you add this to `startAngle` you'll see such effects. Try to set the angle directly (i.e. without the `startAngle+` part). – Howard May 23 '11 at 18:34
  • The problem is that the angle I'm setting is relative to its parent. Thats why I only wanted to add the change in angle – jmasterx May 23 '11 at 18:38
  • @Milo: just a guess: probably a relative angle `-startAngle+...` does help? – Howard May 23 '11 at 18:39