Hi, all i am a new game programmer that's why i m asking for help for every problem....
i am using BSP Maps in my FPS game using GDK for my final year Project... BSP maps have auto collisions feature... but i am unable to add gravity in my game... i read many threads and used the mentioned codes in them but all in vain...
please anyone help me to add gravity...here is my complete code
#include "DarkGDK.h"
#include "SC_Collision.h"
int fCameraAngleX;
int fCameraAngleY;
float cX=51.7;
float cY=1.75;
float cZ=7.6;
void mouse(void);
class myAnimObject
{
public:
myAnimObject();
~myAnimObject() {};
void setID(int ID) {m_ID = ID;}
void initAnim(int startFrame, int endFrame, float framesPerSec);
void animateObject(int curTime);
private:
int m_ID;
int m_startFrame, m_endFrame, m_numFrames;
float m_curFrame, m_fPerSec;
int m_prevTime;
};
//
myAnimObject::myAnimObject()
:m_startFrame(0), m_endFrame(0), m_numFrames(0),
m_curFrame(0), m_fPerSec(0),
m_prevTime(0)
{
}
//
void myAnimObject::initAnim(int startFrame, int endFrame, float framesPerSec)
{
m_startFrame = startFrame;
m_curFrame = startFrame;
m_endFrame = endFrame;
m_numFrames = m_endFrame - m_startFrame + 1;
m_fPerSec = framesPerSec;
m_prevTime = dbTimer();
dbSetObjectFrame(m_ID, startFrame);
}
//
void myAnimObject::animateObject(int curTime)
{
// curTime - prevTime is in milliseconds
float frameProgress = float(curTime - m_prevTime) * m_fPerSec / 1000.0;
m_curFrame += frameProgress;
while (m_curFrame > m_endFrame) m_curFrame -= m_numFrames; // wrap around
m_prevTime = curTime;
dbSetObjectFrame(m_ID, int(m_curFrame + 0.5));
}
void LoadMap()
{
dbLoadBSP ( "media//maps//DangerCity//Dangercity.pk3", "Dangercity.bsp" );
dbSetBSPCameraCollision ( 1, 0, 1.15, 0 );
}
void LoadPlayer()
{
dbLoadObject("media//Objects//fire2.x",10);
//dbPositionObject(10,51.7,1.25,7.6);
dbSetObjectFrame(10,70);
SC_SetupObject(10,0,1);
}
void LoadSky()
{
dbLoadObject ( "media//sky//skybox2.x", 2 );
dbSetObjectLight ( 2, 0 );
dbSetObjectTexture ( 2, 3, 2 );
dbScaleObject ( 2, 5000, 5000, 5000 );
}
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(60);
//postion of spawn only for map DayAfter
//dbPositionCamera(cX,cY,cZ);
dbAutoCamOff();
LoadMap();
LoadSky();
SC_Start();
//dbMaximizeWindow();
//dbSetWindowOff();
LoadPlayer();
dbHideMouse();
dbLockObjectOn(10);
int prevTime = dbTimer();
int frameTime = 0;
myAnimObject Gun;
Gun.setID(10);
Gun.initAnim(0, 320, 3000);
/*int Desktop_Width;
int Desktop_Height;
int Dekstop_Depth = 32;
Desktop_Width=GetSystemMetrics(0);
Desktop_Height=GetSystemMetrics(1);
dbSetDisplayMode(Desktop_Width,Desktop_Height,Dekstop_Depth);
dbSetWindowOff();*/
while (LoopGDK( ) )
{
if ( dbMouseClick ( ) == 1 )
{
int curTime = dbTimer();
Gun.animateObject(curTime);
}
//display and update the position of camera + Object
dbPrint(dbStr(dbCameraPositionX(0)));
dbPrint(dbStr(dbCameraPositionY(0)));
dbPrint(dbStr(dbCameraPositionZ(0)));
dbPrint(dbStr(dbTotalObjectFrames(10)));
dbSync ( );;
mouse();
//dbControlCameraUsingArrowKeys(0, 2.0f, 2.0f);
}
return;
}
void mouse(void)
{
if (dbKeyState (17))//(dbUpKey())
{
dbMoveCamera(0.05);
}
if (dbKeyState (31))//(dbDownKey())
{
dbMoveCamera(-0.05);
}
if (dbKeyState (30))//(dbLeftKey())
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) - 90 );
dbMoveCamera(0.05);
}
if (dbKeyState (32))//(dbRightKey())
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) + 90 );
dbMoveCamera(0.05);
}
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.3f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.3f );
//rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );
}
waiting for best response Thank u all....