[Interest] [Qt 3D] Using an orthographic projection

Sean Harmer sean.harmer at kdab.com
Fri Mar 25 09:32:45 CET 2016


On Friday 25 March 2016 08:06:36 Adrián Chaves Fernández wrote:
> I am working on a game engine with a top-down view where X represents
> North-South, Y represents West-East, and Z is the height (so, Y and Z are
> switched, regarding the OpenGL standard).
> 
> So far I have been successfully using a perspective projection (with some
> help
> <https://forum.qt.io/topic/65277/top-down-view-nothing-visible-with-qcamera-> at-0-1000-0-everything-visible-at-0-1000-0-01>), but I would like to switch
> to an orthographic projection.
> 
> However, I have no idea how to do so. This is what I got so far, but it is
> not working as I expect:
> 
>     cameraEntity->setUpVector(QVector3D(0, 1, 0));
>     cameraEntity->setViewCenter(QVector3D(0, 0, 0));
>     cameraEntity->setPosition(QVector3D(0.0f, 0.0f, 5.0f));
> //     cameraEntity->lens()->setPerspectiveProjection(60.0f, 16.0f / 9.0f,
> 2.0f, -1.0f);
>     cameraEntity->lens()->setOrthographicProjection(-10.0f, 10.0f, -10.0f,
> 10.0f, 2.0f, -1.0f);
> 
> Is the Y-Z switch the issue here, or is it something else? If the Y-Z
> switch is the issue, is there a way to handle it, or do I need to go back
> to the OpenGL standard?

The camera lens just constructs the view volume. In this case a cuboid from 
-10 to +10 in x and y but your near plane and far plane values look strange 
(2.0f and -1.0f). Try setting these to something like 0.01 and 20.0 to give 
you a viewing volume that is (almost) a cube. This defines the volume of space 
relative to your camera that will get rendered.

Then, consider where you camera is positioned and in which direction it is 
oriented. Do you want to be looking down on the X-Z plane or something else?

In such situations, do yourself a favour, and draw a picture on a piece of 
paper with the setup you are after. Otherwise it is so easy to get numbers or 
directions transposed in your head and end up using trial and error which 
usually ends up being fragile.

Cheers,

Sean

--
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. UK +44 (0)1625 809908, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions



More information about the Interest mailing list