How to position objects relative to fullscreen width and height

I'm really enjoying using orx so far. Hopefully this is an easy one - I've set my Display to fullscreen. I then set my camera Frustum width and height based on that. I'd like to be able to set the position of objects relative to those dimensions...for example, to place a blocking pillar at the right edge of the screen. For now I've hard coded positions to look ok on my laptop.

The various ways I've tried to specify this in the Position= line of an object don't seem to work. Assuming this can be done in the ini file, how would you set an object position's x value at the screenwidth - 100 (for example)

thanks again for all the help!


  • Hi Funemaker, you can have a large empty object the same size as your viewport, and then have your objects as relative parent positioned inside the object. Then your position range will be 0.0 ... 1.0.

    And the size of the screen won't matter anymore.

  • Thanks @sausage, this makes sense. I've been trying to get it to work following the "UseParentSpace for Relative Object Positioning and Scaling" tutorial. Seems very simple but I haven't had success yet, my object always shows up at 0,0 when I do it this way.

    Will try again this weekend and see what is wrong.

  • Ah ok. I must have done something not so clear on that tutorial then. Oh and sorry... it's -1.0 to 1.0. So to go into negative range.

  • edited November 2019

    That's not entirely correct though, the viewport's size is in screen space, not world space, and if your camera's frustum isn't the same size as the screen, that won't work. However there's a simpler way, I'll come back to it at the end of this post.

    First things, you don't need to see the camera's frustum to match the display's screen resolution. If you do so, you will end up with different aspect ratio and very different sizes across different machines. This is going to be more of a nightmare to use than anything else. I'd recommend defining a camera size that matches your default target resolution, and then let the viewport do any scaling for you if need be.

    Now regarding your main question, you can set objects as children of a camera. Which in turn will enable you to position/scale them relatively to the camera. That's very handy for things like static backgrounds or UI elements.

    For this to work, you need to set the ParentCamera property on your object (and the camera needs to be created before the objects, obviously).

    Then you have a choice of using the UseParentSpace property. What this does is that instead of using regular units, everything will be relative to the camera's frustum size. By default, UseParentSpace is set to true, which means both position and scale will be expressed in "camera units", 1 meaning the whole length of the frustum on that axis.

    Let's take some examples. Let's assume our camera is called "MyCamera". Let's see how we would set a background object that will be scaled to match the entire camera's frustum:

    ParentCamera = MyCamera
    ; No need to set UseParentSpace as it's already true
    Scale = 1 ; This means that the object will be scaled so that it'll fit exactly 1 camera length on both vertical and horizontal axes
    Pivot = center
    Position = (0, 0, 1) ; This means it'll be exactly under the camera and all the way at the end of the frustum's depth

    Let's now say we want to have a ceiling object that aligns exactly with the top of our camera and that the object's entirely visible in the camera (ie. the object's top aligns with the camera frustum's top). Let's also say we want it to have a scale of twice its default size but won't adapt to the camera (ie. we want the position to be relative to the camera's size but not the scale):

    ParentCamera = MyCamera
    UseParentSpace = position ; Scale will be interpreted as usual, only position will use the camera's size
    Pivot = top ; This way by setting the object's position to match exactly the edge of the camera's frustum, everything will align
    Scale = 2 ; This won't mean twice the camera's size but twice the object's own default size, as per our requirements
    Position = (0, -0.5, 0.5); This means we align to the center of the camera on X, to its top on Y and we're halfway through the depth (Z)

    Note that relative position on one axis goes from -0.5 to 0.5, as 1 means the whole length of the camera's size on that axis (some might have expected to use -1 to 1 but that wouldn't be consistent with the fact that 1 = the whole size). Also note that if you resize your camera later on, the objects using UseParentSpace won't re-adjust their scale/position automatically, the UseParentSpace only affects the position/scale values at creation.

    Let us know if you need more details!

  • edited November 2019

    Now to cover your specific question (Pillar at screenwidth -100), you'll need to either use UseParentSpace and then find what 100 is in parent space (ie. 100 / FrustumWidth), or simply use plain value if you know what the camera's FrustumWidth is. Now if you want your pillar to fit entirely in the screen but be right at the edge (like our ceiling above), you won't need to know the FrustumWidth at all.

    Here are the three variants (assuming vertical centering):

    ParentCamera = MyCamera
    Pivot = center
    Position = % > Get MyCamera FrustumWidth, > / 100 <, - 1 < ; ie. 1 - (100 / FrustumWidth)
    ParentCamera = MyCamera
    Pivot = center
    UseParentSpace = false
    Position = % > Get MyCamera FrustumWidth, > / < 2, - < 100 ; ie. (FrustumWidth / 2) - 100
    ParentCamera = MyCamera
    Pivot = right
    Position = (0.5, 0)

    Note that you can also do the maths yourself and hardcode the values instead of using commands.

  • Thanks @sausage, I think maybe last night it was working, but I was setting my pillar x position to 0.1. That might be why I thought it was still showing in the center when I expected it closer to the left border. And the tutorial itself worked for me as expected, but just not when I tried to apply it to my own project and objects.

    And thanks @iarwain, that is a very comprehensive answer, thanks for taking the time. I'm off to work shortly so can't try anything until later tonight probably. Will report back if I have any trouble.

    thanks guys!

  • Ok, I quickly got it working before heading out. One thing that I got a little confused on is that I'm scaling my object to 0.5. I had this line before the UseParentSpace = position line and I think it must have been scaling to the camera's size. Once I moved the Scale= line after the UseParentSpace line it works completely as expected. Thanks!

  • That's weird as the order in config has absolutely no impact at all (all entries are stored upon loading). Are you sure there wasn't something else, like a typo?
    In any case, I'm glad it's now working. :)

  • I'll check it again later tonight...I thought that was strange for the order to have an impact.

  • My bad! Thanks for pointing that out...indeed the ordering has no consequence! I was able to retrace my tracks with undo in Visual Studio since I had left the file open this morning. Looks like I originally had UseParentSpace = both rather than UseParentSpace = position. Using "both" was causing unwanted scaling of my object. I apparently changed that AND the ordering of the property lines at the same time and made a bad assumption about which change was having an effect.

    That's what I get for trying to "quickly" try something on my way out the door. Sorry for the confusion!

  • No worries, I'm glad you found the reason, this way I don't have to hunt for a bug that doesn't exist!

Sign In or Register to comment.