JHN
01-05-2009, 12:29 PM
That shouldn't be too hard, just calculate back to a float value (0...1) that way you can multiply it with every size you want.
This below code I use to transport 3d positions to 2d screenspace for use in fusion. 3Dto2D tracker data sort of speech.
pX = stringStream ""
pY = stringStream ""
sX = gw.getWinSizeX() as float -- Get WinSize X
sY = gw.getWinSizeY() as float -- Get WinSize X
rPA = renderPixelAspect -- Get Render Pixel Aspect
rX = RenderWidth as float -- Get Render Pixels X
rY = RenderHeight as float -- Get Render Pixels Y
rY = rY * ( 1 / rPA ) -- Correct for aspect ratio
rratio = ( sX / rX ) / (sY / rY) -- Get Ratio
if rratio >= 1. then ( -- If Ratio is bigger than 1 then
ratio = sY / rY -- Use Y ratio for calculations
) else (
ratio = sX / rX -- Else use X ratio for calculations
) -- end if
xMin = ( sX - ( rX * ratio ) ) / 2 -- Get x minimum value
yMin = ( sY - ( rY * ratio ) ) / 2 -- Get y minimum value
ct = animationRange.end as integer / TicksPerFrame -- Animation range end as integer
gw.setTransform (matrix3 1) -- Set gw View transform to zero
for i = 0 to ct do
(
--p = gw.TransPoint ( at time i obj.position ) -- Get 3D point in 2D screenspace
slidertime = i -- Move viewport cause of moving cams
p = gw.TransPoint ( obj.position ) -- Get 3D point in 2D screenspace
x = ( p.x - xMin ) / ( sX - ( xMin * 2) ) -- Convert View space to Render space for X
y = 1 - ( p.y - yMin ) / ( sY - ( yMin * 2 ) ) -- idem for Y
format "% %\n" ( i as float ) x to:pX
format "% %\n" ( i as float ) y to:pY
) -- end for
Be aware this assume topleft as [0,0].
At least I hope this gets you on your way if I understood the question right and you want to convert 3D position to 2D screen data.
-Johan
This below code I use to transport 3d positions to 2d screenspace for use in fusion. 3Dto2D tracker data sort of speech.
pX = stringStream ""
pY = stringStream ""
sX = gw.getWinSizeX() as float -- Get WinSize X
sY = gw.getWinSizeY() as float -- Get WinSize X
rPA = renderPixelAspect -- Get Render Pixel Aspect
rX = RenderWidth as float -- Get Render Pixels X
rY = RenderHeight as float -- Get Render Pixels Y
rY = rY * ( 1 / rPA ) -- Correct for aspect ratio
rratio = ( sX / rX ) / (sY / rY) -- Get Ratio
if rratio >= 1. then ( -- If Ratio is bigger than 1 then
ratio = sY / rY -- Use Y ratio for calculations
) else (
ratio = sX / rX -- Else use X ratio for calculations
) -- end if
xMin = ( sX - ( rX * ratio ) ) / 2 -- Get x minimum value
yMin = ( sY - ( rY * ratio ) ) / 2 -- Get y minimum value
ct = animationRange.end as integer / TicksPerFrame -- Animation range end as integer
gw.setTransform (matrix3 1) -- Set gw View transform to zero
for i = 0 to ct do
(
--p = gw.TransPoint ( at time i obj.position ) -- Get 3D point in 2D screenspace
slidertime = i -- Move viewport cause of moving cams
p = gw.TransPoint ( obj.position ) -- Get 3D point in 2D screenspace
x = ( p.x - xMin ) / ( sX - ( xMin * 2) ) -- Convert View space to Render space for X
y = 1 - ( p.y - yMin ) / ( sY - ( yMin * 2 ) ) -- idem for Y
format "% %\n" ( i as float ) x to:pX
format "% %\n" ( i as float ) y to:pY
) -- end for
Be aware this assume topleft as [0,0].
At least I hope this gets you on your way if I understood the question right and you want to convert 3D position to 2D screen data.
-Johan
