Screen orientation and camera

Started by robert, September 25, 2012, 07:15:47 PM

Previous topic - Next topic

robert

Hi there,

How do I make the scene look the same in both portrait and landscape orientation ? If I setup my scene in portrait mode, when I switch to landscape, the objects don't fit the screen and look bigger, as if the camera position was changed. In the other 3d engine I'm using (Rajawali), the scene looks the same in both landscape and portrait mode.

Thank you.

EgonOlsen

The scene can never look the same if you switch from x*y to y*x. If it would, switching resolutions would be pointless. I think you mean that the size of objects in the scene doesn't change, right? If so...well, in jPCT you can set the fov (field of view). The field of view is indepent of the resolution or the orientation. If you look at the rendered image, you'll notice that the field of view (i.e. how wide is the viewing angle between the left and the right egde) always stays the same. The logical consequence of this is, that objects get bigger on screen if the x-resolution increases (i.e. if you switch to landscape). Any other behaviour would render a fov setting useless. If you want different behaviour, you have to change the fov between landscape and portrait mode.

robert

Thank you Egon, then I should use Camera.setFOV() in onSurfaceChanged() ? What value should I pass to setFOV() ? it's all about trial and error ?

OneManSitting

well i mean you can calculate the field of view. :-\

robert

Egon, this is what the Rajawali engine does onSurfaceChanged():

public void onSurfaceChanged(GL10 gl, int width, int height) {
mViewportWidth = width;
mViewportHeight = height;
mCamera.setProjectionMatrix(width, height);
GLES20.glViewport(0, 0, width, height);
}


And this is the camera setProjectionMatrix() method referenced above:

public void setProjectionMatrix(int width, int height) {
float ratio = (float) width / height;
float frustumH = MathUtil.tan(getFieldOfView() / 360.0f * MathUtil.PI) * getNearPlane();
float frustumW = frustumH * ratio;

Matrix.frustumM(mProjMatrix, 0, -frustumW, frustumW, -frustumH,
frustumH, getNearPlane(), getFarPlane());
}



Can I replicate this in JPCT-AE ?

EgonOlsen

That's actually the exact same thing that jPCT-AE does except that jPCT-AE assumes that fov means the field of view in x-direction while this code assumes that fov defines the field of view in y-direction. Personally, i find this highly unintuitive, because nobody defines his field of view in up/down-direction. Anyway, you can get behaviour by setting the fov values for x and y explicitly. To do this, you can do something like:


Camera cam = world.getCamera();
float fov=1.25f;
if (w > h) {
cam.setFOV(fov);
cam.setYFOV(fov * ((float)h / (float)w));
} else {
cam.setFOV(fov * ((float)w / (float)h));
cam.setYFOV(fov);
}


Hope this helps.

robert

Quote from: EgonOlsen on September 27, 2012, 09:42:35 PM
That's actually the exact same thing that jPCT-AE does except that jPCT-AE assumes that fov means the field of view in x-direction while this code assumes that fov defines the field of view in y-direction. Personally, i find this highly unintuitive, because nobody defines his field of view in up/down-direction. Anyway, you can get behaviour by setting the fov values for x and y explicitly. To do this, you can do something like:


Camera cam = world.getCamera();
float fov=1.25f;
if (w > h) {
cam.setFOV(fov);
cam.setYFOV(fov * ((float)h / (float)w));
} else {
cam.setFOV(fov * ((float)w / (float)h));
cam.setYFOV(fov);
}


Hope this helps.

Thank you very much Egon ! :)