Here's the example:
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(0);
dbAutoCamOff();
dbMakeObjectCube(1, 1.3f);
for (int i = 2; i < 100; ++i)
{
dbInstanceObject(i, 1);
dbPositionObject(i, 0.0, 0.0, i * 2.0f);
}
// Set up the cameras farthest to nearest
dbPositionCamera(0, 1.0, 0.0, 0.0);
dbPointCamera(0, 1.0, 0.0, 10.0);
dbSetCameraRange(0, 100.0f, 33300.0f); // <- Ratio is ~1:333
dbMakeCamera(1);
dbPositionCamera(1, 1.0, 0.0, 0.0);
dbPointCamera(1, 1.0, 0.0, 10.0);
dbSetCameraRange(1, 0.3f, 100.0f); // <- Ratio is ~1:333
// Only leave the backdrop of the main camera active
dbBackdropOff(1);
float x = dbCameraPositionX(0);
int ShowFar = 0;
while ( LoopGDK ( ) )
{
// Make everything that will be rendered to the far camera blink on and off
for (int i = 1; i < 100; ++i)
{
if (dbObjectPositionZ(i) >= 100.0f)
{
if (ShowFar < 10)
dbShowObject(i);
else
dbHideObject(i);
}
}
++ShowFar;
if (ShowFar >= 20)
ShowFar = 0;
// Simple move left/right
if (dbLeftKey() && x > -30.0f)
x -= 0.5f;
if (dbRightKey() && x < 30.0f)
x += 0.5f;
dbPositionCamera(0, x, dbCameraPositionY(0), dbCameraPositionZ(0));
// Cameras must be in the same position & rotation
dbPositionCamera(1, dbCameraPositionX(0), dbCameraPositionY(0), dbCameraPositionZ(0));
dbRotateCamera(1, dbCameraAngleX(0), dbCameraAngleY(0), dbCameraAngleZ(0));
// Render
dbSync();
}
}
Things to remember:
- The cameras are rendered in sequence, so you need to arrange your camera ranges from far to near.
- If you need the backdrop, make sure it's enabled only for the first camera rendered.
You can't multithread this in its current state - it requires the cameras to be rendered sequentially, finishing one before starting another.
It might be possible to multithread rendering in general as long as you render each camera range to its own texture and then combine the textures into a final render at the end. Not sure how you'd go about that in the GDK though.