Animating 3d models in DarkGDK using dbAppendObject

Posted by Rey Dacoco in

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:


// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 30 fps
 dbSyncOn();
 dbSyncRate(30);

 //loads our 3d model
 //we'll be borrowing the Babe DirectX Darkmatter model
 //it's included in the DarkGdk package located in
 //C:\Program Files\The Game Creators\Dark GDK\Media\Dark Matter Models\People\Babe
 //Just copy the contents of the Babe folder to your game project folder
 dbLoadObject("H-Babe-Idle.x",2);
 //Idle.x has 25 frames
 //to find how how many frames there is in a .x animation
 //Click Start>All Programs>The Game Creators>DarkGDK>Documentation>Information>Type "Frame" 
 //in the Textbox and the command used to determine the number of frames will reveal itself to you.
 //appends the number of frames of the Move.x animation to the loaded model
 //Move.x has 25 frames
 dbAppendObject("H-Babe-Move.x",2,26);
 //Attack.x has 24 frames
 //adds the number of frames of Attack.x to the loaded model
 dbAppendObject("H-Babe-Attack1.x",2,51);
 //Die.x has 50 frames
 //adds the number of frames of Die.x to the loaded model
 dbAppendObject("H-Babe-Die.x",2,76);
 //Impact.x has 10 frames
 //adds the number of frames of Impact.x to the loaded model
 dbAppendObject("H-Babe-Impact.x",2,126);
 //positions the object in the -y axis cause its a little bit top aligned by default when loaded
 dbPositionObject(2,0,-1,0);


 while (LoopGDK())
 {
 //display descriptive text
 dbSetTextSize(14);
 dbText(10,0,"WASD-Movement");
 dbText(10,10,"Spacebar-Attack.x");
 dbText(10,20,"Tab-Die.x");
 dbText(10,30,"Q-Impact.x");
 dbText(10,40,"No key pressed-Idle.x");
  

 
   //if the W or A or S or D or Spacebar or Tab or Q is pressed
   if ( dbKeyState(17) || dbKeyState(31) ||dbKeyState(32) || dbKeyState(30)||dbKeyState(57) || dbKeyState(15)|| dbKeyState(16))
   {
   //stop the presently looping animation
  dbStopObject(2);
   //retrieves the object present angle
   int ObjAngleY=dbObjectAngleY(2);
   //determines if the object is presently looping
   int looping=dbObjectLooping(2);
      //if the key pressed is W
   if(dbKeyState(17)) 
   { 
   //move the object on the -Z axis
     dbMoveObject(2,-0.05f);
   //is the object presently not playing?
   if (looping==0 )
   {
   //if yes then execute move.x
      //move Move.x has 25 frames
   //the number of frames from the starting frame to the ending frame must be at least 25 frames

    dbLoopObject ( 2,26, 51 );
   };
   }
   //if the key pressed is S
   if (dbKeyState(31))
   {
   //move the object on the Z axis
    dbMoveObject(2,0.05f);
   //is the object currently not playing?
   if (looping==0 )
   {
      //if yes then execute move.x
      //move directx animation has 25 frames
   //starting frame up to the end frame must be at least 25 frames

    dbLoopObject ( 2,26, 51 );

   };
   }
   //if the A key is pressed

   if (dbKeyState(30))
   {
  //rotate the object along the Y axis
  //for instance, if the objects current angle is 275-5
  //The object will then be rotated 270 degrees which is exactly south
  //from the user's POV
  //the dbWrapValue is to ensure that the object rotation will not exceed 360 degrees

    dbYRotateObject(2,dbWrapValue(ObjAngleY-5.0f));
   }

  //if the D key is pressed
   if (dbKeyState(32))
   {
 
     //rotate the object along the Y axis
  //for instance, if the objects current angle is 85+5
  //The object will then be rotated 90 degrees which is exactly north
  //from the user's POV
  //the dbWrapValue is to ensure that the object rotation will not exceed 360 degrees
    dbYRotateObject(2,dbWrapValue(ObjAngleY+5.0f));
   }
     //if the space key is pressed
   if(dbKeyState(57))
   {
  //is the object currently not playing?
   if (looping==0 )
   {
   //if yes then execute Attack.x
   //Attack.x has 24 frames so from the starting to ending frames
   //must be at least 24 frames
    dbLoopObject ( 2,51,77 );


   };
   }
   //if the Tab key is pressed
   if(dbKeyState(15))
   {
   //is the object currently not playing?
   if (looping==0 )
   {
   //if yes then execute Die.x
   //Die.x has 50 frames so from the starting to ending frames
   //must be at least 50 frames
    dbLoopObject ( 2,78,127 );


   };
   }
       //if the Q key is pressed
  
   if(dbKeyState(16))
   {
  //is the object currently not playing?
   if (looping==0 )
   {
  //if yes then execute Impact.x
     //Impact.x has 10 frames so from the starting to ending frames
     //must be at least 10 frames
    dbLoopObject ( 2,127,137 );


   };
   }


   }
  else
  //if no key is pressed
  //execute Idle.x
  //Idle.x has 25 frames so from the starting to the ending frames miust be at least 25 frames
  {
   dbLoopObject(2,1,25);
  }
// update the screen
  dbSync();
 } 
//return to windows
return;
}




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

0 comments

Post a Comment

Contributor

My photo
I am just a simple man with a simple mind. And this is my simple blog. New Posts will be available soon. Enjoy reading and never stop learning:)

Total Pageviews

Link List

Archives

Got questions? You can reach me here: