Hi I am currently making a very simple first person shooter but the one thing I cant seem to do is get the gun to show infront of the camera. Here is the code can u please help me.
#include "DarkGDK.h"
// THIS IS THE RIGHT ONE
float g_fSpeed = 0.9f; // speed at which camera moves
float g_fTurn = 0.9f;
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
void displaygun (void);
void userInput (void);
void showFPS (void);
void DarkGDK ( void )
{
{
// initial application set up
dbSyncOn ( ); // turn sync on
dbSyncRate ( 60 ); // set sync rate to 60
dbBackdropOff ( ); // switch backdrop off - no need to clear screen
dbSetCameraRange ( 0.5f, 30000 ); // set the camera range
dbHideMouse ( );
// set starting camera position
dbPositionCamera ( 385, 23, 100 );
// load images for the terrain
dbLoadObject ( "media\\Atomiser.X", 10 );
dbLoadImage ( "texture.jpg", 1 ); // diffuse texture
dbLoadImage ( "detail.jpg", 2 ); // detail texture
// create the terrain
dbSetupTerrain ( ); // set up terrain library
dbMakeObjectTerrain ( 1 ); // make a new terrain
dbSetTerrainHeightMap ( 1, "map.bmp" ); // set the terrain height map
dbSetTerrainScale ( 1, 7, 0.6f, 3 ); // set the scale
dbSetTerrainSplit ( 1, 16 ); // set the split value
dbSetTerrainTiling ( 1, 4 ); // set the detail tiling
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1, 1, 0.78f, 0.5f ); // set the light
dbSetTerrainTexture ( 1, 1, 2 ); // set the textures
dbBuildTerrain ( 1 ); // build the terrain
// create our skybox
dbLoadObject ( "skybox2.x", 200 ); // load the skybox model
dbSetObjectLight ( 200, 0 ); // turn lighting off
dbSetObjectTexture ( 200, 3, 1 ); // set texture properties
dbPositionObject ( 200, 1000, 2000, 4000 ); // position the skybox
dbScaleObject ( 200, 30000, 30000, 30000 ); // and finally scale
}
int i;
for ( int i = 10; i < 50; i++ )
{
// make a sphere
dbMakeObjectSphere ( i, 1 );
dbPositionObject ( i, dbRnd (385) , dbRnd (330), dbRnd (500) );
dbScaleObject ( i, 100 + dbRnd ( 400 ), 100 + dbRnd ( 400 ), 100 + dbRnd ( 400 ) );
dbColorObject ( i, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
dbSetObjectSpecularPower ( i, 255 );
dbSetObjectAmbient ( i, 0 );
// position objects directly above terrian
//?
// set starting camera position
dbPositionCamera ( 385, 23, 100 );
}
// loop round until escape key is pressed
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
return;
userInput ( );
showFPS ( );
displaygun ( );
dbUpdateTerrain ( );
dbSync ( );
for ( int i = 2; i < 50; i++ )
dbRotateObject ( i, dbObjectAngleX ( i ) + 0.9, dbObjectAngleY ( i ) + 0.9, dbObjectAngleZ ( i ) + 0.9 );
}
}
void showFPS ( void )
{
char szFPS [ 256 ] = "";
strcpy ( szFPS, "fps = " );
strcat ( szFPS, dbStr ( dbScreenFPS ( ) ) );
dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( szFPS ), dbScreenHeight ( ) - 40, szFPS );
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.2f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.2f );
// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );
}
void displaygun (void)
{
dbRotateObject ( 10 ,-90 , 0 , 0 );
dbSetObjectAmbient ( 10 , 0 );
dbSetObjectAmbience ( 10 , 0x00000000 );
dbFixObjectPivot ( 10 );
dbDisableObjectZDepth ( 10 );
dbSetObjectCollisionOff ( 10 );
dbSetObjectToCameraOrientation ( 10 );
dbPositionObject ( 10 , dbCameraPositionX ( 0 ) , dbCameraPositionY ( 0 ) , dbCameraPositionZ( 0 ) );
dbMoveObjectRight ( 10 , 15 + sin ( 0.0f ) / 2.0f );
dbMoveObject ( 10 , 15.0f );
dbMoveObjectDown ( 10 , 15.0f + cos ( 0.0f ) / 2.0f );
}
void userInput ( void )
{
dbControlCameraUsingArrowKeys ( 0, g_fSpeed, g_fTurn );
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 3.0f, dbCameraPositionZ ( ) );
}