"3d" with matrices
  • DrewDrew January 2008
    In response to a request in another thread, here's my early attempt at doing software 3d with HGE :) (perverse considering HGE is already 2d in 3d ^^)

    image

    This was an exercise in teaching myself the maths I should have picked up at uni but never really got to grips with at the time. Apologies for the lack of comments, commented out blocks & generally rubbish design.

    Classes worth a mention:
    AdvancedSprite - this is where the matrix math & rendering happens. Not the best place for it really - in later attempts this was moved out to its own utility class. There are also a few matrix math libraries around, it may be worth considering one of these :)

    ObjectManager - Update() does some matrix manipulation to each sprite before rendering. Objects store the state of each sprite, data from which is passed to AdvancedSprite. Rather than keep a bunch of pointers to sprites around all the time I use a single sprite which is rendered multiple times & update it with each object's data. The idea being objects take up less space than full blown sprites, but there is a cost associated with initialising sprites on a per object basis. I haven't noticed a significant performance hit with this approach.

    SortingAlgorithms - This is used to sort the rendering order of the sprites by Z depth. only std::sort at the moment but the design allows multiple sort algorithms to be plugged in & swapped between.

    TextureManager: Virtually pointless at present, just saves me having to type HTEXTURE manually :)

    last but not least (and not actually a class), MMGR. Great little memory manager from Fluid Studios

    WinMain contains the setup code for the various objects in the scene.

    Bugs:
    - Zooming doesn't work for negative values of Z.
    - Some of the marines at the back aren't spaced evenly in terms of Z depth, but they should be.

    There's plenty of improvements to make to this project, but it's a start - I suspect there are subtle errors in the maths so if you spot anything let me know.

    and finally..
    Download

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Who's Online (0)