without comments:
#include "DarkGDK.h"
void DarkGDK ( void )
{ dbSyncOn ( );
dbSyncRate ( 30 );
int max = 12;
for (int i=1; i<=max; i++)
dbMakeObjectSphere ( i, 1,1,1);
dbMakeObjectBox ( max+1,.4,.4,.4);
dbMakeMeshFromObject(max+2,max+1);
for (int i = 0; i < max*6; i++)
{
int x = !((i )%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
int y = !((i + 2)%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
int z = !((i + 1)%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
dbAddLimb (((i - (i % 6))/6+1 ) ,i%6+1, max+2 ) ;
dbOffsetLimb(((i - (i % 6))/6+1 ) ,i%6+1,x,y,z);
}
dbDeleteObject(max+1), dbDeleteMesh(max+2);
dbPositionCamera ( 10, 10, -20 );
dbPointCamera (0,0,0);
while ( LoopGDK ( ) )
{
for ( int i = max ; i >= 2; i-- )
dbRotateObject (i, dbObjectAngleX ( i-1 ), dbObjectAngleY ( i-1 ), dbObjectAngleZ ( i-1 ) );
dbRotateObject (1, dbObjectAngleX ( 1 ) + 1, dbObjectAngleY ( 1 ) + 2, dbObjectAngleZ ( 1 ) + 4);
dbSync ( );
}
for ( int i = 1; i <= max; i++ )
dbDeleteObject ( i );
return;
}
with comments:
#include "DarkGDK.h"
void DarkGDK ( void )
{ dbSyncOn ( );
dbSyncRate ( 30 );
int max = 12; // number of cubes / axis
for (int i=1; i<=max; i++) // making the parent objects [id 1 tru max]
dbMakeObjectSphere (i,1,1,1);
dbMakeObjectBox ( max+1,.4,.4,.4); // our little box
dbMakeMeshFromObject(max+2,max+1); // a mesh of the little box
for (int i = 0; i < max*6; i++)
{ // coordinates to place the box ( could be written a bit more proccesor friendly)
// it basicly uses the % operator to deterimine axis, distance, and direction(sign)
int x = !((i )%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
int y = !((i + 2)%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
int z = !((i + 1)%3) * (((i-(i%3))/3%2)*-2+1) * ((i - (i % 6))/6+1 );
// add a limb to parent objects
dbAddLimb (((i - (i % 6))/6+1 ) ,i%6+1, max+2 ) ;
// moving the limbs
dbOffsetLimb(((i - (i % 6))/6+1 ) ,i%6+1,x,y,z);
}
// cleaning up the remaing object an mesh
dbDeleteObject(max+1), dbDeleteMesh(max+2);
// position the camera
dbPositionCamera ( 10, 10, -20 );
dbPointCamera (0,0,0);
while ( LoopGDK ( ) )
{
// form the outside we start copying the inner rotation values
for ( int i = max ; i >= 2; i-- )
dbRotateObject (i, dbObjectAngleX ( i-1 ), dbObjectAngleY ( i-1 ), dbObjectAngleZ ( i-1 ) );
// rotate the inner parent sphere
dbRotateObject (1, dbObjectAngleX ( 1 ) + 1, dbObjectAngleY ( 1 ) + 2, dbObjectAngleZ ( 1 ) + 4);
dbSync ( );
}
// cleaning up after the main loop
for ( int i = 1; i <= max; i++ )
dbDeleteObject ( i );
return;
}
I'm especialy pleased by the compact distribution of the small cubes, only using one for loop.
On my computer the parent spheres vannish automaticly. Perhaps because i gave them only one row and one collumn. (at first it was a box and i forgot to delete the extra parameters). So i suppose it is just one vertex in size.