Im new to DarkGDK and learning C++ have some experience but learning more as I go.
Ive searched the forums and have only been able to find either a basic chase cam or control with keys or always control with mouse, im trying to make it to where its a chase cam (srd person RPG style) and then you can adjust the pitch of the camera by using the mouse and right click, but i cant seem to get it right this is what i have so far.
void gamecontrol(void)
{
float fPlayerHeight;
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
if ( dbUpKey ( ) ||dbKeyState(17))
{
dbMoveObject ( 10, 1.0f );
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if ( dbDownKey ( )||dbKeyState(31) )
{
dbMoveObject ( 10, -1.0f );
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if (dbKeyState(16) )
{
dbMoveObjectLeft ( 10, 1.0f );
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if (dbKeyState(18))
{
dbMoveObjectRight ( 10, 1.0f );
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if(dbRightKey()||dbKeyState(32))
{
dbTurnObjectRight(10,1.0f );
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if(dbLeftKey()||dbKeyState(30))
{
dbTurnObjectLeft (10,1.0f);
fPlayerHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject ( 10, dbObjectPositionX ( 10 ), fPlayerHeight+5.0f, dbObjectPositionZ ( 10 ) );
updatecamera();
}
if(dbMouseClick()&2)
{
fCameraAngleX=dbMouseMoveY()*0.4f;
fCameraAngleY=dbMouseMoveX()*0.4f;
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateObject ( 10, fCameraAngleY);
updatecamera();
dbUpdateTerrain();
dbSync();
}
}
void updatecamera(void)
{
float camerax=dbCameraAngleX();
float fPlayerFace = dbObjectAngleX ( 10 );
dbPositionCamera(dbObjectPositionX(10),dbObjectPositionY(10)+25.0f,dbObjectPositionZ(10));
dbSetCameraToObjectOrientation(10);
dbXRotateCamera(camerax);
dbMoveCamera(-100.0f);
the movement works and it rotates it and the update camera keeps the angle mostly for the pitch(gets a little messed up with terrain sometimes). could use some help thanks