View Full Version : 3d graphic matrix in spin

01-17-2008, 01:00 AM
Hi everyone,
I did a forum search on the subject of 3D matrices without luck.
I know that multi-dimensional arrays are not allowed in Spin,
so has anybody worked around this constraint to implement a rotation matrix (or translation matrix etc)?


". . . the fog is rising" ~ Emily Dickinson

Ken Peterson
01-17-2008, 01:16 AM
Although multi-dimensional arrays may not be supported by SPIN directly, you may be able to implement a 3D array with code. What dimensions do you need for the array? Is it a fixed size?

One possible way: Combine all three indices into one index. Lowest 4 bits are X, next 4 bits are Y, next 4 bits are Z. To address an array element, do the following:

array[Z << 8 | Y << 4 | X] := some value

If you don't need 16 in each direction, you can change the number of bits. Each dimension would have to be a power of 2. Not all of the dimensions need to be the same size either.

Would your transform matrix be 3 x 3 x 3? If that is the case, you only need two bits per direction.


The more I know, the more I know I don't know.· Is this what they call Wisdom?

01-17-2008, 01:43 AM
And of course that "complicated to remember and get right when typing" index can be put into a method so all that's then needed is ...

array[ index(X,Y,Z) ] := var

var := array[ index(X,Y,Z) ]

Ken Peterson
01-17-2008, 01:55 AM
@hippy: Easier to read, but with a performance hit. If you're doing 3D graphics, I imagine efficiency will be important. For less performance-critical applications, using the method is a good idea.

This would be a good application for a macro.


The more I know, the more I know I don't know.· Is this what they call Wisdom?

01-17-2008, 03:28 AM
This primitive but effective method of 3D graphics buffer projection may be awesome if developed on a Propeller:
holodeck.virand.com (http://holodeck.virand.com)
There is a 3D memory mapping Math page on the site.

01-17-2008, 03:35 AM
Thanks for the input guys, and I will try what you have suggested.
I thought for sure someone had already done this.
I guess most folks who do Prop 3d graphics output composite vid and use Graphics object's methods for 3D math (or something like that, I can't recall exactly the objects used) or maybe they do the calculations without the matrices?
Anyway, my display is an OLED, so it looks like I will need to roll my own 3D engine of sorts.

I will give it a go.
thanks again.


P.S. If anyone has implemented a simple (not coupled to·an output device)·3d engine for the prop, I would be interested in your tricks/traps. thx!

Virand: very interesting, and doubles as a cocktail shaker :)

". . . the fog is rising" ~ Emily Dickinson

Post Edited (fish) : 1/16/2008 11:18:10 PM GMT

01-17-2008, 05:55 AM
Did you check the Hydra forum?
I'm trying to make a raycaster and another person made a retro 3D monster maze game.

01-17-2008, 02:25 PM
There's also a Battlezone clone (3D but wireframe).

Michael Park

PS, BTW, and FYI:
To search the forum, use search.parallax.com (http://search.parallax.com) (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/ (http://propeller.wikispaces.com/)