Jump to content

engine.getRenderWidth() and .getRenderHeight() don't take engine.getHardwareScaleLevel() into account


focomoso
 Share

Recommended Posts

In babylon v2.5, engine.getRenderWidth() and .getRenderHeight() return doubled what's expected on retina displays. Scene.pointerX and .pointerY do not, so in order to match screen clicks to objects in the scene, you need to multiply the renderWidth and height by engine.getHardwareScalingLevel(). 

This means that the preferred way of getting the screen coordinates of an object:

BABYLON.Vector3.Project(
        BABYLON.Vector3.Zero(),
        BABYLON.Matrix.Identity(),
        scene.getTransformMatrix(),
        camera.viewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight())
);

Will fail on retina displays.

It seems more intuitive for getRenderWidth and height to do the scaling themselves. (Or, as has been mentioned before, I think, adding a specific object to screen method on scene or engine).

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...