I have finished reworking 'groups'. Here is the example[GDK], you will see that there is not much difference but there is added flexibility.
//-- This example covers 'groups' and 'contact reports'. It also shows how to filter custom collision
//-- tests such as raycasts so you only check the groups that are required.
//-- There are two types of groups, 'shape' groups and 'actor' groups. Actor groups are orthogonal to shape groups.
//-- This can be a little confusing at first but provides great flexibility.
//-- In general, shape groups are used to allow filtering of custom collision tests
//-- such as raycasts etc. As well as disabling/enabling collisions between groups.
//-- Actor groups allow you to setup contact reports between a large number of different actor groups.
int boxStatic = 1;
int boxDynamic = 2;
int sphereDynamic = 3;
void initActorGroups();
void initShapeGroups();
void raycast();
void contacts();
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbPositionCamera ( 0, 10, -100 );
dbAutoCamOff();
//-- Create
dbMakeObjectBox(boxStatic, 100, 2, 200);
dbMakeObjectBox(boxDynamic, 5, 8, 5);
dbMakeObjectSphere(sphereDynamic, 10);
//-- Position
dbPositionObject(boxStatic, 0, -1, 0);
dbPositionObject(boxDynamic, 0, 20, 0);
dbPositionObject(sphereDynamic, 0, 25, -50);
//-- Colour
dbColorObject(boxStatic, dbRGB(255, 0, 0));
dbColorObject(boxDynamic, dbRGB(0, 255, 0));
dbColorObject(sphereDynamic, dbRGB(0, 0, 255));
//-- Physics
dynStart();
dynSetGravity(0, -9.8, 0);
dynSetParameter(NX_VISUALIZATION_SCALE, 1.0f);
dynSetParameter(NX_VISUALIZE_COLLISION_SHAPES, 1.0f);
//-- Create physics for objects.
dynMakeBox(boxStatic, 0);
dynMakeBox(boxDynamic, 10.0);
dynMakeSphere(sphereDynamic, 0.01);
//-- Initialise groups
initShapeGroups();
initActorGroups();
//-- Add force to sphere
dynAddForce(sphereDynamic, 0, 0, 5000);
dynSimulate();
while ( LoopGDK ( ) )
{
dynFetchResults();
dynUpdate();
raycast();
contacts();
dynDebugRender();
dynSimulate();
if ( dbUpKey ( ) )
dbMoveCamera ( 1 );
if ( dbDownKey ( ) )
dbMoveCamera ( -1 );
if(dbLeftKey()){
dbMoveCameraLeft(0, 1);
}
if(dbRightKey()){
dbMoveCameraRight(0, 1);
}
dbPointCamera(0, 0, 0);
dbSync ( );
}
dynFetchResults();
dynStop();
return;
}
void initActorGroups()
{
//---------------------------------//
//----Actor Groups (0 to 32767)----//
//---------------------------------//
//-- All actor groups will NOT generate contacts by default.
//-- All actors default to group 0.
//-- Set actors to different groups.
dynSetGroup(boxStatic, 256);
dynSetGroup(sphereDynamic, 346);
//-- Generate contacts between our actor groups .
dynGroupPairSetFlags(256, 346, NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_END_TOUCH | NX_NOTIFY_ON_TOUCH);
//-- Note: We can't disable group collisions at actor level the way we can at shape level.
//-- Disable collisions for specific pair of actors(nothing to do with groups)
//dynActorPairSetFlags(boxStatic, sphereDynamic, NX_IGNORE_PAIR);
//-- Set contacts for specific pair of actors(nothing to do with groups)
//dynActorPairSetFlags(boxStatic, sphereDynamic, NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_END_TOUCH | NX_NOTIFY_ON_TOUCH);
}
void initShapeGroups()
{
//------------------------------//
//-----Shape groups(0 - 31)-----//
//------------------------------//
//-- All shape groups will collide with all other groups by default.
//-- All actors default to group 0.
//-- Raycast commands can be filtered using shape groups to avoid unnecessary checks.
//-- Here we place shapes in different groups.
dynSetShapeGroup(boxStatic, 0, 1 );
dynSetShapeGroup(boxDynamic, 0, 25 );
dynSetShapeGroup(sphereDynamic, 0, 31 );
//-- We can also disable collisions between shape groups
//dynGroupSetCollision(1, 25, false);
//-- We can turn off collisions for a specific pair of shapes.
//dynShapePairSetFlags(boxStatic, 0, sphereDynamic, 0, NX_IGNORE_PAIR);
//-- NOTE: We can't manipulate contact reports at shape level as we can with actor pairs.
}
void raycast()
{
//-- RAYCAST
int rayOriginVec3 = 1;
int rayDirectionVec3 = 2;
dbMakeVector3( rayOriginVec3 );
dbMakeVector3( rayDirectionVec3 );
//-- Ray originates just above ground level and set back along the z axis.
dbSetVector3(rayOriginVec3, 0, 2.5, -50);
//-- Ray direction is forward along the z axis.
dbSetVector3(rayDirectionVec3, 0, 0, 1);
//-- Simple raycast, simple but not optimised.
//dynRaycastAllShapes(rayOriginVec3, rayDirectionVec3);
//-- Advanced raycast, optimised since we are narrowing down the amount of shapes that will be tested.
//-- We test for just dynamic shapes in any of our 3 groups.
dynRaycastAllShapes(rayOriginVec3, rayDirectionVec3, NX_DYNAMIC_SHAPES, 1<<1 | 1<<25 | 1<<31);
int y = 0;
dbText(0, y, "RAYCAST RESULTS:");
y += 15;
char* buf;
while(dynRaycastHitGetData())
{
int x = 0;
dbText(x, y, "Object: ");
x += 75;
int hitObject = dynRaycastHitGetObject();
buf = dbStr(hitObject);
dbText(x, y, buf);
delete[]buf;
y += 15;
x = 0;
dbText(x, y, "Distance: ");
x += 75;
float distance = dynRaycastHitGetDistance();
buf = dbStr(distance);
dbText(x, y, buf);
delete[]buf;
y += 15;
}
dbDeleteVector3( rayOriginVec3 );
dbDeleteVector3( rayDirectionVec3 );
}
void contacts()
{
int y = 0;
int x = 400;
dbText(x, y, "CONTACT REPORTS: ");
y += 15;
char* buf;
while(dynContactGetData()){
x = 400;
dbText(x, y, "Object: ");
x += 75;
int objA = dynContactGetActorA();
buf = dbStr(objA);
dbText(x, y, buf);
delete[]buf;
y += 15;
x = 400;
dbText(x, y, "Object: " );
x += 75;
int objB = dynContactGetActorB();
buf = dbStr(objB);
dbText(x, y, buf);
delete[]buf;
y+=15;
x = 400;
dbText(x, y, "Flag: ");
x += 75;
int flag = dynContactGetFlag();
buf = dbStr(flag);
dbText(x, y, buf);
delete[]buf;
y += 30;
}
}
Getting pretty close to finishing what is currently on the todo list in the first post.