Applies lighting to a submodel and all its children
| 598 | |
| 599 | // Applies lighting to a submodel and all its children |
| 600 | void ApplyLightingToSubmodel(object *obj, poly_model *pm, bsp_info *sm, float light_dist, float red_scale, |
| 601 | float green_scale, float blue_scale, float dot_range) { |
| 602 | matrix mat; |
| 603 | vector Light_min_xyz; |
| 604 | vector Light_max_xyz; |
| 605 | vector rad; |
| 606 | int i, t; |
| 607 | int subnum = sm - pm->submodel; |
| 608 | int lm_handle; |
| 609 | uint16_t *dest_data; |
| 610 | uint16_t lmilist[MAX_DYNAMIC_FACES]; |
| 611 | int num_spoken_for = 0; |
| 612 | |
| 613 | int red_limit = 31; |
| 614 | int green_limit = 31; |
| 615 | int blue_limit = 31; |
| 616 | |
| 617 | if (IsNonRenderableSubmodel(pm, subnum)) |
| 618 | return; // Don't do shells, frontfaces, etc |
| 619 | |
| 620 | // Start instance stuff |
| 621 | vector temp_vec = sm->mod_pos + sm->offset; |
| 622 | vm_AnglesToMatrix(&mat, sm->angs.p, sm->angs.h, sm->angs.b); |
| 623 | StartLightingInstance(&temp_vec, &mat); |
| 624 | |
| 625 | rad.x = light_dist; |
| 626 | rad.y = light_dist; |
| 627 | rad.z = light_dist; |
| 628 | |
| 629 | vector light_pos = Light_position; |
| 630 | vector light_dir = Light_direction; |
| 631 | |
| 632 | Light_min_xyz = light_pos - rad; |
| 633 | Light_max_xyz = light_pos + rad; |
| 634 | |
| 635 | // Now the Light_position is in the submodels frame of reference |
| 636 | for (i = 0; i < sm->num_faces; i++) { |
| 637 | // check to see if this face is within reach |
| 638 | if (Light_max_xyz.y < sm->face_min[i].y || sm->face_max[i].y < Light_min_xyz.y || |
| 639 | Light_max_xyz.x < sm->face_min[i].x || sm->face_max[i].x < Light_min_xyz.x || |
| 640 | Light_max_xyz.z < sm->face_min[i].z || sm->face_max[i].z < Light_min_xyz.z) |
| 641 | continue; |
| 642 | |
| 643 | // Ok, now we know that this light touches this face |
| 644 | if (Num_dynamic_faces >= MAX_DYNAMIC_FACES) { |
| 645 | mprintf(0, "Too many dynamic faces!\n"); |
| 646 | DoneLightingInstance(); |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | lightmap_object_face *fp = &obj->lm_object.lightmap_faces[subnum][i]; |
| 651 | |
| 652 | if (Lmi_spoken_for[fp->lmi_handle / 8] & (1 << (fp->lmi_handle % 8))) |
| 653 | continue; |
| 654 | |
| 655 | int xres = lmi_w(fp->lmi_handle); |
| 656 | int yres = lmi_h(fp->lmi_handle); |
| 657 |
no test coverage detected