Author Topic: View Frustum top/bottom parameters  (Read 3000 times)

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
View Frustum top/bottom parameters
« on: November 10, 2015, 12:14:16 pm »
Hello,

I'm working on a small project and I've got a slight problem. The observer is standing in a dungeon of sorts and I want him to see more of the floor than of the ceiling given that it's actually much more interesting. I found the interactive explanation at http://relativity.net.au/gaming/java/Frustum.html quite enlightening. What I want it the effect of setting bottom to "-0.7" and top to "1.3", e.g. the effect of moving the vanishing point up inside the viewport. And no, looking down slightly does not quite create the desired effect as that also affects the perspective on items making vertical lines non-parallell in screen space.

I've so far failed to replicate this in jPCT-AE, any way?

Regards,
Martin

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: View Frustum top/bottom parameters
« Reply #1 on: November 10, 2015, 03:43:43 pm »
Just move the camera down?

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
Re: View Frustum top/bottom parameters
« Reply #2 on: November 10, 2015, 05:08:52 pm »
But if I move the camera down I will be looking up at things I was previously level with. Imagine you have a frame (the viewport) in front of you and through it you can see an object at eye level. If I move my head up/down my perspective on the object will change as I will see it slightly from below. What I want to achieve and what those up/down parameters seem to do is to slide the frame downwards instead. That is what the up/down parameters seem to do if I've not misunderstood things horribly (which I'm admittedly prone to do). When I can only control the angle covered in the y-direction (and indirectly at that, which I am fine with) I am left in a situation where the vanishing point for lines which are parallel to the direction of my camera is always placed in the exact center of the screen, e.g. "up" and "down" are always equal. I want to shift that vanishing point up the screen.

Does that make more sense?

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
Re: View Frustum top/bottom parameters
« Reply #3 on: November 10, 2015, 07:58:17 pm »
One could conceivably fake it by rendering a texture which is f.ex. 1/4 higher than the viewport and then blit the bottom part of it onto the screen but that does seem to be a terrible waste of fillrate.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: View Frustum top/bottom parameters
« Reply #4 on: November 10, 2015, 08:17:37 pm »
I see what you mean. No, that's not possible at the moment (at least not directly. You could do that texture thing that you've mentioned, but...Urgh!) and I'm not sure if it's a good idea anyway. That will lead to a strange looking perspective distortion of things on the ground. It might be ok, if all the player can do is to look straight along the z-axis, but if he can look up or down as well, the same frustum will be used and that will look strange. Older 3D games like Duke 3D used this approach to allow the player to look "down" or "up", but it wasn't very convincing and looked quite strange IMHO.
During all these years in which jPCT(-AE) exists now, nobody ever asked for this feature so it doesn't seem like a common thing. The issue that I have with adding that option is that I would have to modify the culling pipeline and all the stuff in Interact2D for this, and I'm not sure if it's really worth it.

Maybe you can explain your actual use case in more detail. Will the player be able to look up and down on his own or will the view be fixed?

« Last Edit: November 10, 2015, 08:34:11 pm by EgonOlsen »

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
Re: View Frustum top/bottom parameters
« Reply #5 on: November 10, 2015, 09:46:28 pm »
Yes indeed, the project I'm toying is a dungeon crawler and it would be restricted to viewing along the Z-axis with just a bit of glancing up/down. I've put together an image to illustrate the effect:

https://goo.gl/photos/ZeQvMN2HxZ9w9zrF6

In old pseudo-3D games such as Eye of the Beholder and Black Crypt this effect is quite pronounced. In Grimrock the effect is somewhat more subtle but the center of the red cross is some 60px above the center of the viewport. To the right you see what I've got right now and though I can tune down the pitch some one can still see that the vertical walls aren't parallell and it looks worse when it moves/animates. It also gets progressively worse as the architecture gets taller and/or thinner, I doubt pillars will look very nice. It's actually quite hard to get the tradeoffs right in situations such as wanting to see the floor when you're standing up close to a wall and similar.

There was another person working on a dungeon crawler and asking for the same things in this forum a couple of years ago and he was satisfied with your answer to raise and tilt the camera but I'm probably a bit more fussy. It bugs me because the tradeoffs are clearly noticeable once you understand them and the solution seems simple. But "seems" is always hard to nail down and I actually figured that this might mess up more of your calculations than you might care to change.

In any event I'm very happy with your library and most grateful for your hard work, thanks a whole bunch!  :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: View Frustum top/bottom parameters
« Reply #6 on: November 10, 2015, 10:18:39 pm »
I'll have a look at it. Changing the frustum itself is done in a few minutes, but sadly that's only one part and the other ones aren't that simple... :(

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
Re: View Frustum top/bottom parameters
« Reply #7 on: November 11, 2015, 12:46:33 pm »
Thanks for considering it and once again, thanks for the lib!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: View Frustum top/bottom parameters
« Reply #8 on: November 11, 2015, 09:43:09 pm »
Please try this jar: http://jpct.de/download/beta/jpct_ae.jar

It contains an additional method in Camera called

Code: [Select]
Camera.setFrustumOffset(<float> offset);

The offset is a relative offset, not an absolute one like in your example. That's because in jPCT-AE, you never really specify the top and bottom parameters. They will be calculated based on your fov settings and your device's resolution. So you never know the actual values and applying an absolute offset to unknown (and varying) runtime values doesn't make much sense IMHO.

Anyway, I hope that I managed to find all other code parts that have to take this into account...please give it a try and let me know how it worked out.
« Last Edit: November 11, 2015, 09:57:07 pm by EgonOlsen »

Offline msandin

  • byte
  • *
  • Posts: 20
    • View Profile
Re: View Frustum top/bottom parameters
« Reply #9 on: November 12, 2015, 09:16:02 am »
That works very nicely thanks!