View Frustum top/bottom parameters

Started by msandin, November 10, 2015, 12:14:16 PM

Previous topic - Next topic

msandin

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

EgonOlsen


msandin

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?

msandin

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.

EgonOlsen

#4
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?


msandin

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!  :)

EgonOlsen

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... :(

msandin

Thanks for considering it and once again, thanks for the lib!

EgonOlsen

#8
Please try this jar: http://jpct.de/download/beta/jpct_ae.jar

It contains an additional method in Camera called


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.

msandin