Is the following code what you are looking for?
#define DIRECTINPUT_VERSION 0x0700
#include <DarkGDK.h>
#include <Dinput.h>
void MoveObjectRelToCamera(int nObj, float dx, float dy, float dz);
// models
int nPlane=1;
int nTroll=2;
// images
int nFloorImage=1;
void DarkGDK ( void )
{
float camPitch, camYaw, xpos=0.0f, ypos=0.0f, zpos=0.0f, rotx=0.0f;
dbSetDisplayMode( 800, 600, 32 );
dbSyncOn( );
dbSyncRate( 60 );
dbAutoCamOff();
// scene
dbSetAmbientLight( 95 );
dbColorBackdrop( dbRGB(0, 0, 0) );
dbPositionCamera( 0.0f, 1.0f, -4.0f );
// textures
dbLoadImage( "../Media/Floor.tga", nFloorImage );
// objects
dbLoadObject( "../Media/Walk.x", nTroll );
dbScaleObject( nTroll, 3.0f, 3.0f, 3.0f );
dbSetObjectSpeed( nTroll, 10 );
dbLoopObject(nTroll);
dbLoadObject( "../Media/Plane.x", nPlane );
dbTextureObject( nPlane, 0, nFloorImage );
while ( LoopGDK ( ) )
{
// update camera
camYaw = dbCameraAngleY( );
camPitch = dbCameraAngleX( );
if ( dbUpKey() )
dbXRotateCamera( camPitch+1.0f );
if ( dbDownKey() )
dbXRotateCamera( camPitch-1.0f );
if ( dbLeftKey() )
dbYRotateCamera( camYaw-1.0f );
if ( dbRightKey() )
dbYRotateCamera( camYaw+1.0f );
if ( dbKeyState( DIK_A) )
dbMoveCamera( 0.25f );
if ( dbKeyState( DIK_Z) )
dbMoveCamera( -0.25f );
if ( dbKeyState( DIK_S ) )
MoveObjectRelToCamera( nTroll, -0.1f, 0.0f, 0.0f );
if ( dbKeyState( DIK_F ) )
MoveObjectRelToCamera( nTroll, 0.1f, 0.0f, 0.0f );
if ( dbKeyState( DIK_E ) )
MoveObjectRelToCamera( nTroll, 0.0f, 0.0f, 0.1f );
if ( dbKeyState( DIK_D ) )
MoveObjectRelToCamera( nTroll, 0.0f, 0.0f, -0.1f );
dbSync ( );
}
}
void MoveObjectRelToCamera(int nObj, float dx, float dy, float dz)
{
int nVectorWorldTroll=1;
int nVectorCameraTroll=2;
int nMatWorld=4;
int nMatView=5;
int nMatProj=6;
dbMakeVector3(nVectorWorldTroll);
dbMakeVector3(nVectorCameraTroll);
dbMakeMatrix4(nMatWorld);
dbMakeMatrix4(nMatView);
dbMakeMatrix4(nMatProj);
// load the world position of troll into nVectorWorldTroll vector
dbSetVector3( nVectorWorldTroll, dbObjectPositionX(nTroll), dbObjectPositionY(nTroll), dbObjectPositionZ(nTroll) );
// transform world troll coordinates to view space
dbViewMatrix4(nMatView);
dbTransformCoordsVector3( nVectorCameraTroll, nVectorWorldTroll, nMatView );
dbSetVector3( nVectorCameraTroll, dbXVector3(nVectorCameraTroll)+dx, dbYVector3(nVectorCameraTroll)+dy, dbZVector3(nVectorCameraTroll)+dz );
// transform view spcace coordinates to world (inverse the view matrix)
dbInverseMatrix4( nMatView, nMatView );
dbTransformCoordsVector3( nVectorWorldTroll, nVectorCameraTroll, nMatView );
dbPositionObject( nTroll, dbXVector3(nVectorWorldTroll), dbYVector3(nVectorWorldTroll), dbZVector3(nVectorWorldTroll) );
dbDeleteVector3(nVectorWorldTroll);
dbDeleteVector3(nVectorCameraTroll);
dbDeleteMatrix4(nMatWorld);
dbDeleteMatrix4(nMatView);
dbDeleteMatrix4(nMatProj);
}