[Add] Ejecta crater flavour. ^.^

This commit is contained in:
Rtch90 2017-11-25 13:03:32 +00:00
parent 849c723d6a
commit 8b8f2606ca

View File

@ -433,11 +433,12 @@ static void SubdivideVeryLongTri(vector3d& tip, vector3d& v1, vector3d& v2, int
glEnd(); glEnd();
} }
static int exp2i(int foo) { int n = 2; while(--foo) n*=2; return n; }
static void MakeContinent(matrix4x4d& rot, float scale, MTRand& rng) { static void MakeContinent(matrix4x4d& rot, float scale, MTRand& rng) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
const int nvps = exp2(GEOSPLIT); const int nvps = exp2i(GEOSPLIT);
const int numVertices = nvps*3 + 1; const int numVertices = nvps*3 + 1;
/* /*
* This is a continent centered on the north pole, of size roughly 45 * This is a continent centered on the north pole, of size roughly 45
@ -478,6 +479,7 @@ void DrawCircle(float rad) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
glNormal3d(0, 1, 0);
glVertex3d(0, 1, 0); glVertex3d(0, 1, 0);
for(double theta = 0; theta < M_PI * 2; theta += 0.1) { for(double theta = 0; theta < M_PI * 2; theta += 0.1) {
vector3d v(rad*sin(theta), 1, rad*cos(theta)); vector3d v(rad*sin(theta), 1, rad*cos(theta));
@ -498,6 +500,43 @@ void DrawCircle(float rad) {
glPopAttrib(); glPopAttrib();
} }
/* Draws at north pole. */
static void DrawEjecta(float rad1, float rad2, int points) { /* That's a star shape. */
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
double step = 2*M_PI/points;
for(int p = 0; p < points; p++) {
double ang0 = step*p;
double ang1 = step*(p+1);
double ang2 = (ang0+ang1)*.5;
vector3d v1(rad1*sin(ang0), 1, rad1*cos(ang0));
vector3d v2(rad2*sin(ang2), 1, rad2*cos(ang2));
vector3d v3(rad1*sin(ang1), 1, rad1*cos(ang1));
v1.Normalize();
v2.Normalize();
v3.Normalize();
SubdivideVeryLongTri(v2, v3, v1, 6);
glBegin(GL_TRIANGLES);
/* Tri to center. */
glNormal3dv(&v1.x);
glVertex3dv(&v1.x);
glNormal3dv(&v3.x);
glVertex3dv(&v3.x);
glNormal3d(0, 1, 0);
glVertex3d(0, 1, 0);
glEnd();
}
glDisable(GL_BLEND);
glDisable(GL_NORMALIZE);
glPopAttrib();
}
/* Draws at north pole. */ /* Draws at north pole. */
void DrawHollowCircle(float rad1, float rad2) { void DrawHollowCircle(float rad1, float rad2) {
glPushAttrib(GL_DEPTH_BUFFER_BIT); glPushAttrib(GL_DEPTH_BUFFER_BIT);
@ -532,21 +571,21 @@ void DrawHollowCircle(float rad1, float rad2) {
void Planet::DrawRockyPlanet(void) { void Planet::DrawRockyPlanet(void) {
int n; int n;
float r; float r, tmp;
matrix4x4d rot; matrix4x4d rot;
float col[4]; float col[4], col2[4];
//MTRand rng((int)L3D::GetGameTime()); //MTRand rng((int)L3D::GetGameTime());
MTRand rng(sbody.seed); MTRand rng(sbody.seed);
float blue[4] = { .2, .2, 1, 1 }; float blue[4] = { .2, .2, 1, 1 };
float green[4] = { .2, .8, .2, 1 }; float green[4] = { .2, .8, .2, 1 };
float white[4] = { 1, 1, 1, 1 }; float white[4] = { 1, 1, 1, 1 };
ColRangeObj_t barrenBodyCol = { { .3, .3, .3, 1 }, { 0, 0, 0, 0 }, .3 }; ColRangeObj_t barrenBodyCol = { { .3, .3, .3, 1 }, { 0, 0, 0, 0 }, .3 };
ColRangeObj_t barrenContCol = { { .2, .2, .2, .6 }, { 0, 0, 0, 0 }, .3 }; ColRangeObj_t barrenContCol = { { .2, .2, .2, 1 }, { 0, 0, 0, 0 }, .3 };
switch(sbody.type) { switch(sbody.type) {
case StarSystem::TYPE_PLANET_DWARF: case StarSystem::TYPE_PLANET_DWARF:
barrenBodyCol.GenCol(col, rng); barrenBodyCol.GenCol(col2, rng);
SetMaterialColor(col); SetMaterialColor(col2);
DrawLovelyRoundCube(1.0f); DrawLovelyRoundCube(1.0f);
n = rng(3, 10); n = rng(3, 10);
@ -555,26 +594,36 @@ void Planet::DrawRockyPlanet(void) {
while(n--) { while(n--) {
rot = matrix4x4d::RotateXMatrix(rng(M_PI/2)); rot = matrix4x4d::RotateXMatrix(rng(M_PI/2));
rot.RotateZ(rng(M_PI*2)); rot.RotateZ(rng(M_PI*2));
MakeContinent(rot, rng.drange(0.1, 0.5), rng); MakeContinent(rot, rng.drange(0.05, 0.2), rng);
} }
n = rng(10, 30); SetMaterialColor(col);
n = rng(50, 100);
printf("%d\n", n);
while(n--) { while(n--) {
barrenContCol.GenCol(col, rng);
r = rng.drange(0.02, 0.1); r = rng.drange(0.02, 0.1);
glPushMatrix(); glPushMatrix();
glRotatef(rng.drange(0, 360), 1, 0, 0); vector3d rx(rng(1.0)-.5, rng(1.0)-.5, rng(1.0)-.5);
glRotatef(rng.drange(0, 360), 0, 0, 1); rx.Normalize();
DrawCircle(r); glRotatef(rng.drange(0, 360), rx.x, rx.y, rx.z);
glPopMatrix();
}
n = rng(10, 30); tmp = rng(1.0);
while(n--) { if(tmp < .46) {
r = rng.drange(0.02, 0.2); DrawCircle(r);
glPushMatrix(); } else if(tmp < .92) {
glRotatef(rng.drange(0, 360), 1, 0, 0); //DrawHollowCircle(r, r*1.3);
glRotatef(rng.drange(0, 360), 0, 0, 1); DrawCircle(r*1.3);
DrawHollowCircle(r, r*1.3); /* Uh.. Yeah. */
SetMaterialColor(col2);
DrawCircle(r);
SetMaterialColor(col);
} else {
SetMaterialColor(col);
DrawEjecta(r*0.6, 3*r, 6);
SetMaterialColor(col2);
DrawCircle(r*0.4);
}
glPopMatrix(); glPopMatrix();
} }
break; break;