Ok my first posy woot
ok so my problem is with the camera angle, i have managed to laod an onject (my char) onto a terrain (used in the tut), i can then make a camera, get the camera to follow my char relative to his possition and i understand all my code so far, my problem however lies with the camera angle when i use the W/S keys, i want the keys to make the camera move up in hight, closer in distance and rotate the angle to point down and i want the total opposite for the S key, like in all MMORPG's when u press the up or down key it scrolls over the head of the char and down will pul lthe camera to the floor. So i am wondering how to make this possible in relation to my code. this is what i have so far
#include "DarkGDK.h"
void DarkGDK(void) {
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode(1680,1050,32);
dbMaximizeWindow();
//Camera
dbAutoCamOff();
dbSetCameraRange ( 1.0f, 100000.0f );
dbSetCurrentCamera(1);
float g_fCamDistance = 250.0f;
float g_fCamAngle = 15.0f;
float g_fHeight = 100.0f;
float g_fCamAngleX = 0.0f;
dbPrint ( "LOADING..." );
dbSync ( );
dbSync ( );
// terrain
//dbSetDir("Pictures");
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "height.JPG" );
dbSetTerrainScale ( 1, 150.0f, 15.5f, 150.0f );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
//dbAutomaticObjectCollision(1, 1, 0);
dbUpdateTerrain();
dbLoadObject ( "skybox2.x", 200 ); // load the skybox model
dbSetObjectLight ( 200, 0 ); // turn lighting off
dbSetObjectTexture ( 200, 3, 1 ); // set texture properties
dbPositionObject ( 200, 10000, 1000, 10000); // position the skybox
dbScaleObject ( 200, 100000, 100000, 100000 );
dbSync ( );
// main character
//dbSetDir("Objects");
dbLoadObject ("Colonel-X.x", 10 );
//dbAutomaticObjectCollision(10, 35, 1);
dbPositionObject(10, 750, 0, 450);
dbXRotateObject(10, 1.0f);
dbYRotateObject(10,180.0f);
//dbScaleObject(10,dbObjectSizeX(10) -10.0f, dbObjectSizeY(10) -10.0f , dbObjectSizeZ(10) -10.0f);
//dbRotateCamera(0.0f,10.0f,0.0f);
// now onto our main loop
while ( LoopGDK ( ) )
{
if (dbUpKey())
{
dbSetObjectSpeed(10, 45);
dbMoveObject(10, -2.0f);
dbLoopObject(10, 235, 259);
if(dbShiftKey())
{
dbSetObjectSpeed(10, 250);
dbMoveObject(10, -20.0f);
if (dbRightKey())
{
dbYRotateObject(10, dbObjectAngleY(10) +1.5f);
g_fCamAngle +=1.5f;
}
else if (dbLeftKey())
{
dbYRotateObject(10, dbObjectAngleY(10) - 1.5f);
g_fCamAngle -=1.5f;
}
}
else if (dbRightKey())
{
dbYRotateObject(10, dbObjectAngleY(10) +1.5f);
g_fCamAngle +=1.5f;
}
else if (dbLeftKey())
{
dbYRotateObject(10, dbObjectAngleY(10) - 1.5f);
g_fCamAngle -=1.5f;
}
}
else if (dbDownKey())
{
dbSetObjectSpeed(10, 25);
dbMoveObject(10, 1.0f);
dbLoopObject(10, 235, 259);
if (dbRightKey())
{
dbYRotateObject(10, dbObjectAngleY(10) +1.5);
g_fCamAngle +=1.5;
}
else if (dbLeftKey())
{
dbYRotateObject(10, dbObjectAngleY(10) -1.5f);
g_fCamAngle -=1.5;
}
} else if (dbRightKey() && (!dbUpKey() || !dbDownKey())) {
dbSetObjectSpeed(10, 30);
g_fCamAngle += 1.5f;
dbYRotateObject(10, dbObjectAngleY(10) +1.5f);
dbLoopObject(10, 235, 259);
} else if (dbLeftKey() && (!dbUpKey() || !dbDownKey())) {
dbSetObjectSpeed(10, 30);
dbYRotateObject(10, dbObjectAngleY(10) -1.5f);
g_fCamAngle -= 1.5f;
dbLoopObject(10, 235, 259);
}
else {
dbSetObjectSpeed ( 10, 20 );
dbLoopObject(10, 210, 234);
}
if (dbScanCode() == 17)
{
//g_fCamAngleX = g_fCamAngleX + 5;
g_fCamDistance = g_fCamDistance -2;
g_fHeight = g_fHeight +1;
}
else if (dbScanCode() == 32 )
{
g_fCamAngle += 1.5f;
}
else if (dbScanCode() == 30)
{
g_fCamAngle -= 1.5f;
}
else if (dbScanCode() == 31)
{
g_fCamDistance = g_fCamDistance +2;
g_fHeight = g_fHeight -1;
//dbPitchCameraDown(1, 0.5f);
dbPointCamera(dbObjectPositionX(10),dbObjectPositionY(10),dbObjectPositionZ(10)-5);
}
float fHeight = dbGetTerrainGroundHeight(1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject(10, dbObjectPositionX(10), fHeight +0.5f , dbObjectPositionZ(10));
dbSetCameraToFollow(dbObjectPositionX(10) , dbObjectPositionY(10) , dbObjectPositionZ(10),
dbWrapValue(g_fCamAngle), g_fCamDistance, g_fHeight, 10, true);
dbUpdateTerrain ( );
dbPointLight(0 , dbObjectPositionX(10), dbObjectPositionY(10), dbObjectPositionZ(10));
//dbPrint("FRAME: "); dbPrint(dbObjectFrame(10));
dbPrint("KEY: ");
dbPrint((double)dbScanCode());
dbPrint("OBJECT LOCATION (X,Y,Z): ");
dbPrint(dbObjectPositionX(10));
dbPrint(dbObjectPositionY(10));
dbPrint(dbObjectPositionZ(10));
dbPrint("CAMERA ANGLE (X,Y,Z): ");
dbPrint(dbCameraAngleX());
dbPrint(dbCameraAngleY());
dbPrint(dbCameraAngleZ());
dbSync ( );
}
}
Also i have so far tried to make the W button (KeyCode 17) add values to the height and distance whitch works fine, my problem lies with changing the relative camera angle,i figured out that it is the Z axis but whenever i try changing that value in the
if(KeyCode) {} section it doesnt work at all, it zooms into my char straight away and then slowly glitches to point to a side angle.
all help is greatly appreiciated.
thx very much in advance guys.
even the life you lead is borrowed because your not promised tommorow