I'm trying to get the height between two points of an object. Unfortunately dbIntersectObject can only deal with one object at a time, so I thought that we could find out which object is currently being detected. That too doesn't work terribly well either.
What I want to do is calculate the height between two points of an object and adjust the height accordingly (so when the box objects are titled, the box stays at the correct height.
Normally I would use a matrix, but unfortunately that cant be tilted...
void DarkSDK()
{
int x,z,obj;
float pitchX,pitchY;
float bX,bY,bZ,i;
dbSyncOn();
dbSyncRate(50);
obj=1;
pitchX=0.0;
pitchY=0.0;
for (x=0; x<25; x++)
{
for (z=0; z<25; z++)
{
dbMakeObjectBox(obj,100.0,2.0,100.0);
//dbLoadObject("c:\\moo.x",obj);
dbPositionObject(obj,x*100.0,0.0+(obj/10.0),z*100.0);
//dbRotateObject(obj,90.0,0.0,0.0);
if (obj>1)
{
dbGlueObjectToLimb(obj,1,0);
dbColorObject(obj,dbRgb(0,255,0));
dbSetObjectCollisionToBoxes(obj);
}
else
{
dbColorObject(obj,dbRgb(255,0,0));
dbShowObjectBounds(1,1);
}
obj++;
}
}
//dbRotateObject(1,90.0,0.0,0.0);
dbMakeObjectCube(obj,10.0);
dbColorObject(obj,dbRgb(255,0,255));
dbSetObjectCollisionToBoxes(obj);
bX=0.0;
bY=9.0;
bZ=-150.0;
dbShowObjectBounds(obj,0);
dbShowObjectBounds(1,0);
//dbMakeMatrix(1,320,240,16,16);
//dbPositionMatrix(1,0.0,10.0,0.0);
//dbRandomizeMatrix(1,20.0);
//dbUpdateMatrix(1);
while(LoopSDK()){
if (dbLeftKey())
{
if (pitchX>-10.0)
{
pitchX-=ANGLE;
//dbRollCameraLeft(ANGLE);
dbRollObjectLeft(1,ANGLE);
}
}
else
if (dbRightKey())
{
if (pitchX<10.0)
{
pitchX+=ANGLE;
//dbRollCameraRight(ANGLE);
dbRollObjectRight(1,ANGLE);
}
}
if (dbUpKey())
{
if (pitchY>-10.0)
{
pitchY-=ANGLE;
//dbPitchCameraDown(ANGLE);
dbPitchObjectDown(1,ANGLE);
}
}
else
if (dbDownKey())
{
if (pitchY<10.0)
{
pitchY+=ANGLE;
//dbPitchCameraUp(ANGLE);
dbPitchObjectUp(1,ANGLE);
}
}
bX-=(pitchX*0.25);
bZ+=(pitchY*0.25);
//
//
//i=dbGetGroundHeight(1,bX,bZ);
dbPointCamera(bX,bY,bZ);
{
char t[256];
float sizeZ,sizeX,sizeY,diff;
int s;
float dist[4];
s=dbObjectCollision(obj,0);
if (s)
{
sizeZ=dbObjectSizeZ(obj);
sizeX=dbObjectSizeX(obj);
sizeY=dbObjectSizeY(obj);
dist[0]=dbIntersectObject(s,bX,bY+sizeY,bZ+sizeZ,bX,-9999.0,bZ+sizeZ);
dist[1]=dbIntersectObject(s,bX,bY+sizeY,bZ-sizeZ,bX,-9999.0,bZ-sizeZ);
diff=dist[0]-dist[1];
if (diff<0) bY+=fabs(diff); else bY-=fabs(diff);
//bY+=(float) diff;
sprintf(t,"[%4.4f]/[%4.4f]/[%4.4f]",dist[0],dist[1],diff);
dbText(0,0,t);
}
}
dbPositionObject(obj,bX,bY,bZ);
dbPositionCamera(bX,(bY+30.0)+pitchY,bZ-75.0);
dbSync();
if(dbEscapeKey())return;
}
}