You will need to decide things like a) how fast the object will move each step, b) how much time to wait before taking the next step, etc.
I will try and give you code examples to walk you through this but as i'm writing in a browser window and not in my c++ IDE and im not actually building and testing with a real project as I go there may be bits overlooked or little bugs for you to explore and fix in your real life project
There are two ways you can do things. One is to use the DGDK commands that make your life easier but your code only really relevent to dgdk based games (ie, cant re-use in a directx game you may make in a years time) or you can do things by hand.
If you were doing this by hand you would store off the objects current location and angle. You would then get the angle between the objects current location and its destination and rotate the object by that angle.
you would then check to see if you were close enough to the destination to be considered "there" (dont check for exacts because of inaccuracies after the decimal point) and if not then plot a coordinate in a line using the angle you were now facing that brought you closer to the destination. I can give you code for this sort of thing if you want it - but im going to assume the easy way is fine and show you that for now instead.
ok, using dgdk commands:
First thing you need to do is point your object towards its destination (this is all presuming streight lines is fine). dgdk makes this easy. Assuming your objects ID is stored in an integer called nObjID and that you're storing your target destination in three floats called fDX, fDY and fDZ then:
dbPointObject(nObjID, fDX, fDY, fDZ);
now you need to check to see if you're close to your destination. Use my distance checking functions to do this, the code for them is:
/*******************************************************************************************/
/* FastSqrt - find the square root of a number, much MUCH faster than normal sqrt routines */
/*******************************************************************************************/
double FastSqrt(double r) {
double x,y;
double tempf;
unsigned long *tfptr = ((unsigned long *)&tempf)+1;
tempf = r;
*tfptr=(0xbfcd4600-*tfptr)>>1;
x=tempf;
y=r*0.5;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
return x*r;
}
/*************************************************************/
/* Dist3D - Find the distance between two 3d points in space */
/*************************************************************/
float Dist3D(float x1, float y1, float z1, float x2, float y2, float z2) {
return (float) FastSqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)) + ((z2 - z1)*(z2 - z1)));
}
and use them to create a conditional like this:
if (Dist3D(dbObjectPositionX(nObjID), dbObjectPositionY(nObjID), dbObjectPositionZ(nObjID), fDX, fDY, fDZ) < 2.5f) {
//we're at the destination. you could pick a new one here.
} else {
//code to move to destination here..
}
Now I would put the dbPointObject() call in the "code to move to destination here" section of the if myself, no need to point otherwise. Then you need to move towards your destination.
Like I said earlier, you need to decide how frequently to move and how much to move when you do. Create an integer to store the time that the object last moved, like:
int nLastUpdate = 0;
also two variables to store how frequently to move and how much to move. Make them variables so you can easilly tweak these settings without changing the code, just to see how it reacts.
int nUpdateFrequency = 10; //move every 10ms - the higher this is, the jerkier the movement! but stops it going crazy fast on high speed cpus.
float fUpdateStep = 1.5f; //move 1.5 units each update
now the code to make the object move using the dgdk easy commands:
if (dbTimer() - nLastUpdate > nUpdateFrequency) {
dbMoveObject(nObjID, fUpdateStep);
nLastUpdate = dbTimer();
}
and that, should simply do it. so a finished program should look SOMEHING like:
#include "DarkGDK.h"
double FastSqrt(double r) {
double x,y;
double tempf;
unsigned long *tfptr = ((unsigned long *)&tempf)+1;
tempf = r;
*tfptr=(0xbfcd4600-*tfptr)>>1;
x=tempf;
y=r*0.5;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
x*=1.5-x*x*y;
return x*r;
}
float Dist3D(float x1, float y1, float z1, float x2, float y2, float z2) {
return (float) FastSqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)) + ((z2 - z1)*(z2 - z1)));
}
void DarkGDK(void) {
int nObjID = 10;
float fDX, fDY,fDZ;
int nLastUpdate = 0;
int nUpdateFrequency = 10;
float fUpdateStep = 1.0f;
dbMakeObjectCube(nObjID, 2.0f);
dbPositionObject(nObjID, 0.0f, 0.0f, 0.0f);
dbPositionCamera(0.0f, 20.0f, 0.0f);
fDX = -100.0f;
fDY = 0.0f;
fDZ = 250.0f;
while (LoopGDK()) {
if (Dist3D(dbObjectPositionX(nObjID), dbObjectPositionY(nObjID), dbObjectPositionZ(nObjID), fDX, fDY, fDZ) < 2.5f) {
//we're at the destination. you could pick a new one here.
dbInk(dbRgb(255,0,0), 0);
dbText(10, 10, "At Destination");
} else {
//code to move to destination here..
dbPointObject(nObjID, fDX, fDY, fDZ);
if (dbTimer() - nLastUpdate > nUpdateFrequency) {
dbMoveObject(nObjID, fUpdateStep);
nLastUpdate = dbTimer();
}
}
dbPointCamera(dbObjectPositionX(nObjID), dbObjectPositionY(nObjID), dbObjectPositionZ(nObjID));
dbSync ( );
}
}
okay, so i got carried away and wrote the whole thing. Still, it might be helpful!! haha, hope that makes things clearer (I usually make things more confusing xD)