2
$\begingroup$

I built a cubic, then use MousePosition together with GUIScreenShot to take a floating region with fixed size (200*200) on the screen, and use it as dynamic texture on the cubic. My code is

Needs["GUIKit`"];
$HistoryLength = 1;

DynamicModule[{mpp},
 Dynamic@{
  Refresh[
   ClearSystemCache[];
   g = GUIScreenShot[With[{mp = MousePosition[]}, mpp = {mp - 100, mp + 100}]];
   Graphics3D[{Texture[g], Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]}, Lighting -> "Neutral"],
   UpdateInterval -> .5],
  mpp, g},
 Initialization :> (
  vtc = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
  coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}}, {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}};)]

You can see the result by executing the code then moving your mouse around. Like this, enter image description here

But there are two strange problems,

1) the size of the floating area taken should be always 200*200, however it will actually change.

2) the memory usage will constantly grow as we move our mouse, but I have already used $HistoryLength=1 and ClearSystemCache[].

Any suggestion?

$\endgroup$

1 Answer 1

1
$\begingroup$

Look very carefully at the documentation. This had me puzzled for a while too:

When the argument consists of screen coordinates of the form {{xmin,xmax},{ymin,ymax}}, a rectangle from the current screen is captured.

The key part is {min,max} like PlotRange. Your code produces {{min,min},{max,max}}.

I think the memory usage problem is a memory leak in the front end Java code. I don't think there's anything you can do about it except report it to WRI. If you really want to investigate, VisualVM might be helpful, though I have never tried it with Mathematica.

$\endgroup$
1
  • $\begingroup$ Yes I was too careless, should have written mpp = {mp[[1]] + {-100, 100}, mp[[2]] + {-100, 100}} instead. I will wait for some more time, if the memory problem cannot be solved, I will report it. Thanks! $\endgroup$
    – saturasl
    Sep 9, 2013 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.