[Solved] Projection of a 3D space in LÖVE
Posted: Mon May 22, 2017 4:40 pm
As said above, I need a formula to properly simulate a 3D space in LÖVE; not necessarily in a realistic manner.
I've been successful by setting a z axis in an object and then proceed to the following:
and it worked somewhat properly.
I quickly found out that the coordinate system didn't work for this; so I got the idea of creating a camera object to change the drawn positions without changing the object's real position; that way I could draw it in the middle of the screen and it would still be at x=0,y=0
It worked! It worked perfectly. Until I realized that I needed the camera for something else in my real project (I made another love project just to test the meter scale and the tridimensional simulation)
Now, I got the idea of making yet another camera object, one for the z axis, and the other for everything else. But I'm not sure that would work and even if it did I think it would be somewhat redundant, unpractical and it would make the processor pretty angry.
And that's why I'm here, Does anybody know a better way to do this?
Thanks in advance!
I also attached the .love file of this; just in case you want to know /exactly/ what I mean. If you want to check exactly why I don't want the camera to be at x=0,y=0; then try it out for yourselves
I've been successful by setting a z axis in an object and then proceed to the following:
Code: Select all
m = 50 --1 meter in-game = 50 pixels on-screen
lg = love.graphics
rect = {0,0,1,3,3}
local x,y,z,w,h = unpack(rect)
lg.draw(dot, (x*m)/z , (y*m)/z , 0 , (w*m)/z , (h*m)/z)
I quickly found out that the coordinate system didn't work for this; so I got the idea of creating a camera object to change the drawn positions without changing the object's real position; that way I could draw it in the middle of the screen and it would still be at x=0,y=0
Code: Select all
m = 50 --1 meter in-game = 50 pixels on-screen
lg = love.graphics
rect = {0,0,1,3,3}
cam = {1,1,0,1,1}
cam[1],cam[2] = 800/2,600/2
local x,y,z,w,h = unpack(rect)
local cx,cy,csx,csy = unpack(cam)
lg.draw(dot, ((x * m)/z) + cx , ((y * m)/z) + cy , 0 , ((w * m)/z) + csx , ((h * m)/z) + csy)
Now, I got the idea of making yet another camera object, one for the z axis, and the other for everything else. But I'm not sure that would work and even if it did I think it would be somewhat redundant, unpractical and it would make the processor pretty angry.
And that's why I'm here, Does anybody know a better way to do this?
Thanks in advance!
I also attached the .love file of this; just in case you want to know /exactly/ what I mean. If you want to check exactly why I don't want the camera to be at x=0,y=0; then try it out for yourselves