Trying to speed up and slow down my object with (dbKeyState() )and joystick. Have used 4 code postings but could not seem to make them work. Also just learning C++ Any help would be great
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
int x = 0;
int view = 0;
int control = 0;
float direction_flt = 0;
float climb_flt = 0;
float speed_flt = 0;
float power_flt = 0;
float rollstep_flt = 0;
float pitchstep_flt = 0;
float joyr_flt = 0;
float joyp_flt = 0;
float alt_flt = 0;
float sineroll_flt = 0;
float rudder_flt = 0;
float truepitch_flt = 0;
float gravity_flt = 0;
float coefdrag_flt = 0;
float drag_flt = 0;
int count = 0;
//this sets our main window up
dbSetDisplayMode ( 1280 , 768 , 32 );
//dbSetWindowOff ( );
dbMaximiseWindow ( );
dbBackdropOff ( 0 );
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//this prints a message on our start up screen
dbPrint ( "Please wait trying to load model..." );
dbSync ( );
dbSync ( );
// switch to the media directory
SetCurrentDirectory ( "R-C_SimMedia" );
//load our world and turn lighting off
dbLoadObject ( "R-C_Sim.x", 1 );
dbSetObjectLight ( 1, 0 );
dbScaleObject ( 1, 1000, 1000, 1000);
// load a model for our aircraft
dbLoadObject ( "Ercoupe.X", 2 );
dbSetObjectLight ( 2, 0 );
dbScaleObject ( 2, 100, 100, 100 );
dbDisableObjectZDepth ( 2 );
// Load sound
dbLoad3DSound ( "RC Eng.wav" , 1 );
dbLoopSound ( 1 );
// our main loop
while ( LoopGDK ( ) )
{
// view control Inputs
if ( dbScanCode() == 59 ) {
view = 0;
// F1
}
if ( dbScanCode() == 60 ) {
view = 1;
}
if ( dbScanCode() == 61 ) {
view = 2;
}
if ( dbScanCode() == 62 ) {
view = 3;
}
//joystick control
joyr_flt = dbJoystickX() / 180.0;
joyp_flt = dbJoystickY() / 180.0;
// apply aileron
rollstep_flt = rollstep_flt + ( joyr_flt / 8 );
// provides an intertia effect
rollstep_flt = rollstep_flt * .4;
// provides a damping effect.. a value like .95 or higher will also allow a
// wandering effect such as you get with some less laterally stable model aircraft.
dbRollObjectRight( 2, rollstep_flt );
// basic aileron / roll action of plane
// apply elevator
pitchstep_flt = pitchstep_flt + ( joyp_flt / 20 );
pitchstep_flt = pitchstep_flt * .7;
dbPitchObjectUp( 2, pitchstep_flt );
// get a roll angle related to WORLD horizontal. When the plane is tilted, pitched or turned this provides
// a result different from the plane relative roll angle. This difference makes the system work.
alt_flt = dbObjectPositionY( 2 );
dbTurnObjectRight( 2, 90 );
dbMoveObject( 2, 1 );
sineroll_flt = dbObjectPositionY( 2 ) - alt_flt;
dbMoveObject( 2, -1 );
dbTurnObjectLeft( 2, 90 );
//then split the tilted lift vector of the wings between the WORLD horizontal and vertical axis using sineroll.
dbTurnObjectLeft( 2, sineroll_flt );
dbPitchObjectUp( 2, dbAbs( sineroll_flt ) / 2 );
//get world related pitch.
dbMoveObject( 4, 1 );
truepitch_flt = alt_flt - dbObjectPositionY( 4 );
dbMoveObject( 4, -1 );
gravity_flt = truepitch_flt * 2;
//add a cheap glide effect!
if ( speed_flt < 2.5 && truepitch_flt < .3 ) {
dbPitchObjectDown( 4, .15 );
}
//adjust camera
if (view == 0) {
dbPositionCamera (0, 6, -20);
dbPointCamera( dbObjectPositionX( 2 ), dbObjectPositionY( 2 ), dbObjectPositionZ( 2 ) );
}
if ( view == 1 ) {
}
dbPositionSound ( 1, dbObjectPositionX( 2 ), dbObjectPositionY( 2 ), dbObjectPositionZ( 2 ) );
// update the screen
dbSync ( );
}
// return back to windows
return;
}