DaBooda Turbo v1.4 - Tutorial D - 2
Poor Man 3D (Vertex Groups)
Andrew "DaBooda" Stickney
August 10, 2004

Hey wait a minute, this is a 2D engine!  And it still is, for this is just a pleasant side effect of the Vertex Class.  There is a Super Nintendo Game called Zelda 3 - A Link To The Past... well during certain parts they use polygon rendering to do the TriForce and such, and I thought it added a very nice element to the game.  So you can blend some 3D into the game, and still keep that 2D element to it.  A good thing about this 3D is that it is strictly math, what that means is if the user can see a sprite, basically anybody able to run this engine, then they can see this 3D.  Another plus to this is believe it or not this is more simple to achieve than the last tutorial, for you don't have to worry about sorting sprites for DirectX8 removes backfaces automatically for you.

Lets look at a few things, and see exactly how this is done.


Constants, A Mans Best Friend...

I meant to point this out in the last tutorial, but forgot, so here it is.  You may have noticed that all the overlays I use for buttons.  Well when dealing with these I decided to use constants to give them a name, this makes working with indexes alot easier.  I know most programmers know about Constants, but I am going to cover it for those who don't.  A constant is basically a variable that well isn't variable.  You are basically telling vb, that hey this name is really this number or value.  For example KeyInput uses constants of the DirectX8 class, but all vb is really concerned with is the numbers they represent.  Trust me a game is going to be way more complicated than these tutorials, so using constants will make programming a lot easier, and do not worry about speed, because once compiled vb will turn everything to numbers anyways.


Polygon, Polygon....

Most do know that a polygon is a multisided object that has more than 2 corners and is enclosed.  Basically when you create a polygon within the Vertex Class all you are doing is declaring what vertices to use for the four corners of the sprite.  To create a polygon you must declare it during every manipulation routine, I would have put something to hold values within the class itself, but it is always changing, and like I said before this is really just a pleasant side effect of the class.

        'Attach all the sprites as polygons to the vertices
        .CreatePolygon 1, 1, 2, 4, 3
        .CreatePolygon 2, 6, 5, 7, 8
        .CreatePolygon 3, 5, 1, 8, 4
        .CreatePolygon 4, 2, 6, 3, 7
        .CreatePolygon 5, 5, 6, 1, 2
        .CreatePolygon 6, 4, 3, 8, 7

You simply declare all the vertices to use for the four corners and what the class does is update the sprites corners to those vertices.  Seeing how this updates the positions to the sprites, then you must have all manipulation done before doing this, basically do this last.  You can also declare whether or not fog will effect the corners, by default this is true.


Back Face and Forth Face...

By default this engine removes back faces, so you must know what it takes to be a back face.  Well for a sprite to be seen its corners must go in a clock wise direction.  So just keep this in mind when creating polygons, make sure the ul, ur, lr, ll.. are all going in a clock wise direction.  If you set it up right initially, whenever the object rotates, the sprites will sort of order themselves.  If you have and object that is concave then you will simply have to find a way to order them yourselves.  One way to do this is maybe create two Vertex Groups have the sprites attach to one, and order them through that one, then create polygons with the other.... this is completely up to you.

You can turn off the Back Face Removing, for the Engine now has the capability to set render states and texture states.  To remove back face culling simply do this:

'Turn off Back Face Culling
Engine.SetRenderState D3DRS_CULLMODE, False

This command will let you set a multitude of different settings to find out more about this and SetTextureStage, consult the DirectX8 SDK... Go ahead and turn off back face removal within the engine and see what happens in this program... kind of wierd, huh...


Old vs. New, Again...

I have mentioned before, that there is a new style of rendering.  Well for CreatePolygon to work, old style must be on, for this is the only style that allows for nonrectangular objects and uneven coloring. 

One more thing to note and that is in this program I used a plain white texture for the polygons, but you can use pictures or patterns, but I wouldn't suggest it.  For this engine uses texture strips, and when they are at certain extents a wierd warped look will occur...  Basically this engine wasn't meant to do 3d, so therefore there is limitations

As for speed, I haven't noticed any difference than if you wanted to display the 6 sprites normally... actually it is a little faster than the last tutorial, for at least it doesn't have to sort sprites..


This wraps up the vertex class and its tutorials, please experiment until you feel comfortable with it.  This class is going to set your game apart from a lot of other vb programs out there, especially the 2D ones.  So use to your full advantage, and feel free to mix and match different combinations of commands for this is truly when the best effects are going to happen.

For anymore questions please email me at masterbooda@yahoo.com ... And please ask me anything...