Cubix

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

A long time ago I wrote a Rubik's cube 3D demo using CDFJ format. I was endlessly frustrated with my hand-drawn attempts to represent the cube rotating at various angles. It occurred to me that a 3D engine should be able to draw a 3D Rubik's cube - and so that's what I'm playing with at the moment. The thing is, to draw a cube correctly - the objects (26 or 27 little cubes) need to be drawn in the correct z-depth order. Currently the 3D engine does not sort the 'objects', and so it's a royal mess.

crt_composite_sentinel.elf_20240726_222150.jpg

So this is a good test-bed to get the sorting functional.

I also "found" the cause of previous crashes - it's something to do with "big lines" in the 3D calculations. I limited the lines to 100 pixels just as a diagnostic. Now I don't get the crashes, but I do get the really odd/awful patches of solid colours on the screen; indicative of bad lines. But at least it no longer crashes. Debugging is difficult at the moment because I'm not setup properly with Gopher to examine variables or do profiling. All of this is old-skool with a value or two printed on the screen.

So, next step required for the cubes - a depth-sort of the transformed object position and then to render in that order (painter's algorithm). We should see a dramatic improvement in visuals when I get that up and running in a day or two.

Andrew Davie

#1
Well, here's where I'll leave it for today. I got the sorting of objects working OK which makes a big difference. Some real oddities in the rendering, though, that I just don't quite understand yet. I may have an axis back to front or something like that. It's getting there.



Andrew Davie

#2
The backface dotproduct was arse-backwards and up to now I've been displaying backfaces of objects -- that is, faces pointing away from the camera. Go figure!  So if you think of the reverse faces of a cube, that's what we're seeing in the previous post.  I'm not quite fixed yet, but flipping that backface makes things look a whole lot better.


Andrew Davie

Well, proof of concept.  It shows how the cube would look at various sizes - near has too many issues with the lores/hires areas, but mid-distance it all looks rather good. I think a workable 3D Rubik's cube would be perfectly functional/possible. The frame rate is a bit slow, though - 27 cubes being rendered ehre and all those 3D calculations are a killer.


Andrew Davie

Here's an updated video. It's still slow, but looking nice.
The face colours change when I press the button. Only the visible faces are coloured - and this helps the black borders between be a bit more defined. The real big task coming up is how to rotate the various groupings/faces together. It shoud be simple-ish, but I'm finding combined rotations and offsets hard to get my head around.


Andrew Davie

In the end, it wasn't the dot-product that was backwards; it was the orientation of the faces of the cube data. Instead of defining in counter-clockwise order, I had defined the cube faces in clockwise order. I blame chatGPT for that.

Andrew Davie

#6

Here's an update - about 2x speed improvement. I'm struggling to find any more speed, though.
This one is fairly stable (no overtimes).  There's a binary at the bototm of this post. Will run on Gopher and PlusCart. Stella - not yet - but coming soon!!

The cube faces just change colour randomly ever now and then. Just to show the colour "sticks" and it's not purely randomly generated during draw.  UP/DOWN to zoom in and out.


Andrew Davie

I got the face rotations working!


This was the bit that I said last video would be "daunting".  In this video - which is obviously very rough - I have the first working version of "face rotation". That is, spinning parts of the cube just like you would a real cube. I'm just manually cycling through the 9 possible rotation 'planes' here and looking at what glitches show up. And yes. there are a few - particularly caused by the draw ordering and overlap. Nonetheless, it's a big step forward for this effort, and I'm very pleased with how it's going. Except for the speed.

Note, there's a bit of a "scramble" every time I change which face is rotating - that's due to the sort order being screwed up and not updated for a short while. As always, these videos are just a video diary of work in progress, so these things are to be expected.  Next major step will be to actually reposition the cubes as the rotation completes - and then we'll have a fully functional cube.

Andrew Davie

A more stationary version - gameplay will be more like this with the cube in a fixed orientation...