How do I make objects attached to the camera never change their apparent size when I change the FOV?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ThomasCloneTHX1139
Posts: 3
Joined: Sun Aug 13, 2023 1:41 pm

How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by ThomasCloneTHX1139 »

I'm making a HUD for a space game. I'm taking inspiration from The Last Starfighter (see https://youtu.be/hafnDoApzpY?t=36 ), so the radar and attitude of the spaceship are represented by 3D spheres, attached to the camera node as children, which match the rotation of the camera.

I've implemented an effect where the FOV depends on the distance between the current camera position, and the camera position in the previous cycle. The faster the camera, the wider the FOV, so it appears that space is being distorted at high speeds. Right now, this applies to all objects, including those attached to the camera. Is there a way to tell the engine not to apply the FOV change to the objects attached to the camera, or a formula to rescale and reposition the objects depending on the camera's FOV, to compensate their changes in apparent size?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by CuteAlien »

HUD should probably always be on top? In that case easiest solution might be using a second scenemanager (ISceneManager:: createNewSceneManager) which is rendered after the first one. Which can have another camera with a different FOV. And then put the HUD stuff in the second scenemanager.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ThomasCloneTHX1139
Posts: 3
Joined: Sun Aug 13, 2023 1:41 pm

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by ThomasCloneTHX1139 »

Where do I find an example where it's used?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by CuteAlien »

There is no example for this.

But basically like this:
Create second SceneManager with something like: secondSmgr = firstSmgr->createNewSceneManager()
Give the second SceneManager it's own camera. Just a simple one with no animators, so secondSmgr->addCameraSceneNode() will do.
Put all objects which should be rendered with the FOV for your HUD in the second SceneManager.
After calling drawAll() for the first SceneManager, do set the second camera pos/up/rotation values to the same as the camera in your first SceneManager (just be careful that you need to call updateAbsolutePosition() after setting position and up-vector and before setting rotation or the rotation can get messed up). And then call drawAll for your second SceneManager.

That's should be all. Note that I did not test this, but in theory it should work.
There are some cases where this will fail. But if your HUD is in front of other objects and the second SceneManager renders the HUD it should be fine.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ThomasCloneTHX1139
Posts: 3
Joined: Sun Aug 13, 2023 1:41 pm

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by ThomasCloneTHX1139 »

It worked. I didn't even have to touch the position and rotation of the second camera, because I attached the HUD to the second camera, so, even if the camera doesn't move, the HUD is always displayed correctly.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by CuteAlien »

Ah right, HUD is fixed! Nice to know this actually works :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by AReichl »

> ..., do set the second camera pos/up/rotation values to the same as the camera in your first SceneManager ...

WHY?
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by AReichl »

Why should the second camera move at all?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?

Post by CuteAlien »

Yeah, we already figured out that's not needed in this case. Same position only needed if you want parts of the world in another FOV. But then one likely runs into depth-sorting problems anyway and this trick no longer works and one has to use shaders instead (edit: it could probably also be done in a lightmanager).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply