I have a spheric panorama rendered by Java applet which is placed onto HTML page. You can see an instance of this applet here: http://www.immervision.com/en/multimedia/index.php?cat=multimedia
(look near to right bottom side of page: in order to rotate panorama hold left button and drag it by mouse; in order to zoom use SHIFT and CTRL). I use the event handler for mouse event "OnClick". This handler recieves two arguments: (x,y) coordinates of clicked point inside Java Applet's window. (x,y) are in pixels relatively of the upper left corner of Applet. This is a "screen projection" coordinates. 0 <= x < w, 0 <= y < h. w - Applet's width, h - height in pixels.
In order to pick an object inside the panorama i should use "model coordinates". Java Applet uses spheric coordinates (Pan, Tilt) angles in degrees as an "model coordinates". Pan - horizontal rotation angle, Tilt - vertical rotation angle. I should calculate model (pan, tilt) coordinates by "screen pixel" (x, y) coordinates. How it can be performed?
x, y - screen coordinates - point clicked by mouse (pixels);
w, h - width and height of Java Applet's window (pixels);
FOV - field of view angle: Java Applet's settings parameter (degrees);
PanX, TiltC - model coordinates (angles) of the view's center poin (w/2, h/2)t: direction of the camera placed inside sphere in origin (degree);
Shoul be calculated:
PanX, PanY - model coordinates (angles) matching to clicked (x, y) screen point (degrees).
Any ideas/ways - how to create missing mathematical formulas?
I need to calculate (Pan,Tilt) by (x,y) in order to dynamically generate hotspot object inside panorama. Hotspots can be added into panorama by either ways: statically or dynamically. In both cases i should specify key-points, each is defined by (pan, tilt) angles.
Illustration of model coordinates can be viewed at: http://exchange.activewebservices.ru/hotspotpolygonal.gif
Panorama instance with static hotspots and illustration of model and screen coordinates can be viewed at: http://exchange.activewebservices.ru/tt/immervision.html
In order to pan - hold left button and drag by mouse. In order to zoom - use shift and ctrl. You will see screen object (+) over the center of Applet's window. This is an raster image. Also, you can find (rotate back) two static hotspots (green and orange) inside of panorama. They are defined as:
<hotspotRectangle id="hs1" color="0xffffaa00" visible="true" display="true"
pan="179.12" tilt="12.78" panSize="8" tiltSize="7">
<hotspotRectangle id="hs2" color="0xffaacc00" visible="true" display="true"
pan="160.98" tilt="11.91" panSize="8" tiltSize="7">
They are seen as unfilled rectangles distorted by perspective transformation. Defined statically by (pan,tilt) of the center and by (panSize, tiltSize) determining width and height.
Still, in my mind comes only equations listed below:
pan = atan2(y, x);
tilt = atan2( z / sqrt(x*x + y*y) );
and r*r = x*x + y*y + z*z;
But, it is far from applicable results.
Thanks for response!