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

(kind of) 3D in CC

Started by billysback, 18 December 2012 - 04:38 AM
billysback #1
Posted 18 December 2012 - 05:38 AM
Multiple times have I - and I'm sure others - have tried to emulate basic level 3D graphics on CC.
There was usually one fatal flaw, which was surprisingly (in my case) not memory issues but was instead graphical limitations, there is only so much you can do with 50x18 pixels even with colour.

This project is my beginnings of an attempt at a extremely simple 3D game engine; note that I have little idea of what maths goes in to true 3D programming and that this code is not only not very functional but is also temporary, it is a test.

Currently it works by creating 2D (sort of 3D) panels in a 3D world using x, y, z, width, height, depth then calculates the distance between the world viewpoint (camera) and panel and scales the panel accordingly.
Before drawing it then decides if the camera can actually see the object based on it's base difference between the cameras coordinates and the objects coordinates, comparing against a camera's "rotation".

I have yet to implement distance ordering so that it draws sprites in distance order, furthest to nearest.

Currently this all works, with sprites and camera movement but sprites not being drawn when you go past them doesn't work along with a lot of things, it's very buggy and unfinished either way, here is the code:
http://pastebin.com/a6n055BY

I posted this because I lost enthusiasm in the project and was hoping not only could people give me a boost in whatever form (even basic interest) that would push me to improve it but also to help me improve it, either by taking the code (which I will update as best as possible) and modifying it or just suggesting improvements.

Please remember this is a huge test and may never properly work, I just want to be sure that it will never work instead of presuming it will never work.

So tell me what you think please :P/>
Orwell #2
Posted 18 December 2012 - 05:49 AM
This is quite nice, but if you're really planning on taking this further, you'd might have made some wrong starts. I had to make a 3D rendering engine in C++ last year for an assignment and I Think that the greatest problem is that you don't seem to handle sprites as a 3D object? Your best bet is to work on proper 3D -> 2D projection first (quite hard with the resolution you have), second you'd think about z-buffering for depth ordering and at last you'd handle ambient, diffuse and specular light and eventually shading. I believe the greatest limitation isn't the screen resolution but the 16 colors. For example, if you draw a gray cube, each side will be a different tint of gray and we need that to create the illusion of 3D. That's practically impossible in CC.
Learning_inpaired #3
Posted 20 December 2012 - 03:20 PM
what if you were to use a massive monitor and spred out the pixels thro out the screen?
also maby make a new API for this to make things easer, and what about multi-tasking?
Orwell #4
Posted 20 December 2012 - 03:42 PM
what if you were to use a massive monitor and spred out the pixels thro out the screen?
also maby make a new API for this to make things easer, and what about multi-tasking?
Multitasking isn't really an issue here, when it comes to the rendering it isn't even needed. Using 6x8 monitors with a scale of 0.5 would indeed make things a lot better, but you'd still have the problem of having only 16 colors. Shading is just almost impossible (I think the best bet would be white/light gray/dark gray/black, but even then..).
PixelToast #5
Posted 21 December 2012 - 03:08 AM
if you want i can give you the steps and code for my 512x512 LCD screen with CCLights
that would allow you to make alot bigger 3d models
billysback #6
Posted 21 December 2012 - 05:02 AM
if you want i can give you the steps and code for my 512x512 LCD screen with CCLights
that would allow you to make a lot bigger 3d models
No thanks, I want to use this with default CC (it's meant to be a challenge)

This is quite nice, but if you're really planning on taking this further, you'd might have made some wrong starts. I had to make a 3D rendering engine in C++ last year for an assignment and I Think that the greatest problem is that you don't seem to handle sprites as a 3D object? Your best bet is to work on proper 3D -> 2D projection first (quite hard with the resolution you have), second you'd think about z-buffering for depth ordering and at last you'd handle ambient, diffuse and specular light and eventually shading. I believe the greatest limitation isn't the screen resolution but the 16 colors. For example, if you draw a gray cube, each side will be a different tint of gray and we need that to create the illusion of 3D. That's practically impossible in CC.
I understand the basics (at least what I would infer as the basics) of 3D games, how they work and what they require but I do not understand the maths behind getting the rotations, angles and colours of different polygons making up the models on the screen, I have thought about it in my head but they best I believe I could do would be to create a cube filled game.

I understand that I am using 2D sprites with a 3D co-ordinate but I don't think that expanding the 3D beyond this would work, in order for 3D to look realistic when using 3D models you must apply light and shading, the limitations of the colours mean that you cannot do this properly.

Although the name of the program may be a give away it may be less obvious to other:
I am trying to achieve a CC clone of a game called "Cubefield", there may be many other alternatives (in fact I can think of older alternatives which are much better than it) but it seems to be one of the most popular ones, the game mechanics are extremely simple and it is very simple to play. I believe that if I get this working I could make a decent enough clone of it, and even with the colours I have available to me I could create a full clone of that game.
Oct125 #7
Posted 23 December 2012 - 11:04 AM
Well i tested and i think that's good! The project are limited by CC limits… right?