Animating 3d models in DarkGDK using dbAppendObject

Been watching 3d Animation tutorials lately but I’ve never really found a tutorial or detailed example for that matter that actually teaches how to animate 3d models in DarkGDK in a less unclear way. And so I’m sharing this example in hope that it will be used by some computer enthusiast out there like myself as a starting point in creating their very own 3d computer game.

I have used the Babe model in this example. Babe model is a Dark Matter Model that is accesible by default when you install DarkGDK and is located at C:\Program Files\The Game Creators\Dark GDK\Media\Dark Matter Models\People. The controls and actions of our model in this example are illustrated in the following table.

ControlsActions
W,A,S,DMove.x
TabDie.x
QImpact.x
No key PressedIdle.x


Enough said, here’s the code:


  1. // Dark GDK - The Game Creators - www.thegamecreators.com  
  2. // the wizard has created a very simple project that uses Dark GDK  
  3. // it contains the basic code for a GDK application  
  4. // whenever using Dark GDK you must ensure you include the header file  
  5. #include "DarkGDK.h"  
  6. // the main entry point for the application is this function  
  7. void DarkGDK ( void )  
  8. {  
  9. // turn on sync rate and set maximum rate to 30 fps  
  10.  dbSyncOn();  
  11.  dbSyncRate(30);  
  12.   
  13.  //loads our 3d model  
  14.  //we'll be borrowing the Babe DirectX Darkmatter model  
  15.  //it's included in the DarkGdk package located in  
  16.  //C:\Program Files\The Game Creators\Dark GDK\Media\Dark Matter Models\People\Babe  
  17.  //Just copy the contents of the Babe folder to your game project folder  
  18.  dbLoadObject("H-Babe-Idle.x",2);  
  19.  //Idle.x has 25 frames  
  20.  //to find how how many frames there is in a .x animation  
  21.  //Click Start>All Programs>The Game Creators>DarkGDK>Documentation>Information>Type "Frame"   
  22.  //in the Textbox and the command used to determine the number of frames will reveal itself to you.  
  23.  //appends the number of frames of the Move.x animation to the loaded model  
  24.  //Move.x has 25 frames  
  25.  dbAppendObject("H-Babe-Move.x",2,26);  
  26.  //Attack.x has 24 frames  
  27.  //adds the number of frames of Attack.x to the loaded model  
  28.  dbAppendObject("H-Babe-Attack1.x",2,51);  
  29.  //Die.x has 50 frames  
  30.  //adds the number of frames of Die.x to the loaded model  
  31.  dbAppendObject("H-Babe-Die.x",2,76);  
  32.  //Impact.x has 10 frames  
  33.  //adds the number of frames of Impact.x to the loaded model  
  34.  dbAppendObject("H-Babe-Impact.x",2,126);  
  35.  //positions the object in the -y axis cause its a little bit top aligned by default when loaded  
  36.  dbPositionObject(2,0,-1,0);  
  37.   
  38.   
  39.  while (LoopGDK())  
  40.  {  
  41.  //display descriptive text  
  42.  dbSetTextSize(14);  
  43.  dbText(10,0,"WASD-Movement");  
  44.  dbText(10,10,"Spacebar-Attack.x");  
  45.  dbText(10,20,"Tab-Die.x");  
  46.  dbText(10,30,"Q-Impact.x");  
  47.  dbText(10,40,"No key pressed-Idle.x");  
  48.     
  49.   
  50.    
  51.    //if the W or A or S or D or Spacebar or Tab or Q is pressed  
  52.    if ( dbKeyState(17) || dbKeyState(31) ||dbKeyState(32) || dbKeyState(30)||dbKeyState(57) || dbKeyState(15)|| dbKeyState(16))  
  53.    {  
  54.    //stop the presently looping animation  
  55.   dbStopObject(2);  
  56.    //retrieves the object present angle  
  57.    int ObjAngleY=dbObjectAngleY(2);  
  58.    //determines if the object is presently looping  
  59.    int looping=dbObjectLooping(2);  
  60.       //if the key pressed is W  
  61.    if(dbKeyState(17))   
  62.    {   
  63.    //move the object on the -Z axis  
  64.      dbMoveObject(2,-0.05f);  
  65.    //is the object presently not playing?  
  66.    if (looping==0 )  
  67.    {  
  68.    //if yes then execute move.x  
  69.       //move Move.x has 25 frames  
  70.    //the number of frames from the starting frame to the ending frame must be at least 25 frames  
  71.   
  72.     dbLoopObject ( 2,26, 51 );  
  73.    };  
  74.    }  
  75.    //if the key pressed is S  
  76.    if (dbKeyState(31))  
  77.    {  
  78.    //move the object on the Z axis  
  79.     dbMoveObject(2,0.05f);  
  80.    //is the object currently not playing?  
  81.    if (looping==0 )  
  82.    {  
  83.       //if yes then execute move.x  
  84.       //move directx animation has 25 frames  
  85.    //starting frame up to the end frame must be at least 25 frames  
  86.   
  87.     dbLoopObject ( 2,26, 51 );  
  88.   
  89.    };  
  90.    }  
  91.    //if the A key is pressed  
  92.   
  93.    if (dbKeyState(30))  
  94.    {  
  95.   //rotate the object along the Y axis  
  96.   //for instance, if the objects current angle is 275-5  
  97.   //The object will then be rotated 270 degrees which is exactly south  
  98.   //from the user's POV  
  99.   //the dbWrapValue is to ensure that the object rotation will not exceed 360 degrees  
  100.   
  101.     dbYRotateObject(2,dbWrapValue(ObjAngleY-5.0f));  
  102.    }  
  103.   
  104.   //if the D key is pressed  
  105.    if (dbKeyState(32))  
  106.    {  
  107.    
  108.      //rotate the object along the Y axis  
  109.   //for instance, if the objects current angle is 85+5  
  110.   //The object will then be rotated 90 degrees which is exactly north  
  111.   //from the user's POV  
  112.   //the dbWrapValue is to ensure that the object rotation will not exceed 360 degrees  
  113.     dbYRotateObject(2,dbWrapValue(ObjAngleY+5.0f));  
  114.    }  
  115.      //if the space key is pressed  
  116.    if(dbKeyState(57))  
  117.    {  
  118.   //is the object currently not playing?  
  119.    if (looping==0 )  
  120.    {  
  121.    //if yes then execute Attack.x  
  122.    //Attack.x has 24 frames so from the starting to ending frames  
  123.    //must be at least 24 frames  
  124.     dbLoopObject ( 2,51,77 );  
  125.   
  126.   
  127.    };  
  128.    }  
  129.    //if the Tab key is pressed  
  130.    if(dbKeyState(15))  
  131.    {  
  132.    //is the object currently not playing?  
  133.    if (looping==0 )  
  134.    {  
  135.    //if yes then execute Die.x  
  136.    //Die.x has 50 frames so from the starting to ending frames  
  137.    //must be at least 50 frames  
  138.     dbLoopObject ( 2,78,127 );  
  139.   
  140.   
  141.    };  
  142.    }  
  143.        //if the Q key is pressed  
  144.     
  145.    if(dbKeyState(16))  
  146.    {  
  147.   //is the object currently not playing?  
  148.    if (looping==0 )  
  149.    {  
  150.   //if yes then execute Impact.x  
  151.      //Impact.x has 10 frames so from the starting to ending frames  
  152.      //must be at least 10 frames  
  153.     dbLoopObject ( 2,127,137 );  
  154.   
  155.   
  156.    };  
  157.    }  
  158.   
  159.   
  160.    }  
  161.   else  
  162.   //if no key is pressed  
  163.   //execute Idle.x  
  164.   //Idle.x has 25 frames so from the starting to the ending frames miust be at least 25 frames  
  165.   {  
  166.    dbLoopObject(2,1,25);  
  167.   }  
  168. // update the screen  
  169.   dbSync();  
  170.  }   
  171. //return to windows  
  172. return;  
  173. }  



