dmurdoch/rgl

coordinates conversion in javascript API

gitdemont opened this issue · 2 comments

In the past rgl0.107.14, there were some functions/objects part of the rglinstance object that were usefull to convert mouse <-> user coordinates (in my use case when registering custom handlers) but they are not part of rgl0.109.16 anymore.
dotprod, vlen and multVM

this.dotprod = function(a, b) {
  return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
};
this.vlen = function(v) {
  return Math.sqrt(this.dotprod(v, v));
};
this.multVM = function(v, M) {
  return [ M.m11 * v[0] + M.m21 * v[1] + M.m31 * v[2] + M.m41 * v[3],
           M.m12 * v[0] + M.m22 * v[1] + M.m32 * v[2] + M.m42 * v[3],
           M.m13 * v[0] + M.m23 * v[1] + M.m33 * v[2] + M.m43 * v[3],
           M.m14 * v[0] + M.m24 * v[1] + M.m34 * v[2] + M.m44 * v[3]
         ];
};

Could these functions be reintegrated ?
Or maybe functions to convert mouse coordinates to user and vice versa
I saw that javascript API is getting documented but I did not find such functions

sessionInfo() ```r R version 4.1.3 (2022-03-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rgl_0.109.16

loaded via a namespace (and not attached):
[1] htmlwidgets_1.5.4 compiler_4.1.3 magrittr_2.0.3 fastmap_1.1.0 R6_2.5.1 cli_3.2.0 htmltools_0.5.3 tools_4.1.3
[9] base64enc_0.1-3 rstudioapi_0.13 knitr_1.39 xfun_0.32 jsonlite_1.8.0 digest_0.6.29 rlang_1.0.4

</details>

Those are still there, but the location has changed. They are now static methods directly under rglwidgetClass, so a call to them looks like this:

rglwidgetClass.multVM(v, m);

instead of

this.multVM(v, m);

This was done so they could be used when there is no instance of an rgl scene available. Docs are still there, e.g. https://dmurdoch.github.io/rgl/rglClass/rglwidgetClass.html#.vlen .

I will use rglwidgetClass javascript global object directly now and not this local object from handler
Thanks for the pointer 👍.