We have written a custom overlay for
our plugin.
We want to draw a bounding box
rectangle when the user clicks and drags. Then when the user releases the mouse
we want to sample all the pixels they have
selected.
This kind of works, but the drawing
is a little off. The rectangle that gets drawn is a few pixels (e.g. 10 pixels)
from the position we would expect.
The mousePositionX,
mousePositionY are sent in normalized space. They seem
correct.
Initially I tried the
following to convert them to canvas space:
[oscAPI convertPointFromSpace:
kFxDrawingCoordinates_OBJECT_CENTERED
fromX:(double)mousePositionX
fromY:(double)mousePositionY
toSpace:kFxDrawingCoordinates_CANVAS
toX:&toX
toY:&toY];
I am assuming canvas space is the
coordinate space that you should draw such that (0,0) is the bottom corner of
the image and (width-1, height-1) is the upper right
corner.
However this does not really seem to
work.
The custom UI has the following
declared:
-
(FxDrawingCoordinates)drawingCoordinates
{
// Use object-centered coordinates.
return kFxDrawingCoordinates_OBJECT_CENTERED;
}
We do NOT set any viewport
or ortho settings in the drawing routine. We just assume the viewport/ortho has
been setup by Motion correctly.
How do we convert normalized
space coordinates to opengl viewer coordinated (or maybe better known as
Canvas coordinates)?
Currently we are hacking the
code to store away the width, height set in the drawOSC and then doing the
following in the mouse callbacks:
int width = g_viewWidth;
// This is what was set in
drawOSC!
int height = g_viewHeight; // This
is what was set in drawOSC!
toX =
mousePositionX*width;
toY =
mousePositionY*height;
=======================================================================================