So in short, I set up a small "flight sim" that basically uses a jet that can roll/pitch/yaw/etc. I wanted to have a third person camera view, and I have it almost perfect! The only problem is when you roll, then pitch; the view gets off for some reason.
The code:
#include "DarkGDK.h"
#define TERRAIN 1
#define SKYBOX 2
#define JET 3
void LoadTerrain(void) {
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( TERRAIN );
dbSetTerrainHeightMap ( 1, "map.bmp" );
dbSetTerrainScale ( 1, 20.0f, 2.0f, 20.0f );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
dbLoadObject ( "skybox2.x", SKYBOX );
dbSetObjectLight ( 2, 0 );
dbScaleObject ( 2, 30000, 30000, 30000 );
dbSetObjectTexture ( 2, 3, 1 );
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbHideMouse();
dbPrint ( "Loading...please hold..." );
dbSync();
dbSync();
LoadTerrain();
dbLoadObject("Jet.x", JET);
dbYRotateObject(JET, 180);
dbSetCameraRange ( 1.0f, 30000.0f );
dbPositionCamera ( -100, 800, 100 );
float speed = 0.0f, throttle = 4.0f;
char buffer[33];
while ( LoopGDK ( ) )
{
dbText ( 0, 0, "Use the arrow keys to fly the camera" );
dbText(0,10,"Throttle");
for (int i=0; i < (throttle - 1) * 10.0f; i++)
dbText(i, 20,"|");
dbText(0,30,"Speed");
dbText(0,40,itoa(speed*10.0f,buffer,10));
dbText(0,50,"Altitude");
dbText(0,60,itoa(dbObjectPositionY(JET),buffer,10));
dbMoveObject(JET, -speed);
if ( dbDownKey ( ) )
throttle-=.1f;
if ( dbUpKey ( ) )
throttle+=.1f;
if (throttle > 10.0f) throttle = 10.0f;
if (throttle < 1.0f) throttle = 1.0f;
if (speed < throttle) speed += .05f;
if (speed > throttle) speed -= .05f;
if (dbObjectPositionY(JET) <= dbGetTerrainGroundHeight(TERRAIN, dbObjectPositionX(JET), dbObjectPositionZ(JET))) dbPositionObject (JET, -100, 800, 100 );
if ( dbLeftKey ( ) )
dbTurnObjectLeft (JET, .5f );
if ( dbRightKey ( ) )
dbTurnObjectRight (JET, .5f );
dbPitchObjectDown(JET, dbMouseMoveY()/2);
dbRollObjectLeft(JET, dbMouseMoveX()/2);
dbPositionMouse(dbScreenWidth()/2, dbScreenHeight()/2);
//dbPositionObject(JET, dbCameraPositionX() + 10, dbCameraPositionY() - 5, dbCameraPositionZ() + 10);
//dbRotateObject(JET, dbCameraAngleX() + 180, dbCameraAngleY(), dbCameraAngleZ() + 180);
dbPositionCamera(dbObjectPositionX(JET), dbObjectPositionY(JET), dbObjectPositionZ(JET));
dbSetCameraToObjectOrientation(JET);
dbYRotateCamera(180);
dbXRotateCamera(-dbObjectAngleX(JET));
dbMoveCamera(-15);
//dbXRotateCamera(-90);
//dbMoveCamera(-10);
//dbXRotateCamera(90);
dbSync ( );
}
dbDeleteObject ( TERRAIN );
dbDeleteObject ( SKYBOX );
dbDeleteObject ( JET );
return;
}
Note:I'm using the Jet model from Dark Matter, though I guess you could substitute any in (though angles would be off)
Also note:I tried using the dbCameraToFollowObject or whatever, but it didn't rotate the view, and when I tried to rotate it myself, well...I'd rather not say...
""What is today, but the mere yesterday of yesterday's tommorow's tommorrow. The world can be a complicated thing"-..umm...I'll find the guy who said that...eventually"-Me