Sorry to bother you all again, but I'm having a problem with my game, basically, when I move the mouse I want to turn the camera, I've managed to do this, but when I do it seems laggy, even though I'm getting a FPS rate of ~59, this effect only happens when rotating the camera about the Y axis, also, this effect is exaggerated when the player is moving, I think its something to do with how I'm managing my collision, but I cant figure out how that would affect it as the only place the camera is at all used is in the main loop.
Again, sorry to be a nuisance yet again. but hey, one day I might come up with something useful from all your amazing advice =).
Source:
#include "DarkGDK.h"
//Function Prototypes
void MovePlayer();
void Jump();
void Gravity();
void Shoot(int sX, int sY, int sZ, int dX, int dY, int dZ);
//Global Vars
int PlayerSpeed = 12;
bool CanJump = true;
bool CanJumpB = true;
bool CanShoot = true;
bool ApplyGravity = true;
int GravityStr = 20;
float Sensitivity=0.5;
int PlayerJumpVelocity = 0;
float playerAngleY = 0;
float playerAngleX = 0;
float playerAngleZ = 0;
void DarkGDK(void)
{
dbSyncOn();
dbSyncRate(60);
dbSetDisplayMode(800, 600, 32);
dbSetWindowOff();
dbLoadImage("MetalTexture.bmp", 1);
if(dbImageExist(1))
{
//Loads map
dbLoadObject("Map3.dbo", 1);
// dbScaleObject(1, 300, 300, 300);
// dbPositionObject(1, 500, 0, 0);
dbSetObjectCollisionToPolygons(1);
//Load Player
dbLoadObject("HandGun.x", 3);
dbSetObjectCollisionOff(3);
//Load player collision Box
dbMakeObjectCube(2, 40);
dbPositionObject(2, 0, 750, 0);
dbSetObjectCollisionToBoxes(2);
dbHideObject(2);
//Head Hit box
dbMakeObjectSphere(4, 35, 5, 5);
dbPositionObject(4, 0, 700, 0);
dbHideObject(4);
//Initialize cameras
dbMakeCamera(1);
dbSetCurrentCamera(1);
dbPositionCamera(1, 0, 1050, -50);
dbSetCameraRange(1, 5, 15000);
dbSetAmbientLight(200);
dbHideMouse();
int fps=0;
char* tFPS=new char[15];
while(LoopGDK())
{
fps = dbScreenFPS();
tFPS= dbStr(fps);
dbText(0,0, tFPS);
delete[] tFPS;
dbPositionMouse(20,20);
MovePlayer();
Jump();
Gravity();
//Rotates and positions the camera
playerAngleX += dbMouseMoveY()*Sensitivity;
playerAngleY += dbMouseMoveX()*Sensitivity;
dbRotateCamera(1, playerAngleX, playerAngleY, 0);
dbPositionCamera(dbObjectPositionX(2), dbObjectPositionY(2)+130,dbObjectPositionZ(2));
//Orients the objects to where the player is looking
dbRotateObject(2, 0, dbCameraAngleY(1), 0);
dbRotateObject(3, 0, dbCameraAngleY(1), 0);
//Moves hit box
dbPositionObject(4, dbCameraPositionX(1) , dbCameraPositionY(1) , dbCameraPositionZ(1));
//Move Gun
dbPositionObject(3, dbCameraPositionX(1) , dbCameraPositionY(1) , dbCameraPositionZ(1));
dbRotateObject(3, dbCameraAngleX(1), dbCameraAngleY(1), dbCameraAngleZ(1));
dbSync ( );
}
dbDeleteObject(1);
dbDeleteObject(2);
dbDeleteObject(3);
dbDeleteObject(4);
dbDeleteImage(1);
dbDeleteImage(2);
dbDeleteCamera(1);
dbShowMouse();
}
else
{
dbPrint("Texture not loaded");
dbWaitKey();
}
return;
}
void MovePlayer()
{
dbRotateObject(2, 0, playerAngleY, 0);
CanShoot = true;
if(dbKeyState(17))
{
dbMoveObject(2, PlayerSpeed);
if(dbObjectCollision(2, 1))
{
dbMoveObject(2, -PlayerSpeed);
}
}
if(dbKeyState(31))
{
dbMoveObject(2, -PlayerSpeed);
if(dbObjectCollision(2, 1))
{
dbMoveObject(2, PlayerSpeed);
}
}
if(dbKeyState(30))
{
dbMoveObjectLeft(2, PlayerSpeed);
if(dbObjectCollision(2, 1))
{
dbMoveObjectLeft(2, -PlayerSpeed);
}
}
if(dbKeyState(32))
{
dbMoveObjectRight(2, PlayerSpeed);
if(dbObjectCollision(2, 1))
{
dbMoveObjectRight(2, -PlayerSpeed);
}
}
}
void Gravity()
{
dbRotateObject(2, 0, playerAngleY, 0);
if(PlayerJumpVelocity>0)
PlayerJumpVelocity--;
dbMoveObjectDown(2, GravityStr-PlayerJumpVelocity);
if(dbObjectCollision(2, 1))
{
CanJump = true;
dbMoveObjectDown(2, -(GravityStr-PlayerJumpVelocity));
}
if(dbObjectCollision(4, 1))
{
PlayerJumpVelocity=0;
dbMoveObjectDown(2, GravityStr-PlayerJumpVelocity);
}
}
void Jump()
{
if(dbSpaceKey())
{
if(CanJump&&CanJumpB)
{
CanJump=false;
CanJumpB=false;
PlayerJumpVelocity=40;
}
}
else
CanJumpB=true;
}
edit:
Never mind, it seems to be working now (even though i did nothing to the source code)