25 void Print(
const char* ftm, ...);
39 for (
int i = 0; i < nstars; i++) {
52 strcpy_s(
name,
"Stars");
89 static const double BOUNDARY = 3000;
90 static const double BOUNDARYx2 = BOUNDARY * 2;
93 : really_hidden(false), bright(b)
95 radius = (float) BOUNDARYx2;
100 strcpy_s(
name,
"Dust");
119 Random(-BOUNDARY, BOUNDARY),
120 Random(-BOUNDARY, BOUNDARY) );
123 c = (BYTE)
Random(96,200);
125 c = (BYTE)
Random(64,156);
145 double dlen = delta.
length();
150 if (dlen > BOUNDARY) {
160 if (v.
x > BOUNDARY) v.
x -= (float) BOUNDARYx2;
161 if (v.
x < -BOUNDARY) v.
x += (float) BOUNDARYx2;
162 if (v.
y > BOUNDARY) v.
y -= (float) BOUNDARYx2;
163 if (v.
y < -BOUNDARY) v.
y += (float) BOUNDARYx2;
164 if (v.
z > BOUNDARY) v.
z -= (float) BOUNDARYx2;
165 if (v.
z < -BOUNDARY) v.
z += (float) BOUNDARYx2;
214 double rad,
const Vec3& pos,
double tscale,
215 const char* rngname,
double minrad,
double maxrad,
216 Color atmos,
const char* gloss_name)
217 : mtl_surf(0), mtl_limb(0), mtl_ring(0), star_system(0)
231 if (!surface_name || !*surface_name) {
232 Print(
" invalid Planet patch - no surface texture specified\n");
236 Print(
" constructing Planet patch %s\n", surface_name);
237 strncpy(
name, surface_name, 31);
249 if (glow_name && *glow_name) {
250 Print(
" loading glow texture %s\n", glow_name);
254 if (gloss_name && *gloss_name) {
255 Print(
" loading gloss texture %s\n", gloss_name);
272 if (glow_name && strstr(glow_name,
"light"))
286 Print(
" loading atmospheric limb texture PlanetLimb.pcx\n");
292 if (maxrad > 0 && minrad > 0) {
309 if (rad > 2e6 && rad < 1e8)
325 double minrad,
double maxrad,
int rsections,
328 const int sect_verts = nsections + 1;
337 int npolys = (nrings + 2) * nsections;
338 int nverts = (nrings + 3) * sect_verts;
358 npolys += rsections * 3;
359 nverts += rsections * 6;
368 if (!vset || vset->
nverts < nverts) {
369 ::Print(
"WARNING: insufficient memory for planet '%s'\n",
name);
376 ::Print(
"WARNING: insufficient memory for planet '%s'\n",
name);
380 ZeroMemory(polys,
sizeof(
Poly) * npolys);
383 double dtheta =
PI / (nrings + 2);
384 double dphi = 2 *
PI / nsections;
388 for (i = 0; i < nrings+3; i++) {
389 double y = radius * cos(theta);
390 double v = theta /
PI;
391 double rsintheta = radius * sin(theta);
394 for (j = 0; j < sect_verts; j++) {
395 double x = rsintheta * sin(phi);
396 double z = rsintheta * cos(phi);
400 vset->
tu[n] = (float) (tscale * (1 - (phi/(2.0*
PI))));
401 vset->
tv[n] = (float) (tscale * v);
416 double dphi = 2.0 *
PI / rsections;
421 for (j = 0; j < rsections; j++) {
422 double x = minrad * sin(phi);
423 double z = minrad * cos(phi);
427 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
431 x = maxrad * sin(phi);
432 z = maxrad * cos(phi);
436 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
445 for (j = 0; j < rsections; j++) {
446 double x = minrad * sin(phi);
447 double z = minrad * cos(phi);
451 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
455 x = maxrad * sin(phi);
456 z = maxrad * cos(phi);
460 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
469 for (j = 0; j < rsections; j++) {
470 double x = maxrad * sin(phi);
471 double z = maxrad * cos(phi);
476 double thickness = maxrad/333;
478 vset->
loc[n] =
Vec3(x, y+thickness, z);
479 vset->
nrm[n] = normal;
480 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
484 vset->
loc[n] =
Vec3(x, y-thickness, z);
485 vset->
nrm[n] = normal;
486 vset->
tu[n] = (j & 1) ? 1.0f : 0.0f;
494 for (i = 0; i < npolys; i++) {
501 for (i = 0; i < nsections; i++) {
504 p0.
verts[1] = sect_verts + i;
505 p0.
verts[0] = sect_verts + ((i+1) % sect_verts);
507 Poly& p1 = polys[ppolys - nsections + i];
508 p1.
verts[2] = pverts - 1 - i;
509 p1.
verts[1] = pverts - 1 - sect_verts - i;
510 p1.
verts[0] = pverts - 2 - sect_verts - i;
519 for (i = 0; i < nrings; i++) {
520 for (j = 0; j < nsections; j++) {
524 p0.
verts[2] = m + (sect_verts) + j;
525 p0.
verts[1] = m + (sect_verts) + ((j + 1) % (sect_verts));
526 p0.
verts[0] = m + ((j + 1) % (sect_verts));
536 for (i = 0; i < pverts; i++) {
537 vset->
loc[averts + i] = vset->
loc[i];
538 vset->
nrm[averts + i] = vset->
nrm[i];
541 for (i = 0; i < ppolys; i++) {
543 Poly& p1 = polys[apolys + i];
564 for (j = 0; j < rsections; j++) {
569 p0.
verts[3] = m + 2*j;
570 p0.
verts[2] = m + 2*j + 1;
571 p0.
verts[1] = m + ((2*j + 3) % (rsections*2));
572 p0.
verts[0] = m + ((2*j + 2) % (rsections*2));
583 for (j = 0; j < rsections; j++) {
588 p0.
verts[0] = m + 2*j;
589 p0.
verts[1] = m + 2*j + 1;
590 p0.
verts[2] = m + ((2*j + 3) % (rsections*2));
591 p0.
verts[3] = m + ((2*j + 2) % (rsections*2));
602 for (j = 0; j < rsections; j++) {
607 p0.
verts[3] = m + 2*j;
608 p0.
verts[2] = m + 2*j + 1;
609 p0.
verts[1] = m + ((2*j + 3) % (rsections*2));
610 p0.
verts[0] = m + ((2*j + 2) % (rsections*2));
621 for (n = 0; n < npolys; n++) {
622 Poly& poly = polys[n];
631 segment =
new(__FILE__,__LINE__)
Segment;
634 segment->
polys = &polys[n];
647 bool treat_translucent_polys_as_solid)
650 Point dst = Q + w*len;
655 double dlen = d1.
length();
661 Point d2 = Q + w * (d0 * w);
666 if (delta0.length() >
radius) {
668 Point delta1 = d2 - Q;
669 Point delta2 = dst - Q;
672 if (delta1 * delta2 < 0 ||