Z height = x pixels?

1 favourites
  • 14 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • Trying to estimate the z height to pixel ratio. Is there any set way to figure that out?

    I realize that it will vary based on the view.

  • The boxes in the example that are 80x80 with a z height of 14 look pretty cubeish to me.

    That should stay consistent regardless of the view I believe.

  • Herm yeah rough estimates look like about 5 to 1.

  • So when we first added Z elevation the Z axis was originally normalised such that at 100% zoom the camera is at a Z position of 100, looking down at the Z=0 plane (i.e. 100 units away). This kind of made sense for Z elevation to make it simple to use no matter the view size. However with the added 3D features I think it's actually become a bit of a complication. We might need to add a setting that lets you change this to something that uses equal units on all axes for 3D.

    To work out the math you just need to think about the camera on a side-view, and use trigonometry:

    If you split the view in half, notice the top triangle has an angle of fov / 2, and the opposite side of the triangle has length viewH / 2. Currently Construct calculates z to be 100 and scales the view to fit that, using a fixed FOV of 45 degrees. But instead you can calculate what z ought to be given the angle and opposite length. With trigonometry we know tan(a) = opposite / adjacent, which in this case is tan(fov/2) = (viewH / 2) / z. Rearranging to solve for z, we get z = (viewH / 2) / tan(fov/2). If I open the 3D shape example and use the view height there of 480, this gives z = 240 / tan(22.5) = 579.4 (approx). Since we know Construct calculated z to be 100, this gives a Z scale factor of ~5.8 to match Z units to X/Y pixels. So one of the 3D boxes is 100x100; to make it a cube its Z height should be 100 / 5.8 = 17.2 (approx).

    So if I set the cube to a Z height of 17.2 and set up a 3D camera looking at it, bingo, it looks like a cube with the same size on every axis:

    The default of 14 was just a guess from eyeballing it, but is a bit too short. Your guess of about 5:1 was close, it's 5.8 in this case, but as you can see it depends on the viewport height of the project.

    With a new camera setting to match all the axes, you'd be able to just set the 3D shape to 100x100 with a Z height of 100, and it'd look cube. Although I'd add the details of these calculations may change in future, such as if we add a configurable FOV.

  • I realised the runtime can actually calculate this for you, so I've added a read-only Z scale property to 3D camera, and a new ZScale expression on 3D camera, for the next beta.

  • Thankyou!

    I think it will be super handy for anybody doing billboarding, especially if they do any camera changes.

  • now that's proactive! thanks for the inquiry Newt!

  • Thanks for explaining the math behind it, I really enjoyed reading it and appreciated the detailed post.

  • Thank you Ashley, z scale now is really not perfect

    this is how exported from blender cube looks like

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you Ashlie, z scale now is really not perfect

    A. That's not his name.

    B. This has nothing to do with what the thread is about.

    C. This is a third party issue. Mikal is still working on the plug, and he's doing a an awesome job.

  • > Thank you Ashlie, z scale now is really not perfect

    A. That's not his name.

    B. This has nothing to do with what the thread is about.

    C. This is a third party issue. Mikal is still working on the plug, and he's doing a an awesome job.

    Thank you for pointing my mistake with the name.

    about other your notices, it is the same issue I believe

    We do not see that cubes are distorted because we are do not see how related width and height of the object with Z height.

    And only when placing a real 3d cube we see that something is wrong

    Also, imported models look ok in the editor and shrinking only when we are using 3D camera on the game preview

    And yeah, Mikal doing a really great job. waiting for the newest version of the plugin with the support of skeletal animation and other 3D formats

  • 1mrpaul1 If you think there's a bug go file a bug report.

    github.com/Scirra/Construct-3-bugs/issues

    This thread is about figuring out what the pixel scale is.

    I would thank you to not hijack it.

  • Ashley thanks for all the info. Can you please also add a C3 script interface for the coming 3DCamera Zscale also?

  • Good point, added for the script interface too in the next beta.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)