Page 1 of 3

How to make a false floor in 3D?

Posted: Wed Dec 18, 2013 9:38 pm
by alberto_lara
Hi, I'm trying to code an algorithm which can make a fake 3d ground/floor like, e.g., in super mario kart (here's a video: http://coolrom.com/roms/snes/7973/Super_Mario_Kart.php).

I'm trying with the kx and ky parameters of love.graphics.love (and rotation) but not sure of what should I do.

I have only this: https://mega.co.nz/#!E8BUVDYQ!a--OQQxb0 ... fFf1ExjWSk
the ground and the rocks (that are suposed to rotate along the ground) rotate with left and right arrows.

What would be a good technique? Many thanks.

Re: How to make a false floor in 3D?

Posted: Wed Dec 18, 2013 10:11 pm
by micha
What you want to achieve is called Mode 7. Unfortunately it is not possible to achieve with LÖVE's onboard functions. kx and ky always do affine transformations. That means that two parallel lines in the texture always stay parallel.

Some people on this forum have implemented Mode 7 in LÖVE. Have a look here, for example or use the forum search.

For a few cases it is possible to use kx and ky to get a 3d effect by applying a transformation on the image in a preprocessing step. I posted an example here, but this method is not very common and only works in very restricted cases.

Re: How to make a false floor in 3D?

Posted: Wed Dec 18, 2013 10:56 pm
by kikito
I am going to give a blind strike here and say that you can probably implement mode 7 with shaders. But I have no idea how.

Re: How to make a false floor in 3D?

Posted: Wed Dec 18, 2013 11:28 pm
by Jasoco
I made a Super Mario Kart clone a while ago using the fake Mode 7 Canvas technique I learned for the other project I was doing at the time, a Wolfenstein 3D clone with floor texture support. (Like Blake Stone) It uses canvases to the extreme though as it requires two separate large canvases per surface. So it might not be optimal for projects where you want to keep support high.

My code was a mess though. But if you want to look at it, it's in one of the files in this zip file, probably game.lua..

https://www.dropbox.com/s/mwr7ncynxeenvfx/Kart.zip

It's not that good though as graphically it looks bad so you probably won't want to use it. But whatever. I'll be removing the file from my DropBox probably next week so grab it while you can. It's also for 0.8.0 I think and is really outdated.

But shaders or something are probably a better method.

Bottom line, 3D in Löve is one of those things everyone has tried, including me. Some of us have done some really cool stuff actually. (I've posted video examples numerous times in other threads. A couple are right here, two of the 3D examples are my own.) But it's not something Löve is built for out of the box.

Re: How to make a false floor in 3D?

Posted: Wed Dec 18, 2013 11:36 pm
by master both
Jasoco wrote:(I've posted video examples numerous times in other threads. A couple are right here, two of the 3D examples are my own.) But it's not something Löve is built for out of the box.
I like how you search that post with the word useless

Re: How to make a false floor in 3D?

Posted: Thu Dec 19, 2013 2:05 am
by alberto_lara
Thanks to all for the answers, I don't know a lot about shaders but I'll take a look.

About that "LOVE doesn't do anything" thread... I hope it's just a sarcastic joke.

Re: How to make a false floor in 3D?

Posted: Thu Dec 19, 2013 2:25 am
by alberto_lara
Jasoco, I guess the Kart game was made for löve 0.8.0, I 'm trying to change the code to 0.9.0 but I get this and I don't know why:
Image

Re: How to make a false floor in 3D?

Posted: Thu Dec 19, 2013 3:29 am
by Jasoco
alberto_lara wrote:About that "LOVE doesn't do anything" thread... I hope it's just a sarcastic joke.
It was a troll.
master both wrote:I like how you search that post with the word useless
I am so glad I left that part in the URL. It was the only way I could remember how to find the thread.
alberto_lara wrote:Jasoco, I guess the Kart game was made for löve 0.8.0, I 'm trying to change the code to 0.9.0 but I get this and I don't know why:
Image
It's an old project that never went anywhere. Sadly the code for drawing the floors relies on the raycasting code the original project was based on. The reason you are getting the error is because the map doesn't exist. I don't know why it doesn't. I might have deleted it, or it never existed. Or I was in the middle of coding when I gave up on the project. Either way, it won't work. Tell you what...

Edit: DropBox link removed. Instead, go to this thread post where I just discovered I had already uploaded this code to the forum, lololol
http://love2d.org/forums/viewtopic.php? ... 76#p105928

This project probably actually works. It's my 3D Wolfenstein clone engine as it was when I stopped working on it. It might actually work. Just remember, it still relies on the same raycasting math your current project might not use. I remember having a problem getting the floor and walls to line up correctly. And yes, it's for 0.8.0.

Edit: I'll explain how it works. It works by creating a floor canvas that consists of the entire floor map predrawn onto a canvas. This floor canvas is drawn onto a container canvas of a significant size (Usually the same size as the floor) at the rotation and offset of the camera. Then, an array of quads is created from top to bottom of the container. Lastly, the floor casting function creates an array of rays from the central vertical point to the bottom of the screen and scales them based on the distance from the camera. Thus you get the illusion of a floor. Reverse the process for a ceiling. It doesn't look perfect though. Since it's canvases, you either need to use small canvases with low resolution textures or rely on a very small fraction of users being able to run it in order to get larger ones.

Re: How to make a false floor in 3D?

Posted: Thu Dec 19, 2013 3:48 am
by alberto_lara
Ok, thanks anyway.

Re: How to make a false floor in 3D?

Posted: Thu Dec 19, 2013 11:57 am
by Kingdaro
Wouldn't you be able to use a Mesh?