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

Function GetFormFactorForElement

editor/rad_cast.cpp:570–690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570float GetFormFactorForElement(rad_surface *dest_surf, rad_element *dest_element, vector *src_center) {
571 int touched = 0;
572 vector dest_center;
573 int i, limit;
574 float ray_area;
575 int ignored = 0;
576 vector light_center = *src_center;
577 float form_factor = 0.0;
578 int multiple_shoots = 0;
579
580 ray_area = rad_MaxSurface->area;
581
582 float rmax = GetMaxColor(&rad_MaxSurface->exitance);
583
584 multiple_shoots = 0;
585 limit = 1;
586
587 for (i = 0; i < limit; i++) {
588 float temp_factor = 0.0;
589
590 if (multiple_shoots && (rad_MaxSurface->elements[i].flags & EF_IGNORE))
591 continue;
592
593 if (multiple_shoots) {
594 GetCenterOfElement(&rad_MaxSurface->elements[i], &light_center);
595 light_center += (rad_MaxSurface->normal / 16.0);
596 ray_area = rad_MaxSurface->elements[i].area;
597 } else
598 ray_area = rad_MaxSurface->area;
599
600 GetCenterOfElement(dest_element, &dest_center);
601 dest_center += (dest_surf->normal / 16.0);
602
603 int hit = 0;
604 vector ray = light_center - dest_center;
605 vector revray = dest_center - light_center;
606
607 if ((vm_DotProduct(&ray, &dest_surf->normal)) < 0)
608 continue;
609 if ((vm_DotProduct(&revray, &rad_MaxSurface->normal)) < 0)
610 continue;
611
612 // Check to see if this ray even matters
613 float ray_length = vm_GetMagnitudeFast(&ray);
614 vector dest_norm_ray = ray / ray_length;
615 vector src_norm_ray = -dest_norm_ray;
616 vector dest_normal = dest_surf->normal;
617 float ff;
618 vector src_normal = rad_MaxSurface->normal;
619 ff = (vm_DotProduct(&src_norm_ray, &src_normal) * vm_DotProduct(&dest_normal, &dest_norm_ray)) /
620 ((3.14 * ray_length * ray_length) + ray_area);
621 ff *= ray_area;
622 ff *= rmax;
623
624 // If shooting from elements, scale the test up
625 if (multiple_shoots)
626 ff *= rad_MaxSurface->area / rad_MaxSurface->elements[i].area;
627

Callers 1

Calls 6

GetMaxColorFunction · 0.85
GetCenterOfElementFunction · 0.85
ShootRayFromPointFunction · 0.85
vm_DotProductFunction · 0.50
vm_GetMagnitudeFastFunction · 0.50
vm_GetMagnitudeFunction · 0.50

Tested by

no test coverage detected