DaBooda Turbo v1.4 - Tutorial D
You Spin Me Right Round! (Vertex Groups)
Andrew "DaBooda" Stickney
August 10, 2004

Say hello to a long hour grueling hell to program.  Here is DBVertex, the first stand alone class in this engine, and the sole reason why this Dll has lost its compatibility.  Was it worth it, yes it was, this class lets you take a group of sprites and treat them as if they where one three dimensional entity.  I actually got the idea for this class from playing AfterBurner2, for anyone who has played this, they will remember the II at the begining was a collection of sprites that would rotate... pretty neat I think.  Well this class will let you do this and more, this class will make that boring game into something interesting.

I will admit that this class has a high learning curve, but anybody with any 3d experience will find it pretty simple.  Lets break this thing down, baby!


The Stand Alone Ranger!

Those titles just keep getting better....not.  Well what this means is this class is a stand alone, which means you have to create your own instances of it.  I did this because you will most likely be using more than one at a time for really complex mechanics, well now you can.  You create an instance of this class just like you do with the main core... like this:

'The vertex group, it is stand alone
Dim VGroup As New DBVertexGroup
'Destroy VGroup
Set VGroup = Nothing

Its this easy, and this is truly the easy part.  You really don't have to destroy the instance at the end of the program but it is good practice.


Adding The Vertexes, Drives Me Mad!

For this class to work, it must have vertexes to manipulate, well lets break down the init class.

'Initialize VGroup
With VGroup
    'Create the 12 Vertices
    .VertexAdd -48, -48, 0
    .VertexAdd -16, -48, 0
    .VertexAdd 16, -48, 0
    .VertexAdd 48, -48, 0
    .VertexAdd -48, -16, 0
    .VertexAdd -16, -16, 0
    .VertexAdd 16, -16, 0
    .VertexAdd 48, -16, 0
    .VertexAdd -16, 16, 0
    .VertexAdd 16, 16, 0
    .VertexAdd -16, 48, 0
    .VertexAdd 16, 49, 0

Its that simple this is how you add vertices to the class.  The coordinates are set up on the classic Cartesian coordinate system.

    'set the origin to be the middle of the screen
    .VertexSetOrigin 320, 240

Now for 3D to truly work, it has to have a center to rotate on, well this class considers the center 0,0,0... well we do not want the entity to be at the upper left portion of the screen.  So set this to tell it where you wish to view it.  This can be set at any time you wish, but perspective and stuff does not change with this.

    'Attach Sprite List
    .SpriteAttachList 1

Ok, this is important for this is what determines the sprites for each vertex.  You basically give it a start number and it attaches each consecutive sprite to the vertexes, how many sprites are attached is determined by the number of vertices, so plan ahead.  Of course you do not have to do this, you can just attach a few by using the SpriteAttach command.

    'set up fog
    .SpriteSetUpFog 0, -250, False, False, False, True
End With

This is what gives it that neat fading effect as it moves away from you.  Set this to anything you wish the booleans are for what values apply to the sprites.


There Is An Order To The Vertex Universe...

I am going to break down the Manipulate loop, this is what I call it.  Most of these commands should be done in this order, for it is essential for it to look right.  This is where you can become easily confused.  I left this open so you can pick and choose what you wish to do.

'update vgroup
    With VGroup
        .VertexReset

This is perhaps the most important command within the vertex group and must be done first.  What it does is convert all the vertices to temp variables so you can then manipulate them without changing the original structure.  This command also puts all the sprites back into the original order, if you had used a SortZ command.  The vertex class does manualy move all sprites in its list, so it is important to use a VertexReset command if you wish to kill the group.

        .VertexScale ScaleRate
        .VertexRotateZ ZAngle
        .VertexRotateX XAngle
        .VertexRotateY YAngle
        .VertexTranslate XTrans, YTrans, ZTrans

These are your translation commands for they do what they look like they do.  You can put these in any order you wish to do different things... its up to you.  One thing to keep in mind the ScaleRate just changes the distance between vertices and does not effect the fog or scale of the sprites, believe it or not I have no idea why that does that... maybe someone can break down the code and find out..(hint)

        .VertexPerspective

This adds the 1:3 aspect ration to the vertices.  This is what gives it depth, I would only do this after translating is done.  Or you will have odd mishappen shapes.

        .SpriteUpdateScale

This command is what gives the sprites a larger appearence when moving towards you on the screen and makes them smaller as they go farther.  Its a pretty nice command and adds to the depth.

        .SpriteUpdateFog

This applies the fog settings to the sprites.  What this sets was determined by you earlier in the vertex init routine.

        .SpriteUpdateXY
    End With

Your sprites will stay in one place unless you use this command, for they will not be updated to the vertices.  Pretty important command.

    'do specular from counters before sprites are sorted
    For I = 1 To 12
        Engine.DBSprite.QMSetSpecular I, Engine.DBCounter.ReturnPositiveInteger(I), Engine.DBCounter.ReturnPositiveInteger(I), Engine.DBCounter.ReturnPositiveInteger(I)
    Next I

This is pretty important, for if you wish to manipulate the sprites it is best to do this before the next command, because they will then be out of order and the counters will update the wrong ones.  Just remember to split up the Vertext Manipulate routine like this is you wish to check or manipulate the sprites.  This can be confusing and I hope you understand, but try this, take the above and put it after the next command and see what happens.

    'now we can sort the sprites
    With VGroup
        .SpriteSortZ
    End With

This is what keeps the sprites in front of the other ones that are further away.  This command actually changes the order of the sprites within the sprite class so it is essential to keep this in mind, for if you wish to detach them it is important to do so only after you use a VertexReset and before you use a SpriteSortZ command.  This command I will warn you is very processor intensive so do not use with a large number of sprites.

That is it, this is what has to be done to use the vertex group... I know it seems like a lot of work, but if you think about it, it is very little compared to what the class is doing behind the scenes... This class took forever to get the kinks out and to be honest there might be some more, please let me know.


That is it for this tutorial, I do hope you understand this class, for it will really give your games an edge.. the ideas this class derives for me are endless.  If you have questions, please email me at masterbooda@yahoo.com .  I will answer any question and please experiment with the code, its the only way to learn.