Ok, after playing around with the GDK and 3D objects and animation, and also the Dark Physics plugin, I noticed that if the model you are using isnt one that you have created yourself, getting information about the limbs, to be able to reference them in your own program can be a painful process...
To that end, I wrote a little piece of code that will simply load a 3D Object, assign it as dbObject 1, display it to the screen(if possible) and iterate thru its limb name's and number's, displaying that information to the screen also.
The Code is very very simple, and also very very inefficent and full of bad programming practices, written only for the a simple purpose, there are probably many better ways to do this, however, the code is heavily commented, from the point of view of explaining each step of what the program is doing...
I have included the Main.cpp file from the project as an attachment to this post, feel free to download it and add it to a project of your own..
The Code is very self-explanatory :
//------------------------------------------------------------------------------------------------------------------------------//
// Dark GDK - The Game Creators - www.thegamecreators.com //
// //
// this little app was coded by Paul Wilson ( a.k.a Mista Wilson ) //
// //
// you may use this code in any way that you see fit and for any purpose, i hope it helps :) //
// if there are any problems or questions, PM me on the TGC forums.. @ Mista Wilson //
// //
// PLEASE NOTE : This app uses the GDK system function "dbChecklist" however, it would not be too difficult to alter this code //
// to manually iterate thru all of the limb on the object one at a time and assign their values to a //
// custom defined array(that is if its possible to even load a model with so many limbs in GDK...) //
// in this case though, GDK is taking care of all the internals :) //
// Depending on how many limbs the object has, and how large it is, the Display may not work correctly //
// however, you can still cycle through the limbs information. //
// I have loaded an object with over 1500 limbs, and while the object itself didnt display, its information was //
// all correct(it was a 3D World Studio game level(.dbo format), and the limb information contained all of //
// the "entity data" including lights and their types etc etc, you could thus use this information to extract //
// entity enformation from your levels and link it to classes within your game engine). //
// //
// EXPANSION : It would be a fairly easy task to expand this program to take the information it is displaying to screen, //
// the Object Limb Information, and save that information to a text file, to review later or print etc //
// All of the limb information is stored in the dbChecklist //
// //
// USAGE : This code will load a single 3D Object onto the screen, and perform a checklist function on that object //
// to determine the maximum amount of, and names of, all the limbs that are a part of the object //
// This information will then be displayed to the screen, and updated via a single iteration with each keypress //
// //
// OBJ_TO_LOAD is the name of the object you wish to load, and must be a GDK compatible object.. ie (.x .3ds .dbo) //
// TEXT_TO_LOAD is the name of the texture that you are loading for this object. (not required) //
// //
// Control the camera using the arrow keys : UP = Forward, DOWN = Back, LEFT = Rotate Left, RIGHT = Rotate Right //
// SHIFT = Move Camera Up, CONTROL = Move Camera Down //
// //
// Camera Movement is only possible while holding down the ENTER key. While the ENTER key is being held, the app //
// enters "Free-Roam" mode and you may move the camera freely. While the ENTER key is NOT being held, the app //
// goes into its "Limb Iteration" mode, this works by cycling through all of the limbs that are part of the object //
// one by one, and displaying to the screen the limb's name and number. Each iteration will display a single limb's //
// name and number, then wait for the user to press any key, before dispalying the next limb's name and number.... //
// //
// //
// //
//------------------------------------------------------------------------------------------------------------------------------//
#include "DarkGDK.h"
// these 2 integers are declared as globals simply because im lazy and didnt want to worry about scopes..
// ( this code was originally longer and had extra functionality)
// declaring variables as global when they arent required to be global is generally bad practice
int itotlimb=0; // hold the total number of limbs of our object as an integer value
int i=0; // simply used to iterate thru loops
// these integers are used for you windows resolution, set to 1024,768,32 as default.. change to suit
int ix=1024; // screen width(ie 800, 1024, 1280)
int iy=768; // screen height(ie 600, 768, 1024)
int ibit=32; // screen colour depth(ie 32bit 16bit)
// these 2 variables are declared here and are self explanatory.. change them to the name of the object
// and texture that you want to load if your object does not require you to manually load the texture
// just comment out the line .... char* TEXT_TO_LOAD = " "; and the line dbLoadImage(TEXT_TO_LOAD,1); further down
char* OBJ_TO_LOAD = "buggy.x"; // example - change between "" to the name and extension of your model
char* TEXT_TO_LOAD = "buggy001.tga"; // example - change between "" to the name and extension of your image
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn the screen on, get ready for some extremely intensive, machine bending 3D calculations.. ;)
dbSyncOn ();
dbSyncRate (60);
dbSetDisplayMode(ix, iy, ibit);
dbSetWindowPosition(((dbScreenWidth()/2)-(ix/2)), ((dbScreenHeight()/2)-(iy/2)));
dbSetWindowOn();
dbText(0,0, "LOADING...");
// these lines are simply "asthetics" ... comment/uncomment and change them to suit your tastes, and make viewing you
// object easier
//dbColorBackdrop( 0 );
//dbMakeLight(1);
//dbSetDirectionalLight(1, -5, -5, 5);
// this line simply loads our 3D object(using the char* variable defined above) and assigns it as dbObject Number 1
dbLoadObject(OBJ_TO_LOAD, 1);
dbPositionObject(1, 0.0, 0.0, 0.0);
// Uncomment the below lines to load a texture and apply it to you object.
//dbLoadImage(TEXT_TO_LOAD, 1);
//dbTextureObject(1, 1);
dbShowObject(1);
// this function interrogates object 1 and assigns its limb information, name and number, to the dbchecklist
dbPerformCheckListForObjectLimbs(1);
// this assignment simply makes the variable itotlimb equal the total amount of items in the dbChechlist
itotlimb = dbChecklistQuantity();
// point the camera initially at our object :) change to suit
dbPositionCamera((dbObjectSizeX(1)-dbObjectPositionX(1)), (dbObjectSizeY(1)-dbObjectPositionY(1)), (dbObjectSizeZ(1)-dbObjectPositionZ(1))); // -- uncmoment this line to place the camera where u want, fill the values appropriately
dbPointCamera( dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1) );
dbText(0,0, " ");
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
// position our object at the 0,0,0 3d world co-ords, and make sure it stays there
dbPositionObject(1, 0.0, 0.0, 0.0);
// tell our camera to be controlled with the arrow keys..
dbControlCameraUsingArrowKeys(0, 4.0, 4.0);
// if the control key is pressed, move the camera down
if ( dbControlKey() == 1)
{ dbMoveCameraDown(0, 2.0);
}
// if the shift key is pressed, move the camera up
if ( dbShiftKey() == 1)
{ dbMoveCameraUp(0, 2.0);
}
// Display our Frames Per Second while in free-roam
dbText(0,15,"FPS : ");
dbText(120,15,dbStr(dbScreenFPS()));
// this while loop just checks if the enter key is being pressed.. if its not, then the program goes into
// "pause mode" and cycles through the list of limbs and limb names of the object with each key press
// if the enter key is being held down, this loop is skipped, allowing a "free-roam" mode
// yes, this is very inefficient code, and fairly untidy, it was written only for a purpose, being so simple
// efficiency doesnt become an issue.
// NOTE : the dbEscapeKey() part is to prevent the app getting stuck in an infinte loop if u hit escape at the wrong time
// start the iteration mode loop
while ( (dbReturnKey() == 0) && (dbEscapeKey() == 0) )
{
// display some simple instructions
dbText ( 0, 0, "Press a single key to advance through the list of limbs one at a time. Hold <ENTER> for Free-Roam." );
// display total object polygons
dbText(0,35,"Total Polys : ");
dbText(120,35,dbStr(dbStatistic(1)));
// display the name of the loaded object
dbText(0,50,"Object Name :");
dbText(120,50,OBJ_TO_LOAD);
// display the total number of limbs the object has
dbText(0,65,"Total Limbs : ");
dbText(120,65,dbStr(itotlimb));
// display the current number of the limb
dbText(0,95,"Limb Number : ");
dbText(120,95,dbStr(i));
// display the current name of the limb
dbText(0,110,"Limb Name : ");
dbText(120,110, dbChecklistString(i));
// this little loop simply counts thru from zero to the total number of limbs, once it has counted all the limbs, it resets to
// zero and starts again, used to iterate the display of the limb number and name each loop
++i;
if ( i == (itotlimb+1) ) i = 0;
// these 2 lines simply draw our screen and then wait for the user to press a key before doing it again
dbSync ( );
dbWaitKey();
}
// draw our screen while in "free-roam" mode
dbSync();
}
// before quitting delete our object
dbDeleteObject(1);
// and now everything is ready to return back to Windows
return;
}
If you have any questions, ideas for improvements, or just an overriding need to tell me how bad my code is, then feel free to PM me @ Mista Wilson...
If it ain't broke.... DONT FIX IT !!!