As for part 1:
#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
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 ( ), 0 /*fHeight + 3.0f*/, dbCameraPositionZ ( ) );
}
/**
@brief Entry point to the application.
*/
void DarkGDK(void)
{
dbSyncOn ( );
dbSyncRate ( 0 );
dbSetDisplayModeVSync(800, 600, 32, 0);
dbLoadObject("HighPolyCount.x", 1); // Object close to the player
dbLoadObject("MidPolyCount.x", 2); // Object moderately distant from the player
dbLoadObject("LowPolyCount.x", 3); // Object far, far away from the player
for (int i=1; i<4; i++)
{
dbPositionObject(i, 0, 0, 0);
dbScaleObject(i, 300, 300, 300);
dbHideObject(i);
}
int visible_object=0;
float fast_distance=0;
while (LoopGDK())
{
UserInput();
// we can get away with this since all objects are at <0,0,0> coords
float fast_distance= ((dbCameraPositionX() * dbCameraPositionX()) +
(dbCameraPositionY() * dbCameraPositionY()) +
(dbCameraPositionZ() * dbCameraPositionZ()));
dbHideObject(visible_object);
if (fast_distance>50000) {
visible_object=3;
}
else if ((fast_distance>=30000) && (fast_distance<=50000)) {
visible_object=2;
}
else if (fast_distance<30000) {
visible_object=1;
}
dbShowObject(visible_object);
char txt[50]="0";
sprintf_s(txt, 50, "FPS: %d DISTANCE: %f", dbScreenFPS(), fast_distance);
dbText(0,0,txt);
dbSync();
}
}
I believe this illustrates what you are looking to do...
Regards,
JTK