static void bezier_split_up_down(VECTOR (*Patch)[4][4], VECTOR (*Bottom_Patch)[4][4], VECTOR (*Top_Patch)[4][4]) { int i, j; VECTOR Temp1[4], Temp2[4]; VECTOR Half; for (i = 0; i < 4; i++) { Assign_Vector(Temp1[0], (*Patch)[i][0]); VHalf(Temp1[1], (*Patch)[i][0], (*Patch)[i][1]); VHalf(Half, (*Patch)[i][1], (*Patch)[i][2]); VHalf(Temp1[2], Temp1[1], Half); VHalf(Temp2[2], (*Patch)[i][2], (*Patch)[i][3]); VHalf(Temp2[1], Half, Temp2[2]); VHalf(Temp1[3], Temp1[2], Temp2[1]); Assign_Vector(Temp2[0], Temp1[3]); Assign_Vector(Temp2[3], (*Patch)[i][3]); for (j = 0; j < 4; j++) { Assign_Vector((*Bottom_Patch)[i][j], Temp1[j]); Assign_Vector((*Top_Patch)[i][j] , Temp2[j]); } } }
static void bezier_split_left_right(VECTOR (*Patch)[4][4], VECTOR (*Left_Patch)[4][4], VECTOR (*Right_Patch)[4][4]) { int i, j; VECTOR Half; VECTOR Temp1[4], Temp2[4]; for (i = 0; i < 4; i++) { Assign_Vector(Temp1[0], (*Patch)[0][i]); VHalf(Temp1[1], (*Patch)[0][i], (*Patch)[1][i]); VHalf(Half, (*Patch)[1][i], (*Patch)[2][i]); VHalf(Temp1[2], Temp1[1], Half); VHalf(Temp2[2], (*Patch)[2][i], (*Patch)[3][i]); VHalf(Temp2[1], Half, Temp2[2]); VHalf(Temp1[3], Temp1[2], Temp2[1]); Assign_Vector(Temp2[0], Temp1[3]); Assign_Vector(Temp2[3], (*Patch)[3][i]); for (j = 0; j < 4; j++) { Assign_Vector((*Left_Patch)[j][i], Temp1[j]); Assign_Vector((*Right_Patch)[j][i], Temp2[j]); } } }
static DBL ground_fog(RAY *Ray, DBL Depth, DBL Width, FOG *Fog, COLOUR Colour) { DBL fog_density, delta; DBL start, end; DBL y1, y2, k; VECTOR P, P1, P2; /* Get start point. */ VEvaluateRay(P1, Ray->Initial, Depth, Ray->Direction); /* Get end point. */ VLinComb2(P2, 1.0, P1, Width, Ray->Direction); /* * Could preform transfomation here to translate Start and End * points into ground fog space. */ VDot(y1, P1, Fog->Up); VDot(y2, P2, Fog->Up); start = (y1 - Fog->Offset) / Fog->Alt; end = (y2 - Fog->Offset) / Fog->Alt; /* Get integral along y-axis from start to end. */ if (start <= 0.0) { if (end <= 0.0) { fog_density = 1.0; } else { fog_density = (atan(end) - start) / (end - start); } } else { if (end <= 0.0) { fog_density = (atan(start) - end) / (start - end); } else { delta = start - end; if (fabs(delta) > EPSILON) { fog_density = (atan(start) - atan(end)) / delta; } else { fog_density = 1.0 / (Sqr(start) + 1.0); } } } /* Apply turbulence. */ if (Fog->Turb != NULL) { VHalf(P, P1, P2); VEvaluateEq(P, Fog->Turb->Turbulence); /* The further away the less influence turbulence has. */ k = exp(-Width / Fog->Distance); Width *= 1.0 - k * min(1.0, Turbulence(P, Fog->Turb, NULL)*Fog->Turb_Depth); } Assign_Colour(Colour, Fog->Colour); return (exp(-Width * fog_density / Fog->Distance)); }