Ericky14

[Solved] Device Scaling Resolution

Recommended Posts

Hello,

I have my canvas stretching 100% width and height of the page. When running it in a small resolution screen and in a big resolution screen, the whole thing is scaled up.

Is there any simple way to simple increase the radius of the camera based on the device resolution instead of having everything scale up? (Everything stays the same size just like regular html elements)

Share this post


Link to post
Share on other sites

I am. But that is not the behavior I want. You can test it with the default playground environment. I am expecting the camera radius to increase rather than the whole scene to scale up just like in game engines such as Unity. (I tested it with my laptop and my tv, the whole scene scales up and the html stuff looks really tiny next to the scene)

Share this post


Link to post
Share on other sites

Yep so you can do that but manually. There is no automatic way to keep the same visual representation as this clearly 

You are the first to ask but I'm interested to see if more people could use it

 

Why not starting to hack something in the playground to see how we could do that?

Share this post


Link to post
Share on other sites

Hey.
I had a similar problem. I solved it using this function when canvas resize. I don't have too much time now, but I'll provide a playground later. Play with it ;)

function fitToView()
{
    //component - is an object from the midle of the scene :))
	component.computeWorldMatrix(true);
	let radius = component.getBoundingInfo().boundingSphere.radiusWorld;
		
    let aspectRatio = engine.getAspectRatio(scene.activeCamera);
    let halfMinFov = scene.activeCamera.fov / 2;
    if (aspectRatio < 1) {
        halfMinFov = Math.atan( aspectRatio * Math.tan(scene.activeCamera.fov / 2) );
    }
    let viewRadius = Math.abs( radius / Math.sin(halfMinFov));
    scene.activeCamera.radius = viewRadius;
}

 

Share this post


Link to post
Share on other sites

I solved this problem by looking at the "window.devicePixelRatio" variable which is either 2 or 1. And I have "adaptToDeviceRatio" turned on. So, for an orthographic camera, I just change the radius(orthoTop, orthoBottom...) which should be doubled at devicePixelRatio 1. And for perspective camera, I also change the radius, but I set custom values for both 2 and 1 so they would match nicely since doubling didn't work too well.

Thanks for the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.