This will get you started - its not CAMERA Collision, but sparky is working.
I did notice a glitch - but I think its because at certain angles the Eular reports 180degree opposite where you want to be - also I KNOW sometimes OBJECT's and CAMERA's don't report correct Angles intermittantly, and this can usually be squelched by rotating on a different axis than the one you just turned on.. like if turned left, look up, then down, maybe left then right.
Stupid I know - but its intermittant and might exmplain the ocassion "FLASH" where it seems like you did a 180 turn for ONE frame.
anyways...try this:
#include "SC_Collision.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
SC_Start( );
// Walls.
dbMakeObjectBox(1, 100, 100, 16);
dbMakeObjectBox(2, 100, 100, 16);
dbPositionObject(1, 50, 50, 100);
dbPositionObject(2, 200, 50, 50);
SC_SetupObject(1, 1, 2); // Groups other than ZERO for stuff you hit
SC_SetupObject(2, 1, 2); // reserve ZERO for your player :)
// I think this is a good idea - I'm not sure you can have a group item hit something
// in the same group. That MIGHT be an issue you came across and didn't know it.
// Player.
dbMakeObjectCube(3, 32);
dbPositionObject(3, 0, 16, 0);
SC_SetupObject(3, 2, 2);
// Camera Object.
//dbMakeObjectCube(4, 100);
//dbHideObject(4);
//SC_SetupObject(4, 0, 2);
// Old Values. (More Efficient I THINK declaring up here).
// maybe no difference seeing how SCOPE didn;t change... anyways...
float ox;
float oy;
float oz;
float oax;
float oay;
float oaz;
int iCollideID=0;
while ( LoopGDK ( ) )
{
//float ay = dbObjectAngleY(3);
// Old Values.
//ox = dbCameraPositionX();
//oy = dbCameraPositionY();
//oz = dbCameraPositionZ();
ox =dbObjectPositionX(3);
oy =dbObjectPositionY(3);
oz =dbObjectPositionZ(3);
oax = dbObjectAngleX(3);
oay = dbObjectAngleY(3);
oaz = dbObjectAngleZ(3);
// I move the player.
if (dbUpKey() == 1)
{
dbMoveObject(3, 1.0);
}
if (dbDownKey() == 1)
{
dbMoveObject(3, -1.0);
}
if (dbLeftKey() == 1)
{
//dbYRotateObject(3, oy + 1.0);
dbTurnObjectLeft(3,1.0);
}
if (dbRightKey() == 1)
{
//dbYRotateObject(3, oy - 1.0);
dbTurnObjectRight(3,1.0);
}
SC_UpdateObject(3);
iCollideID = SC_GroupCollision(3,1);// your Box, and Group 1
if(iCollideID>0){
dbPositionObject(3,ox,oy,oz);
dbRotateObject(3,oax,oay,oaz);
};
dbPositionCamera(dbObjectPositionX(3),dbObjectPositionY(3),dbObjectPositionZ(3));
dbRotateCamera(dbObjectAngleX(3),dbObjectAngleY(3),dbObjectAngleZ(3));
dbMoveCamera(-160);
dbPitchCameraUp(90);
dbMoveCamera(40);
dbPointCamera(dbObjectPositionX(3),dbObjectPositionY(3),dbObjectPositionZ(3));
// I move the Camera Object.
//float cz = dbNewZValue(dbObjectPositionZ(3), dbWrapValue(ay + 180), 100);
//float cx = dbNewXValue(dbObjectPositionX(3), dbWrapValue(ay + 180), 100);
//dbPositionObject(4, cx, dbObjectPositionY(3) + 30, cz);
//dbRotateObject(4, dbObjectAngleX(3), dbObjectAngleY(3), dbObjectAngleZ(3));
// Camera Object collision.
//if (dbObjectCollision(4, 0) > 0)
//{
// dbPositionObject(4, ox, oy, oz);
// dbRotateObject(4, oax, oay, oaz);
//}
// I place the camera.
//dbPositionCamera(dbObjectPositionX(4), dbObjectPositionY(4), dbObjectPositionZ(4));
//dbRotateCamera(dbObjectAngleX(4), dbObjectAngleY(4), dbObjectAngleZ(4));
dbSetCursor(0,0);
dbPrint(dbStr(iCollideID));
dbSync ( );
}
return;
}