MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SetupSky

Function SetupSky

Descent3/terrain.cpp:674–792  ·  view source on GitHub ↗

Compute a parametric sphere for our sky.

Source from the content-addressed store, hash-verified

672
673// Compute a parametric sphere for our sky.
674void SetupSky(float radius, int flags, uint8_t randit) {
675 int jump = 65536 / MAX_HORIZON_PIECES;
676 int top = ((65536 / 4) * 3) + (65536 / 8);
677
678 int i, t;
679
680 Terrain_sky.radius = radius;
681 Terrain_sky.flags = flags;
682
683 int horizon_r = GR_COLOR_RED(Terrain_sky.horizon_color);
684 int horizon_g = GR_COLOR_GREEN(Terrain_sky.horizon_color);
685 int horizon_b = GR_COLOR_BLUE(Terrain_sky.horizon_color);
686
687 float rad_diff = radius - SKY_RADIUS;
688
689 // Figure out where our points in the inside of the sphere are
690 for (i = 0; i < 6; i++) {
691 const int increment = 16384 / 5;
692 const angle pitch = (65536 - 16384) + (i * increment);
693
694 for (t = 0; t < MAX_HORIZON_PIECES; t++) {
695 vector *vec = &Terrain_sky.horizon_vectors[t][i];
696
697 matrix tempm;
698 vm_AnglesToMatrix(&tempm, pitch, t * jump, 0);
699 vm_ScaleVector(vec, &tempm.fvec, SKY_RADIUS / 2);
700
701 vec->y -= MAX_TERRAIN_HEIGHT;
702 vec->y += (rad_diff / 4);
703 }
704 }
705
706 // Now figure out texture UVS
707 for (i = 0; i < 5; i++) {
708 float scalar = (float)i / 4.0;
709 int angle_increment = 65536 / MAX_HORIZON_PIECES;
710 for (t = 0; t < MAX_HORIZON_PIECES; t++) {
711 float cur_sin = FixSin(t * angle_increment) * scalar;
712 float cur_cos = FixCos(t * angle_increment) * scalar;
713
714 cur_sin = (cur_sin + 1) / 2;
715 cur_cos = (cur_cos + 1) / 2;
716
717 Terrain_sky.horizon_u[t][i] = cur_cos;
718 Terrain_sky.horizon_v[t][i] = cur_sin;
719 }
720 }
721
722 int highcount = 0; // keep track of what stars are close to the top of the sphere
723 // don't draw too many of them
724 if (!randit)
725 return;
726
727 for (i = 0; i < MAX_STARS; i++) {
728 vector starvec;
729 matrix tempm;
730 int p;
731 top = ((65536 / 4) * 3);

Callers 5

OnSkyNearerMethod · 0.85
OnSkyFartherMethod · 0.85
OnTerrRandomizeSkyMethod · 0.85
InitTerrainFunction · 0.85

Calls 9

GR_COLOR_REDFunction · 0.85
GR_COLOR_GREENFunction · 0.85
GR_COLOR_BLUEFunction · 0.85
ps_randFunction · 0.85
vm_AnglesToMatrixFunction · 0.50
vm_ScaleVectorFunction · 0.50
FixSinFunction · 0.50
FixCosFunction · 0.50
GR_RGBFunction · 0.50

Tested by

no test coverage detected