Another way of animating models is by using the dbShowObject and dbHideObject commands. I'll post an example of that here when I have time. If you want more information on animating darkGDK models or creating games per se, you can visit DarkGDK's official site www.thegamecreators.com

Terminate an Executable Application in Visual Foxpro 9.0 at Run-time by Force

To terminate an executable application in Visual FoxPro 9.0 at run-time, use the RUN and Taskkill command. RUN is a Visual FoxPro command that allows you to execute DOS commands, Taskkill, on the other hand, is DOS command that allows you to terminate an exe applications and processes , similar to using the task manager. For details on using the taskkill command, follow these steps:

1. Click Start>Run>Type CMD> then press enter.

2. In the command prompt, type TASKKILL/?.

Using Run and Taskkill to terminate an executable application at run-time is essential especially if you have hidden the Visual FoxPro 9 IDE using the _SCREEN.VISIBLE command and your form just freezes when you click the Exit button, even though you have attached a THISFORM.RELEASE or whatever code to it. To see RUN and TASKKILL in action, follow these steps:


1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.

2. Close the Task Pane Manager window.


3. Let’s make a form by typing CREA FORM in the command window and pressing enter.

Note: If the command window is hidden, just press CTRL + F2 to show it.

4. Add two buttons to your form, Refer to the following screenshot for control names and values:




5. Double-click the Terminate Ms-Word button, enter the following codes:

  1. private anyvariable  
  2. anyvariable=MESSAGEBOX(“Are you sure you want to terminate Ms-Word?”,4+32)  
  3. if anyvariable=6  
  4. RUN "Taskkill /f /im winword.exe”  
  5. ENDIF  


Your code window should now look like this:



6. Double-click the Terminate Visual FoxPro button, enter the following codes:
  1. private anyvariable  
  2. anyvariable=MESSAGEBOX(“Are you sure you want to terminate Ms-Word?”,4+32)  
  3. if anyvariable=6  
  4. RUN "Taskkill /f /im VFP9.exe”  
  5. ENDIF  
