Sure you could! I actually don't think I used the vector module in the end. it's from HÜMPEamonn wrote:Incredible job! I could never do anything like that I spent about 10 minutes just moving about and being fascinated. The code wasn't all to confusing either(granted I only looked at main.lua). I assume the Vector thing was a library or something? Or did you make it?
The meat of it is all in buildings.lua
On update you ask for the four corners + each slice's height relative to your viewport. Using those corner data you can scale and position each of your slices into a spritebatch to draw each side. I'm working on generalizing it to be able to use any number of points positioned relative to the origin to allow for more interesting buildings and street lamps and hanging stuff. It is very dumb in that it assumes the viewport is at a fixed rotation, and it's not super efficient given that each side needs its own batch, and currently only supports scaling a single texture, but it's progress. I've got it shimmed into my working game right now although it doesn't make much sense with the buildings in the middle of the street
just for the sake of sharing, the algorithm to get the projected position on the screen of an object with height (that I used) is:
Code: Select all
px = cameraHeight * (object.x - cameraX)) / (cameraHeight - object.z) + cameraX py = cameraHeight * (object.y - cameraX)) / (cameraHeight - object.z) + cameraY