## Playmat - A Mode 7 Library

hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

### Playmat - A Mode 7 Library

Borrowing retrotail's fast shader code, i've decided to create a library that helps the mode 7 effect become much more accessible. The mode 7 plane is well documented, but sprites were a big difficulty. After hitting that wall myself, i've finally figured it out, so i hope playmat helps you out too!

Playmat
A strong utility for making mode 7 games from within love2d!

Features:
• Fast to set up!
• Cool helper functions.
• Versatile sprite system.
• Ability to run on slow computers.
Example Code:

Code: Select all

PM = require("playmat")

mapimg = love.graphics.newImage("map.png")
spriteimg = love.graphics.newImage("sprite.png")

cam = PM.newCamera() --Sets up a new camera, resolution is 800 x 600 by default.

cam:setPosition(100,50)
cam:setZoom(48)

function love.draw()
PM.drawPlane(cam, mapimg) --The image drawn as a plane.

PM.placeSprite(cam, spriteimg, 125,100, 0, 8,8)
PM.renderSprites(cam) --And now the sprite is there too!
end

Changelog:

Code: Select all

v1.5 - Experimentally better
Sprites can now be colored!
Planes are stretchy now.
Planes now render directly using the shader.
Some major code improvements.

v1.2 - Minor
Fixed Sprite scaling problems

v1.1 - Perfection
Fixed non-square images not working right.

v1.0.3 - Hotfixes
The demo has also been updated to fix crashing for some.

v1.0 - Made public!
Find it here:
Github

Feedback would be greatly appreciated!

Demo controls:
wasd - Movement
q & e - Rotate
- & + - Zoom in and out
i & o - Change FOV
k & l - Change Offset
Attachments
Playmat Demo.love
Last edited by hatninja on Sat Jun 24, 2017 7:09 pm, edited 7 times in total.

zorg
Party member
Posts: 2732
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Playmat - A Mode 7 Library

hatninja wrote:(...)
Didn't try it out (yet), but i did look at the code a bit;

Code: Select all

local size = ((1/distance)/cam.z*cam.o)*800 -- line 162
I'm assuming that magic number there wanted to be the width of the screen? Or is it more magic than that?
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

### Re: Playmat - A Mode 7 Library

It was an approximation, but i'm still surprised i didn't catch that! Sounds like it would be the case!

zorg
Party member
Posts: 2732
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Playmat - A Mode 7 Library

I remember myself wanting to calculate aperture, fov and z distance relations for my own camera implementation too, was quite suprised that the equation turned out simpler than i imagined... which i did want to share, if only for the fact that with some "basic" values, like 90° field-of-view and similarly default numbers, what it gave me back was exactly half of the value i was expecting... but yeah, sadly i can' find my code, (nor the equations i actually wrote out into one of my notebooks) so i can't be more clear than this.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Playmat - A Mode 7 Library

This is amazing.

pgimeno
Party member
Posts: 1905
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

### Re: Playmat - A Mode 7 Library

I'm getting this:

Code: Select all

Error: playmat.lua:125: Shader uniform 'r' does not exist.
A common error is to define but not use the variable.
stack traceback:
[C]: in function 'send'
playmat.lua:125: in function 'drawPlane'
main.lua:26: in function 'draw'
[string "boot.lua"]:468: in function <[string "boot.lua"]:436>
[C]: in function 'xpcall'

I've got that sometimes myself. An extern variable is optimized out and that causes an error. I removed the 'extern r = 0' and the shader:send('r'...) lines and then it worked.

Awesome work!

Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Playmat - A Mode 7 Library

What version of Löve do you have? What GPU and drivers? It worked for me on 0.10.2.

Davidobot
Party member
Posts: 1149
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

### Re: Playmat - A Mode 7 Library

Jasoco wrote:This is amazing.
Does this mean that our Raycasters can get a proper floor now?
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Playmat - A Mode 7 Library

Davidobot wrote:
Jasoco wrote:This is amazing.
Does this mean that our Raycasters can get a proper floor now?
I was wondering that myself. Maybe you should do some experimenting. It'd be figuring out the correct angles to use to make it line up properly.

yetneverdone
Party member
Posts: 351
Joined: Sat Sep 24, 2016 11:20 am
Contact:

### Re: Playmat - A Mode 7 Library

wow, very awesome. Possible to make doom-esque fps?

### Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 6 guests