Your code window should now look like this:


7. Press CTRL + F3 to test your application.

8. Before Clicking the Terminate Ms-Word button, ensure that Ms-word is activated.

9. Try clicking the Terminate Visual FoxPro button and see what happens. And that’s all :)

Retrieve values from another form in Visual FoxPro 9.0

One of the ways to retrieve values from another form in Visual Foxpro is to use a Form Set. A Form Set (from the name itself) is a set or collection of forms. To create a Form Set, follow these steps:

1. Click Start>All Programs>Visual FoxPro 9.0.
2. Close the Task Pane Manager Window.
3. To create a form, type CREA FORM in the command window, and then press enter.



Note: If the Command Window is not shown, Press CTRL + F2.
4. A new form will now come into view.



5. To create a form set, click Form>Create Form Set.




Although nothing appear to happen when you click the Create Form Set Submenu but essentially a new submenu will be enabled, the Add New Form submenu.

6. To add a form to your Form Set, Click Form>Add New Form.



A new form named form2 will now be added to your Form Set. If you add another form, that form will be named form3 and so on. Repeat the step no. 6 to add one more form to your form set. Our form set will now have 3 forms named form1, form2, and form3.




7. For the sake of example, let’s make an application that will allow us to enter our first name in the first form, last name in the second form, and display our first name and last name in the last form. We also want to display just the main form when our application is first executed and hide the unneeded forms.

8. If we click the Run icon or press control + E now. you’ll noticed that all forms are displayed at once.




8. Click all the close button of all the opened form to go back to the design view. To hide Form2 and Form3 when the application is first executed, double Click Form1, in the Init procedure, enter the following:
  1. *hides the second form  
  2. Thisformset.Form2.Hide ()  
  3. *hides the third form  
  4. Thisformset.Form3.Hide ()  


The code window will now look like this:




9. While still in the code window of Form1, Select the Unload event.

Enter the following code:

  1. *Closes all the forms in the formset  
  2.  RELEASE Thisformset  


The code window will now look like this:



10. Click the close button of the code window to save all codes that we have entered so far in form1.

11. Add a Label, a textbox and a button to form1, refer to the following screenshot for control property values:




12. What we aim to do here is if click the next button, form1 will be hidden and form2 will appear. To be able to do that, double click the Next button in form1 and enter the following codes:

  1. *Hides form1  
  2. Thisformset.Form1.Hide()  
  3. *Show form2  
  4. Thisformset.Form2.Show()  

The code window will now look like this:



Click the close button of the code window to save the codes that we have entered in Command1.

13. Add a Label, a textbox and two buttons to form2, refer to the following screenshot for control property values:



14. What we intend to do here is if we click the Prev Button, Form2 will be hidden and Form1 will be shown. If we click the Next Form3 will be shown and Form2 will be hidden.

15. Double click the Prev button then enter the following codes:
  1. *Shows form1  
  2. Thisformset.form1.Show()  
  3. *Hides form2  
  4. Thisformset.form2.Hide()  

Your code window will now look like this:




Click the close of the code window to save your codes

16. Double click the next button in form2 then enter the following codes:
  1. *Hides form2  
  2. Thisformset.form2.Hide()  
  3. *Shows form3  
  4. Thisformset.form3.Show()  

Your code window will now look like this:



Click the close of the code window to save your codes

17. Add four labels to form3. Refer to the following screenshot for control property values:



18. What we intend to do here is if Form3 is loaded, all the values from the previous will be displayed on their respective controls. Double-click form3. Select the Activate procedure then enter the following codes:
  1. *retrieves the value of the textbox in form1 and  
  2. *display it in the our label in form3  
  3. Thisformset.Form3.Label2.Caption=Thisformset.Form1.text1.value  
  4. *retrieves the value of the textbox in form2 and  
  5. *display it in our label in form3  
  6. Thisformset.Form3.Label4.Caption=Thisformset.Form2.text1.value  

Your code window will now look like this:



19. Click the close button of the code window to save your codes. Let’s take a look to all our forms once more time.



20. Click the run icon or press Ctrl + E to test your Form Set.

21. Try entering your first name on form1>Next. Your Last name on Form2>Next. Your first name and last name should now appear on form3.

Symet BEAM Robot

Time for some break in programming and delve into the exciting world of robotics. Symet, FYI , is an intelligent agent that can sense it’s environment through the solar cell and perform an action (e.i. tweaks or rotates) the moment it senses heat. A perfect example of a simple AI robot. Here is a mobile video taken by Christine (one of my apprentice LOL) showing Symet at work. This was edited using PowerDirector( A rich-featured video editing software by Cyberlink) which is available for download at www.cyberlink.com. The title and PIP Templates were downloaded from directorzone.cyberlink.com. The Kinetic Typography was made using Microsoft PowerPoint.