Hello,
Could you please help me add that camera script you posted to this script - i would like the pistol to be positioned in front of the camera, FPS style. However, i am not sure where to place the code in the existing camera function. Thanks
// Dark GDK - The Game Creators - www.thegamecreators.com
// include Dark GDK header file
#include "DarkGDK.h"
// global variables - used for the camera
float g_fSpeed = 0.1f; // speed at which camera moves
float g_fTurn = 0.03f; // turn speed for mouse look
float g_fOldCamAngleX = 0.0f; // to store original x angle
float g_fOldCamAngleY = 0.0f; // to store original y angle
float g_fCameraAngleX = 0.0f; // to sotre new x angle
float g_fCameraAngleY = 0.0f; // to store new y angle
// forward declaration for functions
void userInput ( void ); // handles user input
void showFPS ( void ); // show frame rate
void DarkGDK ( void )
{
// entry point for the application
dbSetDir ( "media\\" );
// 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
// load images for the terrain
dbLoadImage ( "media\\texture.jpg", 1 ); // diffuse texture
dbLoadImage ( "media\\detail.jpg", 2 ); // detail texture
// create the terrain
dbSetupTerrain ( ); // set up terrain library
dbMakeObjectTerrain ( 1 ); // make a new terrain
dbSetTerrainHeightMap ( 1, "media\\map.bmp" ); // set the terrain height map
dbSetTerrainScale ( 1, 3, 0.6f, 3 ); // set the scale
dbSetTerrainSplit ( 1, 5 ); // 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 ( "media\\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
// set starting camera position
dbPositionCamera ( 385, 23, 100 );
// Load the Model
dbLoadObject ("weapoms\\L-Pistol-Static.x", 1 ); // Load the model
dbScaleObject( 1, 100, 100, 100 ); // and finally scale
dbLoadImage ( "models\\pistolL.dds", 5 ); // Load texture
dbTextureObject ( 1, 5 ); // Texture the model
dbPositionObject ( 385, 23, 100, 100 ); // Position the model
dbSetObjectToCameraOrientation ( 1 );
// loop round until escape key is pressed
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
return;
// show the frame rate and handle user input
showFPS ( );
userInput ( );
// update the terrain
dbUpdateTerrain ( );
// render everything
dbSync ( );
}
}
void showFPS ( void )
{
char szFPS [ 256 ] = "";
strcpy ( szFPS, "fps = " );
strcat ( szFPS, dbStr ( dbScreenFPS ( ) ) );
dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( szFPS ), dbScreenHeight ( ) - 40, szFPS );
}
void userInput ( void )
{
dbControlCameraUsingArrowKeys ( 0, g_fSpeed, g_fTurn );
g_fOldCamAngleY = g_fCameraAngleY;
g_fOldCamAngleX = g_fCameraAngleX;
g_fCameraAngleY = dbWrapValue ( g_fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
g_fCameraAngleX = dbWrapValue ( g_fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
dbYRotateCamera ( dbCurveAngle ( g_fCameraAngleY, g_fOldCamAngleY, 24 ) );
dbXRotateCamera ( dbCurveAngle ( g_fCameraAngleX, g_fOldCamAngleX, 24 ) );
char* szKey = dbInKey ( );
if ( strcmp ( szKey, "+" ) == 0 )
{
if ( g_fSpeed < 1000 )
g_fSpeed = g_fSpeed + 0.01f;
}
if ( strcmp ( szKey, "-" ) == 0 )
{
if ( g_fSpeed > 0.02f )
g_fSpeed = g_fSpeed - 0.01f;
}
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 3.0f, dbCameraPositionZ ( ) );
}
Thanks In Advance!