$\begingroup$

I'm trying to make a graphics display on a touchscreen device in Mathematica. This means that there will not be a keyboard available for functions such as Panning and Zooming. Because of this, I have created a scaling system to allow zooming, and a series of Events that are bound to aspects of panning. My code worked fine on a simple object, using for example a green cylinder and just moving the center of view:

EventHandler[ Dynamic[Graphics3D[{color, Cylinder[]}, ViewCenter -> {{1/2, 1/2, 1/2}, {x = CurrentPosition[[1]] + value[[1]], y = CurrentPosition[[2]] - value[[2]]}}, RotationAction -> "Clip"], Initialization :> (color = Green; value = {0, 0}; CurrentPosition = {1/2, 1/2})], {{"MouseDown", 2} :> (a = CurrentValue[MousePosition]; pt = CurrentValue[ImageSize]), {"MouseDragged", 2} :> {b = CurrentValue[MousePosition], drag = b - a, val1 = drag[[1]]/(pt[[1]]), val2 = drag[[2]]/(pt[[2]]), value = {val1, val2}}, {"MouseUp", 2} :> {value = {0, 0}, CurrentPosition[[1]] = x, CurrentPosition[[2]] = y}}]

(As a side note, I realize that most of you will probably find my code very sloppy, but I'm just a student and coding isn't really my forte) Above, I establish the Graphic wrapped in Dynamic, and make it so that your mouse position is initialized upon a right-click, the difference between your mouse and the initial click is recorded, and this distance is scaled and changes the two-dimensional center of view.

However, when I go to a much more complex manipulate function to allow for several objects that can be toggled on and off, zoom functionality and this panning system, everything works fine until the image is rotated. Following the rotation, my pan system does not work, and I was hoping that someone could tell me how to go about fixing my code. Sorry for this huge chunk of code, but here is the graphic that is not working.