Mode 7 demo + full source!

After chatting about mode 7 earlier today, I earned myself a short break and used it to knock up this demo. It only really shows the concept, but works well enough that I figured I’d give the source out and let people see how quickly you can knock up code in graphics 2.

Note the code is massively un-customisable as a result of me putting in a lot of quick hacks to get everything working ASAP, but it might be of use to someone.

What I’m basically doing:

  1. I load the level and create the sprites.

  2. I draw the entire level and place it into a display group.

  3. That group gets placed into a snapshot.

  4. I rotate the group and snapshot to match the player movement.

  5. I invalidate() the snapshot and then distort it to give a perspective effect.

The source includes the whole corona set-up, and also the Tiled level so you can have a play yourself.

Thanks Rakoonic - you’re certainly leading the charge on helping Corona devs utilise the power of Graphics 2.0…

As always… super cool!

Thank you very much!

awesome! looking forward to digging into this later today :slight_smile:

nice

how to add object on the track looking at you? Such as a tree.

Super cool. I played around with adding a filter effect, e.g. pixelate, to the global snapshot.

Just remember if you are applying pixelate to a snapshot, you are likely better off creating a smaller snapshot and just enlarging it onscreen - this way you don’t need the over head of the filter, and you actually speed things up as you are asking for lower fill-rate. See my section about pixelate here, about 1/4 of the way down the document: https://docs.google.com/document/d/168-Rp86pioZM-e0QM0GBb2eeBUasXAHPYm-iGu1xjLI/edit?usp=sharing  :slight_smile:

I should point out that if you are distorting the overall snapshot first, then my suggestion likely won’t have the intended effect. Just realised that and I will test it out and add it to the above doc to alert people to this!

What about my question? How to add objects on the track?(Trees, signs, etc.)

What you’d need to do is come up with a calculation that converts from the 2D coordinates of the Tiled level, via the 3D transform of the snapshot, back into a pair of 2D screen coordinates.

Normally this wouldn’t be too tough to achieve, but since I hacked this code together it isn’t gonna be really easy.

If I get time next week I’ll update the demo to use proper 3D transforms, which would make it easier to calculate.

Very nice indeed! Your other demos also look very nice, especially with threes in the car-demo. Are those threes flat 2D or do you model them as textured surfaces?

The reason I ask is that I have been planning a game in which threes and plant modeling would be necessary to get it going. Leaves are always a problem (you kind of end up with too many textures), so it hasn’t been possible in Corona.

What is you impression with respect to performance as for zooming in on objects? (E.g. driving towards them). In pre-graphics 2.0 it is very slow, especially for large objects.

Best,
Renato

PS: I used to make 3D games in the old days were 3D->2D transforms were the “normal way”. I don’t see why you have to go both ways as you could keep all the game mechanics in the 3D universe and only use the 2D transform for showing things on screen?

Zooming large objects isn’t much fun (and yes the trees are just a 2D image). I took out most of the overhead banners in the racing demo because up close each one was essentially a full screen or bigger sprite.

Trees get pretty big, but since they are never in the road, they get clipped and culled which helps a great deal.

For this demo you’d want to go 2D->3D->2D because the base information isn’t in 3D - it is a 2D Tiled map.

So what people would need is a way to take a 2D point in the Tiled level, and end up with a 2D point in screen space (but with a third component - the depth in 3D space so they would know how much to scale the object and how to depth sort).

So you’d go:

2D->3D (Tiled level position to 3D position on the road in perspective)

3D->2D (The 3D position to screen coordinates)

Thanks Rakoonic - you’re certainly leading the charge on helping Corona devs utilise the power of Graphics 2.0…

As always… super cool!

Thank you very much!

awesome! looking forward to digging into this later today :slight_smile:

nice

how to add object on the track looking at you? Such as a tree.

cool demo, but

I don’t get the benefit of emulating 3D in a 2D projection of a real 3D environent, besides retro mode7 coolness.

Isn’t it more complicated to manage all the perspective transformations instead of using a z-Buffer?