@@ -1805,6 +1805,49 @@ namespace IPMu
1805
1805
NODE_RETURN (mp);
1806
1806
}
1807
1807
1808
+ NODE_IMPLEMENTATION (ndc2event, Mu::Vector2f)
1809
+ {
1810
+ // Convert from Normalized Device Coordinates (NDC) space [-1, 1] to
1811
+ // event space coordinates.
1812
+ // This bypasses image transforms and works purely in viewport space.
1813
+ // Height spans 2 NDC units, and assumes the viewport fully contains the
1814
+ // height of the image (eg: has vertical bars, no horizontal bars).
1815
+ //
1816
+ // When that is not the case (eg: we have horizontal bars) the
1817
+ // scale of the drawing end up not being "quite" the same, but, since
1818
+ // this functionality (at least for now) is purely to test concurrent
1819
+ // annotation drawing on multiple computers in live review scenarios,
1820
+ // this doesn't matter one bit.
1821
+ //
1822
+ Session* s = Session::currentSession ();
1823
+ Vector2f inp = NODE_ARG (0 , Vector2f);
1824
+ float x = inp[0 ];
1825
+ float y = inp[1 ];
1826
+
1827
+ Vector2f mp;
1828
+ try
1829
+ {
1830
+ Box2f vp = s->renderer ()->viewport ();
1831
+ float vpWidth = vp.size ().x ;
1832
+ float vpHeight = vp.size ().y ;
1833
+ // Map from NDC space to viewport space using the smaller dimension
1834
+ // This ensures square coordinate space regardless of viewport
1835
+ // aspect ratio
1836
+ float minDimension = min (vpWidth, vpHeight);
1837
+ mp[0 ] = (x + 1 .0f ) * 0 .5f * minDimension + vp.min .x
1838
+ + (vpWidth - minDimension) * 0 .5f ;
1839
+ mp[1 ] = (y + 1 .0f ) * 0 .5f * minDimension + vp.min .y
1840
+ + (vpHeight - minDimension) * 0 .5f ;
1841
+ }
1842
+ catch (...)
1843
+ {
1844
+ // If viewport is not available, return the input coordinates
1845
+ mp[0 ] = x;
1846
+ mp[1 ] = y;
1847
+ }
1848
+ NODE_RETURN (mp);
1849
+ }
1850
+
1808
1851
NODE_IMPLEMENTATION (imagesAtPixel, Pointer)
1809
1852
{
1810
1853
Process* p = NODE_THREAD.process ();
@@ -6083,6 +6126,10 @@ namespace IPMu
6083
6126
new Param (c, " sourceName" , " string" ),
6084
6127
new Param (c, " point" , " vector float[2]" ), End),
6085
6128
6129
+ new Function (c, " ndcToEventSpace" , ndc2event, None, Return,
6130
+ " vector float[2]" , Parameters,
6131
+ new Param (c, " point" , " vector float[2]" ), End),
6132
+
6086
6133
new Function (c, " imagesAtPixel" , imagesAtPixel, None, Return,
6087
6134
" PixelImageInfo[]" , Parameters,
6088
6135
new Param (c, " point" , " vector float[2]" ),
0 commit comments