I don't know what i'm doing wrong.....i don't know why colonel-X isn't collide with the cube
#include "DarkGDK.h"
#include "SC_Collision.h"
int fCameraAngleX;
int fCameraAngleY;
void collision (void);
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
SC_Start ( );
dbLoadObject ( "Colonel-X.x", 1 );
dbRotateObject (1, 0,50, 0);
dbSetObjectSpeed (1,20);
SC_SetupObject(1,0,1);
dbLoadObject ( "Atomiser.x", 2 );
dbPositionObject(3,50,0,-10);
dbRotateObject(3,-106,0,167);
dbScaleObject(3,450,450,450);
dbLoadObject ( "skybox2.x",4);
dbSetObjectLight ( 4, 0 );
dbSetObjectTexture ( 4, 3, 2 );
dbScaleObject ( 4, 5000, 5000, 5000 );
dbMakeMatrix (12,200,200,20,20);
for( int i=10002; i <= 10040; i++ )
{
dbMakeObjectPlain( i,3,3 );
dbTextureObject (i,5);
dbSetObjectLight( i,0 );
dbHideObject( i );
}
dbGlueObjectToLimb (2,1,32);
dbRotateObject (2,80,-380,-20);
dbScaleObject (2,76,76,76);
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbHideMouse ();
dbMakeObjectCube (15,30);
dbPositionObject (15,375,40,100);
dbScaleObject (15,200,200,200);
SC_SetupObject (15,0,1);
dbSetObjectCollisionToPolygons (1);
dbSetObjectCollisionToBoxes (15);
bool Should_Walk = false;
bool Is_Walking = false;
bool Should_Walk_Left = false;
bool Is_Walking_Left = false;
bool Should_Walk_Right = false;
bool Is_Walking_Right = false;
bool Should_Crouch = false;
bool Is_Crouching = false;
bool Should_Crouch_Forward = false;
bool Is_Crouching_Forward = false;
bool Should_Run = false;
bool Is_Running = false;
bool Should_Run_Left = false;
bool Is_Running_Left = false;
bool Should_Run_Right = false;
bool Is_Running_Right = false;
bool Should_Turn_Right = false;
bool Is_Turning_Right = false;
bool Should_Turn_Left = false;
bool Is_Turning_Left = false;
// our main loop
while ( LoopGDK ( ) )
{
dbPositionCamera(dbObjectPositionX(1),dbObjectPositionY(1)+65,dbObjectPositionZ(1));
dbRotateCamera(dbObjectAngleX(1),dbObjectAngleY(1)+180,dbObjectAngleZ(1));
dbMoveCamera (-120);
SC_UpdateObject(1);
Should_Walk = dbKeyState ( 17 ) || dbUpKey ( );
if ( Should_Walk )
{
dbMoveObject ( 1, -2.0f );
}
if ( Should_Walk && ! Is_Walking )
{
dbLoopObject ( 1,598,622 );
Is_Walking = true;
}
else if ( ! Should_Walk && Is_Walking )
{
dbStopObject ( 1 );
Is_Walking = false;
} // Makes object #1 walk
if ( ! Is_Walking && ! Is_Walking_Left && ! Is_Walking_Right && ! Is_Crouching && ! Is_Crouching_Forward && ! Is_Running && ! Is_Running_Left && ! Is_Running_Right )
{
dbLoopObject ( 1,573,597 );
}
Should_Walk_Left = dbKeyState ( 30 );
if ( Should_Walk_Left )
dbMoveObjectRight ( 1, 1.0f );
if ( Should_Walk_Left && ! Is_Walking_Left )
{
dbLoopObject ( 1, 623,642 );
Is_Walking_Left = true;
}
else if ( ! Should_Walk_Left && Is_Walking_Left )
{
dbStopObject ( 1 );
Is_Walking_Left = false;
}
Should_Walk_Right = dbKeyState ( 32 );
if ( Should_Walk_Right )
dbMoveObjectLeft ( 1, 1.0f );
if ( Should_Walk_Right && ! Is_Walking_Right )
{
dbLoopObject ( 1,381,405 );
Is_Walking_Right = true;
}
else if ( ! Should_Walk_Right && Is_Walking_Right )
{
dbStopObject ( 1 );
Is_Walking_Right = false;
}
Should_Crouch = dbKeyState ( 29 );
if ( Should_Crouch && ! Is_Crouching )
{
dbLoopObject ( 1, 732,756 );
Is_Crouching = true;
}
else if ( ! Should_Crouch && Is_Crouching )
{
dbStopObject ( 1 );
Is_Crouching = false;
}
Should_Crouch_Forward = dbKeyState ( 29 ) && dbKeyState ( 17 );
if ( Should_Crouch_Forward )
dbMoveObject ( 1, -1.0f );
if ( Should_Crouch_Forward && ! Is_Crouching_Forward )
{
dbLoopObject ( 1, 757,781 );
Is_Crouching_Forward = true;
}
else if ( ! Should_Crouch_Forward && Is_Crouching_Forward )
{
dbStopObject ( 1 );
Is_Crouching_Forward = false;
}
Should_Run = dbKeyState ( 42 ) && dbKeyState ( 17 );
if ( Should_Run )
dbMoveObject ( 1, -6.0f );
if ( Should_Run && ! Is_Running )
{
dbSetObjectSpeed (1,30);
dbLoopObject ( 1, 663,681 );
Is_Running = true;
}
else if ( ! Should_Run && Is_Running )
{
dbStopObject ( 1 );
Is_Running = false;
}
SC_UpdateObject(1);
SC_DrawObjectBounds(1);
SC_DrawObjectBounds(15);
// create a rotation axis based on mouse movement
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.2f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.2f );
// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateObject ( 1,fCameraAngleY );
collision( );
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ),
dbCameraPositionZ ( ) );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 40.0f,
dbCameraPositionZ ( ) );
// update the screen
SC_UpdateObject(1);
dbSync ( );
}
// return back to windows
return;
}
void collision(void)
{
int collide=0;
int counter = 10002;
if ( dbMouseClick() == 1 )
{
//get our collision vector
float oldx = dbCameraPositionX();
float oldy = dbCameraPositionY();
float oldz = dbCameraPositionZ();
dbMoveCamera( 200 );
float x = dbCameraPositionX();
float y = dbCameraPositionY();
float z = dbCameraPositionZ();
dbMoveCamera( -200 );
collide = SC_RayCast( 0, oldx,oldy,oldz, x,y,z, 0 );
if ( collide > 0 )
{
//get the collision point
float newx = SC_GetStaticCollisionX();
float newy = SC_GetStaticCollisionY();
float newz = SC_GetStaticCollisionZ();
//get collision normal
float normx = SC_GetCollisionNormalX();
float normy = SC_GetCollisionNormalY();
float normz = SC_GetCollisionNormalZ();
//position and point a marker in the right direction
dbPositionObject( counter, newx + normx/10.0f, newy + normy/10.0f, newz + normz/10.0f );
dbPointObject( counter, newx + normx, newy + normy, newz + normz );
dbShowObject( counter );
counter++;
if ( counter > 10040 ) counter = 10002;
}
}
}