Well, I got something to happen, but I think I murdered it.
void CreatePlanetModel(int planet_seed, float earth_relative_size, int iteration_limit, int is_there_water, float x, float y, float z, float water_level, int lod)
{
earth_relative_size = 6371000 / earth_relative_size; // earth-standard.
water_level = 6371000 / water_level;
int num = FreeObject(1000);
int water = FreeObject(2000);
dbMakeObjectSphere(num, earth_relative_size, lod, lod);
dbMakeMeshFromObject(1, num);
dbMakeMemblockFromMesh(1, 1);
dbDeleteObject(num);
int number_of_vertices = dbGetMemblockSize(1)/32;
dbRandomize(planet_seed);
int iter = 0;
while (iter <= iteration_limit)
{
int nx;
int ny;
int nz;
if (dbRnd(1) == 0)
nx = -1;
else
nx = 1;
if (dbRnd(1) == 0)
ny = -1;
else
ny = 1;
if (dbRnd(1) == 0)
nz = -1;
else
nz = 1;
int n = 1;
dbMakeVector3(n);
dbSetVector3(n, nx, ny, nz);
dbRandomize(dbTimer());
int m;
if (dbRnd(1) == 1)
{
m = 1;
}
else
{
m = -1;
}
int vertex_num = 1;
while (iter <= number_of_vertices)
{
int p = 32;
dbMakeVector3(p);
dbSetVector3(p, dbMemblockFloat(1, vertex_num + (4 * vertex_num - 1) + (32 * vertex_num - 1)), dbMemblockFloat(1, vertex_num + (8 * vertex_num - 1) + (32 * vertex_num - 1)), dbMemblockFloat(1, vertex_num + (12 * vertex_num - 1) + (32 * vertex_num - 1)));
int v = 3;
dbMakeVector3(v);
dbSubtractVector3(v, p, n);
float d = dbDotProductVector3(n, v);
if (d > 0)
{
dbNormalizeVector3(p, p);
dbScaleVector3(p, p, m);
}
else
{
dbNormalizeVector3(p, p);
dbScaleVector3(p, p, -m);
}
dbWriteMemblockFloat(1, vertex_num + (4 * vertex_num - 1) + (32 * vertex_num - 1), dbXVector3(p));
dbWriteMemblockFloat(1, vertex_num + (8 * vertex_num - 1) + (32 * vertex_num - 1), dbYVector3(p));
dbWriteMemblockFloat(1, vertex_num + (12* vertex_num - 1) + (32 * vertex_num - 1), dbZVector3(p));
//dbChangeMeshFromMemblock(1, 1);
iter++;
vertex_num++;
}
}
dbChangeMeshFromMemblock(1, 1);
//this is where you customize stuff.
dbMakeObject(num, 1, 0);
dbPositionObject(num, x, y, z);
if (is_there_water == 1)
{
dbMakeObjectSphere(water, water_level, lod, lod);
//do texture/shader crap here too.
dbPositionObject(water, x, y, z);
}
}