Shop OBEX P1 Docs P2 Docs Learn Events
3d graphic matrix in spin — Parallax Forums

3d graphic matrix in spin

fishfish Posts: 55
edited 2008-01-17 07:25 in Propeller 1
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)?

thanks
-fish


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

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2008-01-16 18:16
    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[noparse][[/noparse]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?
  • hippyhippy Posts: 1,981
    edited 2008-01-16 18:43
    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[noparse][[/noparse] index(X,Y,Z) ] := var

    var := array[noparse][[/noparse] index(X,Y,Z) ]
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-01-16 18:55
    @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?
  • VIRANDVIRAND Posts: 656
    edited 2008-01-16 20:28
    This primitive but effective method of 3D graphics buffer projection may be awesome if developed on a Propeller:
    holodeck.virand.com
    There is a 3D memory mapping Math page on the site.
  • fishfish Posts: 55
    edited 2008-01-16 20:35
    Hi,
    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.

    -fish

    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 [noparse]:)[/noparse]

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

    Post Edited (fish) : 1/16/2008 11:18:10 PM GMT
  • VIRANDVIRAND Posts: 656
    edited 2008-01-16 22:55
    Did you check the Hydra forum?
    I'm trying to make a raycaster and another person made a retro 3D monster maze game.
  • mparkmpark Posts: 1,305
    edited 2008-01-17 07:25
    There's also a Battlezone clone (3D but wireframe).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Michael Park

    PS, BTW, and FYI:
    To search the forum, use search.parallax.com (do not use the Search button).
    Check out the Propeller Wiki: propeller.wikispaces.com/
Sign In or Register to comment.