Hi,
I am building a 3D flying game using a jet fighter and would like to have a camera that follows the object. I have tried, unsuccessfully, to use the command dbSetCameraToFollow but it's not as smooth as I would like.
I have the jet moving perfectly, it is able to roll right and left, turn right and left (which involves a degree of roll as well as it looks more realistic), it can pitch up and down and moves in any direction using the space key.
Actually there's another question to do with the pitching of the plane. I want it to not be able pitch further than 90 degrees either way. Is that possible?
Any help is much appreciated.
Here's my code, please ignore anything commented out, i've tried on many occasions to make myself a smooth camera.
// 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 )
{
dbSetDisplayMode(1280, 800, 32);
dbSyncOn ( );
dbSyncRate ( 60 );
/*dbSetCameraRange(1.0f, 30000.0f);
dbLoadImage("Image4.jpg",2);
dbLoadImage("Image5.jpg",3);*/
float planePosX;
float planePosY;
float planePosZ;
float cameraPosX;
float cameraPosY;
float cameraPosZ;
float cameraAngleX;
float cameraAngleY;
float cameraAngleZ;
planePosX = 0;
planePosY = 0;
planePosZ = 0;
cameraPosX = planePosX;
cameraPosY = planePosY + 10;
cameraPosZ = planePosZ - 30;
dbLoadObject( "H-Jet Fighter-Move.x" ,1 );
dbPositionObject(1,planePosX,planePosY,planePosZ);
//dbPositionCamera(0,10,-30);
dbRotateObject(1,0,180,0);
dbLoopObject(1,1,1);
dbSetObjectSpeed(1,2);
dbPositionCamera(cameraPosX, cameraPosY, cameraPosZ);
/*dbRotateCamera(cameraAngleX, cameraAngleY, cameraAngleZ);*/
/*dbSetupTerrain();
dbMakeObjectTerrain(100);
dbSetTerrainHeightMap(100, "Image3.jpg");
dbSetTerrainScale(100,10,0.4,10);
dbSetTerrainLight(100, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.2f);
dbSetTerrainTexture(100,2,3);
dbBuildTerrain(100);
dbLoadObject("skybox2.x",4);
dbSetObjectLight(4,0);
dbScaleObject(4, 30000, 30000, 30000);*/
while ( LoopGDK ( ) )
{
if(dbShiftKey()==1)
{
if(dbKeyState(44)==1)
{
dbRollObjectRight(1,1);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbKeyState(44)==1)
{
dbRollObjectRight(1,3);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbShiftKey()==1)
{
if(dbKeyState(45)==1)
{
dbRollObjectLeft(1,1);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbKeyState(45)==1)
{
dbRollObjectLeft(1,3);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbShiftKey()==1)
{
if(dbLeftKey()==1)
{
dbRollObjectRight(1,1);
dbTurnObjectLeft(1,2);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbLeftKey()==1)
{
dbRollObjectRight(1,3);
dbTurnObjectLeft(1,5);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbShiftKey()==1)
{
if(dbRightKey()==1)
{
dbRollObjectLeft(1,1);
dbTurnObjectRight(1,2);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbRightKey()==1)
{
dbRollObjectLeft(1,3);
dbTurnObjectRight(1,5);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbShiftKey()==1)
{
if(dbDownKey()==1)
{
dbPitchObjectDown(1,1);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbDownKey()==1)
{
dbPitchObjectDown(1,3);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbShiftKey()==1)
{
if(dbUpKey()==1)
{
dbPitchObjectUp(1,1);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
} else if(dbUpKey()==1)
{
dbPitchObjectUp(1,3);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
if(dbSpaceKey()==1)
{
dbMoveObject(1,-1);
dbPlayObject(1);
/*planePosX = dbObjectPositionX(1);
planePosY = dbObjectPositionY(1);
planePosZ = dbObjectPositionZ(1);*/
}
dbSync ( );
}
return;
}