12-19-2007 10:29
Currently there is a bug in llDetectedGrab() that causes the initial (non-zero) offset to be pretty worthless. Please see:

/54/1d/186955/1.html
https://jira.secondlife.com/browse/SVC-265

However, if you ignore the first non-zero value during a touch (except to remember it) and then always use offsets from the previous value, you can get a good magnitude and direction. As of 1.18.5(3), this seems to work fine for in-world object and HUD attachments, and for both root prims and child prims. For HUD attachments, you still might want to track the camera position and compensate (e.g. relativeDragOffset = dragOffset/llGetCameraRot()).

I hope this helps folks. I know it makes HUD development a lot easier for me personally.

Some example (pseudo-)code:

// From touch_start
lastDragVec = ZERO_VECTOR;

// From touch
vector dragVec = llDetectedGrab(0);
if (lastDragVec != ZERO_VECTOR)
{
handleDragOffset(dragVec-lastDragVec);
}
lastDragVec = dragVec;