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?
How do I make objects attached to the camera never change their apparent size when I change the FOV?
-
- 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?
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- 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?
Where do I find an example where it's used?
Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?
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.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- 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?
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.
Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?
> ..., do set the second camera pos/up/rotation values to the same as the camera in your first SceneManager ...
WHY?
WHY?
Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?
Why should the second camera move at all?
Re: How do I make objects attached to the camera never change their apparent size when I change the FOV?
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm