The owner of that particular video sent me the code for it. He just removed the terrain and replaced it with a matrix, and the model with a cube. But it might help to study the code snippet.
#include "DarkGDK.h"
#define PLAYER 1
struct vector2 // 2d vector
{
float x, y;
};
struct vector3 // 3d vector
{
float x, y, z;
};
struct vector4 //4d vector
{
float x, y, z, v;
};
class player
{
public:
int spawn( float fX, float fY, float fZ )
{
// spawn player and set basic attributes
spawned = true;
height = 5;
position.x = fX;
position.y = fY;
position.z = fZ;
// make player model (setup for dwarf mdl, http://www.psionic3d.co.uk/gallery/displayimage.php?album=topn&cat=0&pos=2)
// dbLoadObject( "media/3d/characters/dwarf1.x", PLAYER );
// dbScaleObject( PLAYER, 35, 35, 35 );
dbMakeObjectCube( PLAYER, 1 );
dbPositionObject( PLAYER, position.x, position.y + 0.5, position.z );
return 0;
}
int rotate( float fX, float fY, float fZ )
{
angle.x = fX;
angle.y = fY;
angle.z = fZ;
dbRotateObject( PLAYER, angle.x, angle.y, angle.z );
return 0;
}
int control( )
{
// show mouse
dbShowMouse( );
// reset animation
animstate = 'z';
// rightclick
if( dbMouseClick( ) == 2 || dbMouseClick( ) == 3 )
{
// rotate player
// rotate( 0, dbWrapValue( angle.y + ( dbMouseMoveX( ) / 2 ) ), 0 );
if( dbMouseX( ) > oldMouseX )
angle.y = angle.y + 8;
if( dbMouseX( ) < oldMouseX )
angle.y = angle.y - 8;
oldMouseX = dbMouseX( );
// set camera height
if( height <= 10 && height >= 0 )
{
if( dbMouseY( ) > oldMouseY )
height = height + .8;
if( dbMouseY( ) < oldMouseY )
height = height - .8;
}
oldMouseY = dbMouseY( );
if( height <= 0 )
height = .01;
if( height >= 10 )
height = 9.99;
if( dbKeyState( 30 ) )
{
animstate = 'b';
position.x = dbNewXValue( position.x, angle.y - 90, .1 );
position.z = dbNewZValue( position.z, angle.y - 90, .1 );
}
if( dbKeyState( 32 ) )
{
animstate = 'b';
position.x = dbNewXValue( position.x, angle.y + 90, .1 );
position.z = dbNewZValue( position.z, angle.y + 90, .1 );
}
}
// control forward/backwards
if( dbKeyState( 17 ) )
{
animstate = 'a';
position.x = dbNewXValue( position.x, angle.y, .2 );
position.z = dbNewZValue( position.z, angle.y, .2 );
}
if( dbKeyState( 31 ) )
{
animstate = 'b';
position.x = dbNewXValue( position.x, angle.y, -.1 );
position.z = dbNewZValue( position.z, angle.y, -.1 );
}
// rotate
if( dbMouseClick( ) != 2 )
{
if( dbKeyState( 30 ) )
{
animstate = 'b';
angle.y = dbWrapValue( angle.y - 5 );
}
if( dbKeyState( 32 ) )
{
animstate = 'b';
angle.y = dbWrapValue( angle.y + 5 );
}
}
// move, rotate, and animate player
dbPositionObject( PLAYER, position.x, position.y + 0.5, position.z );
dbRotateObject( PLAYER, angle.x, angle.y, angle.z );
animate( );
// success!
return 0;
}
int animate( )
{
switch( animstate )
{
case 'a':
dbSetObjectSpeed( PLAYER, 80 );
dbLoopObject( PLAYER, 1, 13 );
oldanimstate = animstate;
return 0;
case 'b':
dbSetObjectSpeed( PLAYER, 40 );
dbLoopObject( PLAYER, 1, 13 );
oldanimstate = animstate;
return 0;
default:
dbSetObjectSpeed( PLAYER, 40 );
dbLoopObject( PLAYER, 292, 360 );
oldanimstate = animstate;
return 0;
}
}
int camera( )
{
dbSetCameraToFollow( position.x, position.y, position.z, angle.y, 8, height, 6, 0 );
dbPointCamera( position.x, position.y, position.z );
return 0;
}
bool despawn( )
{
// despawn player/delete model
spawned = false;
dbDeleteObject( PLAYER );
return spawned;
}
bool isSpawned( )
{
return spawned;
}
private:
bool spawned;
// camera/movement stuff
int mouseX;
int mouseY;
float oldMouseY;
float oldMouseX;
float height;
// animations
char animstate;
char oldanimstate;
// vector 3s
vector3 position;
vector3 angle;
// game information
int pyrolvl;
int hydrolvl;
int terralvl;
int zephyrlvl;
};
void DarkGDK ( void )
{
// setup sync and video
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode( 640, 480, 32 );
dbColorBackdrop( 0 );
dbSetAmbientLight( 100 );
dbMakeMatrix( 1, 100, 10, 10, 10 );
// create test player
player mainPlayer;
mainPlayer.spawn( 5, 0, 5 );
// main loop
while ( LoopGDK ( ) )
{
if( mainPlayer.isSpawned( ) == true )
{
// control player
mainPlayer.control( );
mainPlayer.camera( );
}
// syncs it up!
dbSync ( );
}
// return back to windows
return;
}