I'm trying to get collision to work between two .x object in my current project. Whenever the objects get close, sparky's starts to use up tons of my computers resources, but once they overlap it is not returning that they have collided.
Here is the code:
#include "DarkGDK.h"
#include "SC_Collision.h"
void DarkGDK ( void )
{
int CX=5;
int CY;
int CZ=0;
int Knight = 3;
int speed = 0;
dbSyncOn ( );
dbSyncRate ( 60 );
SC_Start ();
dbSetCameraRange ( 1.0f, 30000.0f );
dbLoadImage ( "texture12.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ();
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "heightmap13.bmp" );
dbSetTerrainScale ( 1, 2, 2, 2 );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
dbLoadObject ( "skybox2.x", 2 );
dbSetObjectLight ( 2, 0 );
dbScaleObject ( 2, 30000, 30000, 30000 );
dbLoadObject ("Knight/H-Knight-Move.x",3);
SC_SetupObject (3,0,0);
SC_AllowObjectScaling (3);
dbLoadObject ("Tank2/H-Tank 2.x",4);
SC_SetupObject (4,2,0);
SC_AllowObjectScaling (4);
dbPositionObject (3,1200,2,1500);
dbPositionObject (4,1385,81,1225);
dbSetObjectTexture ( 2, 3, 1 );
dbScaleObject(3,1000,1000,1000);
dbLoopObject (3);
dbSetObjectSpeed (3,100);
dbScaleObject(4,1000,1000,1000);
SC_SetObjectCollisionOn (3);
SC_SetObjectCollisionOn (4);
while ( LoopGDK ( ) )
{
float fHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( 3), dbObjectPositionZ ( 3) );
dbPositionCamera (dbObjectPositionX(3),dbObjectPositionY(3) + 40,dbObjectPositionZ(3));
dbRotateCamera (dbObjectAngleX(3),dbObjectAngleY(3)+180,dbObjectAngleZ(3));
dbMoveCamera (-40);
dbPitchCameraDown (35);
dbSetObjectSpeed (3,speed);
speed = 0;
SC_UpdateObject (3);
SC_UpdateObject (4);
int collide = SC_ObjectCollision(3,0);
if (collide = 0); {
if (dbUpKey()==1)
{
dbMoveObject(3,-1.5f);
speed =70;
}
if (dbDownKey()==1)
{
dbMoveObject (3,1.5f);
speed = -70;
}
if (dbLeftKey()==1)
{
dbTurnObjectLeft(3,1.5f);
}
if (dbRightKey()==1)
{
dbTurnObjectRight(3,1.5f);
}
}
dbUpdateTerrain ( );
dbPositionObject(3,dbObjectPositionX(3),fHeight+2,dbObjectPositionZ(3));
dbText (0,0,"X: ");
dbText (15,0,dbStr (dbObjectPositionX(3)));
dbText (0,10,"Y: ");
dbText (15,10,dbStr (dbObjectPositionY(3)));
dbText (0,20,"Z: ");
dbText (15,20,dbStr (dbObjectPositionZ(3)));
dbText (0,30,"C: ");
dbText (15,30,dbStr (collide));
dbSync ( );
}
}
The coding is a bit messy because I've just been playing around with dark GDK. Any help would be greatly appreciated.
Thanks!
alalala