| 423 | float GetMaxColor(spectra *sp); |
| 424 | |
| 425 | float GetFormFactorForElementAndSatellite(rad_surface *dest_surf, rad_element *dest_element, vector *src_center) { |
| 426 | vector dest_center; |
| 427 | vector light_center = *src_center; |
| 428 | float form_factor = 0.0; |
| 429 | |
| 430 | if (Ignore_satellites) |
| 431 | return 0; |
| 432 | |
| 433 | // Bash src center to first element vertex (if sun or moon) |
| 434 | light_center = rad_MaxSurface->elements[0].verts[0]; |
| 435 | |
| 436 | for (int j = 0; j < dest_element->num_verts; j++) { |
| 437 | dest_center = dest_element->verts[j]; |
| 438 | dest_center += (dest_surf->normal / 32.0); |
| 439 | float temp_factor = 0; |
| 440 | |
| 441 | int hit = 0; |
| 442 | vector ray = light_center - dest_center; |
| 443 | |
| 444 | if (dest_surf->surface_type != ST_TERRAIN) { |
| 445 | if ((vm_DotProduct(&ray, &dest_surf->normal)) < 0) |
| 446 | continue; |
| 447 | } |
| 448 | |
| 449 | // If this surface is a terrain surface, use the terrain speedup table |
| 450 | if (dest_surf->surface_type == ST_TERRAIN) { |
| 451 | ASSERT(ROOMNUM_OUTSIDE(dest_surf->roomnum)); |
| 452 | int cellnum = CELLNUM(dest_surf->roomnum); |
| 453 | if (dest_surf->facenum == 0) { |
| 454 | if (j == 1) |
| 455 | cellnum += TERRAIN_WIDTH; |
| 456 | else if (j == 2) |
| 457 | cellnum += (TERRAIN_WIDTH + 1); |
| 458 | } else { |
| 459 | if (j == 1) |
| 460 | cellnum += (TERRAIN_WIDTH + 1); |
| 461 | else if (j == 2) |
| 462 | cellnum++; |
| 463 | } |
| 464 | |
| 465 | hit = TerrainLightSpeedup[rad_MaxSurface->roomnum][cellnum]; |
| 466 | } else |
| 467 | hit = ShootRayFromPoint(&light_center, &dest_center, rad_MaxSurface, dest_surf); |
| 468 | |
| 469 | if (hit) { |
| 470 | float ray_length = vm_GetMagnitude(&ray); |
| 471 | vector dest_norm_ray = ray / ray_length; |
| 472 | vector dest_normal = dest_surf->normal; |
| 473 | float ff; |
| 474 | |
| 475 | ff = vm_DotProduct(&dest_normal, &dest_norm_ray); |
| 476 | |
| 477 | if (ff > 0) |
| 478 | temp_factor += ff; |
| 479 | } |
| 480 | |
| 481 | form_factor += temp_factor; |
| 482 | } |
no test coverage detected