Page 1 of 2

How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 9:11 am
by adge
So I came across a few pico-8 projects that actually display 3d models and I thought, I want to know how to do that.

First of all which types of 3d techniques are there? No matter which type do they all have to use 3d to 2d projection in order to draw the stuff on the screen? Or is there also "real 3d" that stays 3d? Can somebody explain to me the main types?

My solution would be something like: 3d stuff is handled by the machine and then converted to 2d to draw in on the screen.

Of course I would start with something very simple. A cube or a pyramid with a fixed camera or stuff like that. So I would convert the 5 points in the 3d space to a 2d space and then connect them by a triangle drawing function and the bottom points through a square drawing function.

I've searched the web but didn't really find something valuable.

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 10:59 am
by ZodaInk
https://www.youtube.com/watch?v=Kdyviza ... bUghwO1RQo

Here are a few videos of basic 3d modelling.
3d engines are not easy, if you're new to programming I would suggest something easier.

There is also LÖVE3D: viewtopic.php?f=5&t=78943

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 11:07 am
by adge
I'm pretty used to math it wouldn't be the problem. I know how to use vectors matrices etc. I know how 3d to 2d projection works I just don't know what techniques are used which are the most performant ones and stuff like that.

I really would start off with just a small pyramid in the center of the screen which you could then rotate with the direction keys around x,y and z axis. And I'm not really new to programming anyways :).

Does this even make sense in Love2D? I would say yes because you can draw lines and simple shapes which would be all you need to represent simple geometric objects in a 2D space. So my question is, why would anyone need access to something complicated like OpenGL if you just need to create code to convert points from a 3D space to a 2D space. I think this can surely be done with Love and Lua. At least for simple objects. But when do you need something more down to the hardware?

Thanks for the link. Its a good start.

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 11:48 am
by Davidobot
Here is an old abandoned not finished project of mine - Lovecraft.
Use the mouse to look around and the standard FPS controls to navigate (Q and E to ascend/descend). You can also press the ~/` button to bring up the debug menu. Also, you can press tab to release the mouse.
Feel free to look around the code. You can turn textures on/off as well as edges and faces in code/misc.lua in lines 23-27.
This should give you an idea how to do 3D.

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 12:36 pm
by adge
Thank you very much! This will really get me started. Works very well!

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 12:47 pm
by Davidobot
adge wrote:Thank you very much! This will really get me started. Works very well!
Glad I could help. I would love to see what you could make of it. :awesome:

Re: How to represent 3d objects in 2d

Posted: Wed Apr 20, 2016 12:57 pm
by adge
Probably not much at first. Will take me some time to get into it. I will upload it if I managed to create some "interesting artful" stuff :D

Re: How to represent 3d objects in 2d

Posted: Mon May 02, 2016 2:02 pm
by adge
If anybody is interested, this is what I came up with for now:

viewtopic.php?f=5&t=82207

Its just simple 3d to 2d projection. There is now camera view or stuff like that. I still need to implement that. I want the view to be adjustable and the object to be rotatable on its own not affecting the camera view. I took a look at LoveCraft but seemed a bit too overwhelming at first. Have to dig more into it.

Re: How to represent 3d objects in 2d

Posted: Mon May 02, 2016 7:52 pm
by Davidobot
adge wrote:..
Dude, I'm like always on the forum, so if you have any questions, don't be shy and ask.

Re: How to represent 3d objects in 2d

Posted: Mon May 02, 2016 11:17 pm
by adge
Ok so I got 3D to 2D projection and some basic rotations. Translation isn't that hard at all. Just add a number to the direction you want to move the object to all vertices.
Should I maybe use matrices? Are they faster? Add lighting. That would be cool. But that exceeds my knowledge. I would use normals for every face and the more the normal and the lightning vector are facing each other the brighter the face will be drawn.
How are faces done? Just draw a polygon or rectangle with the nodes positions?