Hello, krpano guys. I have an issue which breaks my mind. Currently I am working on polygonal hotspots editor which will be used as a part of CMS for panoramas management.
This editor will provide ability for end-users to select some picture and then display it as a hotspot inside panorama. Also, user will be able to display only a particular area of the picture with appying polygonal hotspot mask to it. Of course user need to specify polygon points too. The only aim of the current editor is to give ability set picture into polygonal hotspot. Here is the example code showing how two types of hotspots cooperate with each other.
<hotspot name="polygonal_mask" capture="true" alpha="1" fillcolor="0xffffff"
fillalpha="0xffffff" visible="true"
fillcolorhover="0xffffff" fillalphahover="1"
<point ath="0" atv="0" />
<point ath="25" atv="0" />
<point ath="25" atv="50" />
<point ath="0" atv="50" />
</hotspot>
<hotspot name="masked_picture"
url="picture.jpg"
atv="0" ath="50"
width="200" height="200"
alpha="1" blendmode="normal"
distorted="true"
mask="hotspot[polygonal_mask]">
Display More
I want to create "flat editor" outside of krpano, so user will see only picture and then set polygon points by clicking on picture, similar to image map editor like this (http://iakob.com/canvas-area-draw/demo.html ).
So, after above operations I have flat coordinates of polygon points relative to the picture dimensions. For example, if I have 200x200px picture and I want to create polygonal mask that will hide right part of the original image and leave only left part, then I need to specify polygon with such coordinates (in clockwise order starting from left-top corner) [0,0], [0,100], [100,200], [0,200].
Now I need a way how to convert these flat points coordinates to a spherical coordinates inside panorama. For example, I have distorted image hotspot placed on the panorama at atv=0, ath=0 coordinates. Then I try to recalculate polygon points coordinates with spheretoscreen/screentosphere functions in a such way:
//Convert image hotspot spherical coordinates to screen coordinates
spheretoscreen(hotspot[masked_image].ath, hotspot[masked_image].atv, hsx, hsy);
//Recalculate polygon point coordinates relative to current hotspot[masked_image] coordinates (hsx, hsy)
for(set(i,0), i LT hotspot[polygonal_mask].point.count, inc(i),
//On start hotspot[polygonal_mask].point[get(i)].ath, hotspot[polygonal_mask].point[get(i)].atv is initialized with flat coordinates relative to the image dimensions
//we need to add current hotspot[masked_image] screen coordinates (hsx, hsy) to each point coordinates
add(nhsx, hotspot[polygonal_mask].point[get(i)].ath, hsx);
add(nhsy, hotspot[polygonal_mask].point[get(i)].atv, hsy);
//Cause hotspot[masked_image] has origin at center, but initial polygon coordinates were started from left top corner,
//so that we need to subtract half image width and height from new point x,y coordinates accordingly
sub(nhsx, 100);
sub(nhsy, 100);
//Convert new point's coordinates to spherical
screentosphere(nhsx, nhsy, hsh, hsv);
set(hotspot[polygonal_mask].point[get(i)].ath, get(hsh));
set(hotspot[polygonal_mask].point[get(i)].atv, get(hsv));
);
Display More
But it gives me wrong results, so my polygon didn't fit properly. I think that problem is that spheretoscreen/screentosphere gives coordinates according to visible screen area(stage), but not according to the whole panorama image size. I don't know. Maybe I am wrong.
Please give me some feedback about my approach and maybe some ideas about how to solve this.