This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xenthera's profile picture

The Road To 3D Programming. (From Scratch That Is)

Started by Xenthera, 19 July 2013 - 06:45 PM
Xenthera #1
Posted 19 July 2013 - 08:45 PM
I'm very interested in learning how 3D programming is done. However, I wouldn't know where to start. I know it involves 3D matrices and stuff. The problem is, I have no idea what those are. I'm not expecting someone to sit here and explain how to program Crysis 3 or anything (good god), rather, I simply want to be pushed in the right direction to the stuff I have to learn to accomplish some 3d stuff. Also, any perquisites I may need to have.

I'd like to at least accomplish something like Nitro did. (link)

Thanks if you can help me out
Yevano #2
Posted 19 July 2013 - 10:57 PM
If you just want to draw 3D polygons onto the screen, you can start with these 2 steps. (from personal experience)

1. Convert (project) your 3D triangle (world) vertices to 2D (projected) points.
My implementation uses atan2 to convert the components on the XY and YZ axes (where X is left to right, Y is backward to forward, and Z is down to up) to bearing and elevation angles. Then I did some simple multiplication to get the correct range on the angles given a certain FOV and screen size.

2. Rasterize the triangles.
Once you have your 2D vertices for drawing, it's just a matter of using a triangle filling algorithm to draw your shapes. I used one which draws top-flat and bottom-flat triangles which make up the original triangle. I won't go into exactly how to do it as there are many different algorithms you can use.

There's more than this to actually keep the triangles from drawing in the wrong order (depth buffering I think). And there's still things like texture mapping to consider. The above two steps will get you started, however.
GravityScore #3
Posted 20 July 2013 - 06:28 AM
Well, it depends on how complex you want the 3D programming to be. I have no idea about how to use projection/rotation/translation matrices to convert 3D points into 2D ones, but I found a really cool simple article on using ray casting to do pseudo 3D (it's the same method GopherAlt used to make his wolfenstien-style 3D graphics for CC): http://www.permadi.com/tutorial/raycast/index.html

It's pseudo 3D because its only possible to have walls 90 degrees to the ground. The article explains it very well, and goes into lighting, into texture mapping, etc…