A leap between dimensions

Alright, so I study graphics, and I am baffled by how many people are.. well, baffled.. by the idea that I can program as well! Are people’s personal ambitions really so low that the very concept of being good at more than one area is cause for the reactions that gett? Anyhow, I’ve been making games since I was 13, and by that, I mean that I’ve been handling/learning all vital areas connected to that; 2d-graphics, 3d-graphics, programming, sound design and music. Thus, when this project started I made sure that my fellow workmates knew of the fact that I knew programming and could gladly help if it would be neccessary! This blogpost will be describing my process of how I created the dynamic, faked 3D walls, that we use in the game:

So, first of all we have the problem that needs solving: the game is viewed from a completely top-down perspective, and being a 2d game this poses a few problems, the most vital being that, well, you can’t see the walls, since the perspective is orthographic.

Failed solution #1:

To accomodate for this problem, my initial idea was, to simply tilt all the corners of the walls away from the center of the room and, to a degree this worked. We decidedthat we should use OpenGL and polygons  to dynamically create the walls, as such:

Blogg_2_1

 

This method allowed us to create new wall segments/rooms just by adding new controlpoints, and then a few simple trigonometric functions did the rest! We also used the very same controlpoints to later create the collision dynamically!

This solution worked for me… at first. To me, since I had set out to create walls that ”poked” upwards, that is what I saw. There is however a serious flaw with this technique; if you were do see the walls for the first time, you could just as well think that they went the other way, pointing downwards! This HAD to be fixed!

Failed solution #2

The first step to solve any problem is, to make sure that you’ve figured out the actual source of it! The source of our problem was, as I figured, that our brains are too clever to be fooled by a trick like the one we used before, faked perspective. So, I figured, why not make it real perspective! And this is what I ended up doing! Now, ”real” isn’t actually the right word to use.. we are in fact still faking 3D, but much more convincingly!

To fix this I let the bottom vertices have the position that they have, whilst applying a parallax effect to the ones on ”top”.

This worked great!…. aaaas long as you stayed in the first room… See, since I applied the same parallax offset to ALL roof-vertices, as you moved further and further away from the spawn position (0, 0), the walls began to cover up the entire level! This, also, HAD to be fixed!

Working solution:

The way I did it was, entirely on my own without Google I dare quite proudly say, to change the parallax individually for all vertices! I realized, that no matter where you should stand, the walls to your right should ALWAYS points to your right, the walls to the left should ALWAYS point to the left etc. So, the solution was, quite simply, to let the offset be, the distance between the player and the vertex, multiplied by a factor. Thus, the further a vertex was to your right, for example, the… well, further… it was to your right, and as you got closer to it, the offset decreased! This created the faked depth the we have in the game!

Another small problem that arose was, that as you moved right of a ”right” wall, you could see the wall from the other side. The way we solved this, was to apply so called back-face culling, a method that makes OpenGL only render out one side of the polygon!

To do this, you simply add..

glEnable( GL_CULL_FACE );

..before the draw-call! If you have other draw-calls after that point, you should also remember to add..

glDisable( GL_CULL_FACE );

.. afterwards! OuO