FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #1

    getViewpoint() and setViewpointCenter()

    It seems to me that image.getViewpoint() and image.setViewpointCenter() use different references for Y. That is, when I getViewpoint() the Y is positive (for example) but to set it the same, I have to setViewpointCenter() with -Y. It's like one uses top-left for Y reference and the other uses bottom-left for Y reference.

    Thoughts?

  2. #2
    Is this in FGU or FGC?

    JPG

  3. #3
    FGU.

    Here are examples of zooming in and zooming out. You can see that I had to negate the Y to make it work.

    Code:
    function zoomIn(image)
    	local vpX, vpY, vpZoom = image.getViewpoint();
    	-- for some reason, you have to negative Y
    	image.setViewpointCenter(vpX, -vpY, vpZoom*1.1);
    end
    
    function zoomOut(image)
    	local vpX, vpY, vpZoom = image.getViewpoint();
    	-- for some reason, you have to negative Y
    	image.setViewpointCenter(vpX, -vpY, vpZoom/1.1);
    end

  4. #4
    This is a bug in the API. The result of getViewpoint should be Y-positive in down direction like the rest of the API. It is currently returning Y-negative in down direction (which is what Unity uses internally).

    I'll get it fixed in the next release build.

    Regards,
    JPG

  5. #5
    Sounds good. If you don't mind posting back here when it's fixed then I'll fix my extension.

  6. #6
    You can subscribe to EA release updates on this thread.
    https://www.fantasygrounds.com/forum...Access-Updates

    Regards,
    JPG

  7. #7
    @Moon Wizard - Thanks for the fix.

    However, I'm still experiencing madness with this. Here's some code:

    Code:
    local vpX, vpY, vpZoom = image.getViewpoint();
    local w, h = image.getImageSize();
    
    Debug.console("Current viewport center after Zoom to Fit but before hitting running code below: ", vpX, " ", vpY);
    Debug.console("w and h of image: ", w, " ", h);
    		
    local newW = w/2;
    local newH = h/2;
    
    Debug.console("NEW w and h for centering image--should be middle point: ", newW, " ", newH);
    
    image.setViewpointCenter(newW, newH, vpZoom);

    This should center the image, right? Well, sometimes it does. Sometimes, it doesn't. The doesn't is the problem.

    I have an image here that I created in Photoshop and imported into FGU by dragging from Assets into the Image/Maps list to create a new image record. It's 1000px x 1000px at 72dpi. When I hit the "Zoom to Fit" button, it correctly fills the image window. However, when I hit my button to center it, it moves the image so that the bottom right hand corner is in the center of the image window. With some images, it's not the bottom right corner, it's the bottom left that gets centered.

    BUT... what's totally weird is that on some images--like the map images from the DMG and other images in modules, the calculations work (newW and newH are the centre of the image) AND my code above correctly centers the image in the viewport, regardless of zoom level, regardless of scroll position.

    It's like it only doesn't work with images imported from Assets by hand (I've tried a number of them and none of the work properly with the code above). And it's like it always works with images from modules (I've tried a number of them, too).

    And it feels like after hitting Zoom to Fit then running my code above, the viewPort's data isn't updated after the Zoom to Fit--if I look at what the Debug commands above return, sometimes the first Debug shows the center values and sometimes they make no sense. I would have expected that after Zoom to Fit, if an image is 1000x1000, what getViewPort should return is the center, 500 and 500. But only with images imported into FGU by hand, not images from modules.

    Is something not being set correctly in the database data of images brought in by manually creating the image records that's causing the code above not to work?

    (Sorry about the weird description... it's hard to explain.)

    After Zoom to Fit but before my centering code.png

    After my centering code.png
    Last edited by zuilin; November 1st, 2020 at 16:06.

  8. #8
    Viewpoint 0,0 is not the midpoint of an image. The image layers are laid out on an imaginary set of axes.

    If you drop an image into the images list or into the image data control, it adds at 0,0 by default. If you drop an image onto the image directly, it adds at whatever x,y coordinate that the mouse is at. 0,0 is only the center of the image if the image is placed at 0,0.

    Regards,
    JPG

  9. #9
    Quote Originally Posted by Moon Wizard View Post
    Viewpoint 0,0 is not the midpoint of an image. The image layers are laid out on an imaginary set of axes.

    If you drop an image into the images list or into the image data control, it adds at 0,0 by default. If you drop an image onto the image directly, it adds at whatever x,y coordinate that the mouse is at. 0,0 is only the center of the image if the image is placed at 0,0.

    Regards,
    JPG
    Right, but where is 0,0? Top left? Bottom left?

    How would you calculate the centre of an image and place it in the middle of the viewpoint if not h/2 and w/2 then use setViewpointCenter to place at midpoint of h and w at centre of the viewpoint? How does Zoom to Fit do it?
    Last edited by zuilin; November 1st, 2020 at 17:12.

  10. #10
    0,0 is completely relative to how image assets were added. For example, you could have only a single 1000,1000 image placed at 5000,5000. That doesn't change where 0,0 is located. The 0,0 position is not relative to assets; the assets are placed relative to 0,0.

    I'm not sure if there is currently a way to calculate the center position of an image. We aren't planning on adding any FGU specific image APIs until we get further past release. For now, you should use the zoomToFit or zoomToFill APIs for image controls (added for FGU) to do that.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in