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

Function GetTerrainDynamicScalar

Descent3/terrainrender.cpp:901–940  ·  view source on GitHub ↗

Gets the dynamic light value for this position

Source from the content-addressed store, hash-verified

899}
900// Gets the dynamic light value for this position
901float GetTerrainDynamicScalar(vector *pos, int seg) {
902 float cube_values[10];
903 int y_increment = MAX_TERRAIN_HEIGHT / 8;
904 int y_int = pos->y / y_increment;
905 int x_int = pos->x / TERRAIN_SIZE;
906 int z_int = pos->z / TERRAIN_SIZE;
907
908 float x_norm = (pos->x / TERRAIN_SIZE) - x_int;
909 float z_norm = (pos->z / TERRAIN_SIZE) - z_int;
910 float y_norm = (pos->y / y_increment) - y_int;
911 if (y_norm < 0) {
912 y_norm = 0;
913 y_int = 0;
914 }
915 if (y_norm > 1) {
916 y_norm = 1.0;
917 y_int = 7;
918 }
919 if (x_norm < 0 || x_norm > 1 || z_norm < 0 || z_norm > 1)
920 return .5;
921 float left_norm, right_norm, top_norm, bottom_norm, scalar;
922
923 cube_values[0] = IsTerrainDynamicChecked(seg, y_int);
924 cube_values[1] = IsTerrainDynamicChecked(seg + TERRAIN_WIDTH, y_int);
925 cube_values[2] = IsTerrainDynamicChecked(seg + TERRAIN_WIDTH + 1, y_int);
926 cube_values[3] = IsTerrainDynamicChecked(seg + 1, y_int);
927 cube_values[4] = IsTerrainDynamicChecked(seg, y_int + 1);
928 cube_values[5] = IsTerrainDynamicChecked(seg + TERRAIN_WIDTH, y_int + 1);
929 cube_values[6] = IsTerrainDynamicChecked(seg + TERRAIN_WIDTH + 1, y_int + 1);
930 cube_values[7] = IsTerrainDynamicChecked(seg + 1, y_int + 1);
931 left_norm = ((1 - z_norm) * cube_values[0]) + (z_norm * cube_values[1]);
932 right_norm = ((1 - z_norm) * cube_values[3]) + (z_norm * cube_values[2]);
933 bottom_norm = ((1 - x_norm) * left_norm) + (x_norm * right_norm);
934 left_norm = ((1 - z_norm) * cube_values[4]) + (z_norm * cube_values[5]);
935 right_norm = ((1 - z_norm) * cube_values[7]) + (z_norm * cube_values[6]);
936 top_norm = ((1 - x_norm) * left_norm) + (x_norm * right_norm);
937 scalar = ((1 - y_norm) * bottom_norm) + (y_norm * top_norm);
938 ASSERT(scalar >= 0 && scalar <= 1);
939 return scalar;
940}
941// Takes a min,max vector and makes a surrounding cube from it
942void MakePointsFromMinMax(vector *corners, vector *minp, vector *maxp);
943struct obj_sort_item {

Callers 3

RenderCockpitFunction · 0.85
SetupTerrainObjectFunction · 0.85
DoPlayerFrameForOneFunction · 0.85

Calls 1

IsTerrainDynamicCheckedFunction · 0.85

Tested by

no test coverage detected