Trying to convert flat polygon points coordinates to polygonal hotspot

  • 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.

    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:

    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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!