How should I do if I want to have box collision instead of sphere collision in this code?:
#include "DarkGDK.h"
#include "SC_Collision.h"
float gravity = -0.1f;
int ground = 1;
float radius = 10.0f;
int jumptimer = 0;
float slope = 0.5f;
float vx = 0;
float vy = 0;
float vz = 0;
void styra()
{
float oldx = dbObjectPositionX(1);
float oldy = dbObjectPositionY(1);
float oldz = dbObjectPositionZ(1);
vx = 0;
vz = 0;
if ( vy == 0 && jumptimer == 0 ) vy = vy + 10*gravity;
else vy = vy + gravity;
if(dbUpKey() == 1)
{
vz++;
}
if(dbDownKey() == 1)
{
vz--;
}
if(dbRightKey() == 1)
{
vx++;
}
if(dbLeftKey() == 1)
{
vx--;
}
if ( ground == 1 )
{
if ( dbSpaceKey() == 1 && jumptimer == 0 )
{
vy = vy + 5.0f;
jumptimer = 10;
}
}
float x = oldx + vx;
float y = oldy + vy;
float z = oldz + vz;
//Sphere collision!
int collide = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 );
if ( collide > 0 )
{
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope )
{
oldy = SC_GetStaticCollisionY();
}
else
{
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
if ( ny > slope )
{
ground = 1;
vy = 0;
}
else
{
ground = 0;
if ( ny < -slope ) vy = gravity;
}
}
else
{
oldy = oldy + vy;
ground = 0;
}
if ( ground == 1 && jumptimer > 0 ) jumptimer--;
//Another sphere collision!!
collide = SC_SphereSlideGroup( 1, oldx,oldy,oldz, x,oldy,z, radius,0 );
if ( collide > 0 )
{
x = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
z = SC_GetCollisionSlideZ();
vx = 0;
vz = 0;
}
dbPositionObject(1,x,oldy,z );
SC_UpdateObject(1);
}
void DarkGDK( )
{
dbSyncOn();
SC_Start();
dbMakeObjectBox(1, 32, 32, 32);
dbPositionObject(1, -250, 16, 250);
SC_SetupObject(1, 0, 2);
dbMakeObjectPlain(2, 1000, 1000);
dbXRotateObject(2, 270);
dbColorObject(2, dbRGB(0, 255, 0));
SC_SetupObject(2, 1, 2);
dbMakeObjectPlain(3, 100, 100);
dbXRotateObject(3, 45);
dbColorObject(3, dbRGB(255, 0, 0));
SC_SetupObject(3, 1, 2);
dbMakeObjectBox(4, 100, 100, 100);
dbPositionObject(4, -250, 0, 0);
dbColorObject(4, dbRGB(0, 0, 255));
SC_SetupObject(4, 1, 2);
dbSetNormalizationOn();
dbSetPointLight(0, 0, 200, 0);
dbSetAmbientLight(40);
dbSetLightRange(0, 2000);
while( LoopGDK( ) )
{
styra();
float cz = dbNewZValue(dbObjectPositionZ(1), dbWrapValue(dbMouseX()), 100);
float cx = dbNewXValue(dbObjectPositionX(1), dbWrapValue(dbMouseX()), 100);
dbPositionCamera(cx, dbObjectPositionY(1) + 50, cz);
dbPointCamera(dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1));
dbSync( );
}
}