| 1649 | } |
| 1650 | |
| 1651 | void MapDrawerSoft::DrawModelShadow( |
| 1652 | const Model& base_model, |
| 1653 | const unsigned int animation_frame, |
| 1654 | const ViewClipPlanes& view_clip_planes, |
| 1655 | const m_Vec3& position, |
| 1656 | const m_Mat4& rotation_matrix, |
| 1657 | const m_Mat4& view_matrix, |
| 1658 | const m_Vec3& camera_position, |
| 1659 | const m_Vec3& light_pos, |
| 1660 | const unsigned char visible_groups_mask, |
| 1661 | const unsigned int submodel_id ) |
| 1662 | { |
| 1663 | const float c_shadow_z_offset= 0.02f; |
| 1664 | |
| 1665 | const Submodel& model= (submodel_id == ~0u) ? base_model : base_model.submodels[ submodel_id ]; |
| 1666 | const std::vector<unsigned short>& indeces= model.regular_triangles_indeces; |
| 1667 | if( indeces.size() == 0u ) |
| 1668 | return; |
| 1669 | |
| 1670 | m_Mat4 inv_rotation_mat= rotation_matrix; |
| 1671 | inv_rotation_mat.Transpose(); // For rotation matrix transpose is euqivalent for inverse. |
| 1672 | |
| 1673 | const m_Vec3 light_pos_model_space= ( light_pos - position ) * inv_rotation_mat; |
| 1674 | |
| 1675 | PC_ASSERT( animation_frame < model.frame_count ); |
| 1676 | const m_BBox3& bbox= model.animations_bboxes[ animation_frame ]; |
| 1677 | |
| 1678 | const auto project_model_vertex= |
| 1679 | [&]( const m_Vec3& v ) -> m_Vec3 |
| 1680 | { |
| 1681 | const m_Vec3 vec_from_light= v - light_pos_model_space; |
| 1682 | return m_Vec3( light_pos_model_space.xy() + vec_from_light.xy() / vec_from_light.z * (-light_pos_model_space.z), c_shadow_z_offset ); |
| 1683 | }; |
| 1684 | |
| 1685 | // Project bouning box to 2d bounding box. |
| 1686 | m_BBox2 bbox_projected; |
| 1687 | bbox_projected.min= bbox_projected.max= project_model_vertex( bbox.min ).xy(); |
| 1688 | for( unsigned int z= 0u; z < 2u; z++ ) |
| 1689 | for( unsigned int y= 0u; y < 2u; y++ ) |
| 1690 | for( unsigned int x= 0u; x < 2u; x++ ) |
| 1691 | { |
| 1692 | const m_Vec3 point( |
| 1693 | x == 0 ? bbox.min.x : bbox.max.x, |
| 1694 | y == 0 ? bbox.min.y : bbox.max.y, |
| 1695 | z == 0 ? bbox.min.z : bbox.max.z ); |
| 1696 | |
| 1697 | bbox_projected+= project_model_vertex( point ).xy(); |
| 1698 | } |
| 1699 | |
| 1700 | unsigned int active_clip_planes_mask= 0u; |
| 1701 | |
| 1702 | m_Mat4 translate_mat, bbox_mat; |
| 1703 | translate_mat.Translate( position ); |
| 1704 | bbox_mat= rotation_matrix * translate_mat; |
| 1705 | |
| 1706 | // Clip-planes bounding box test |
| 1707 | for( const m_Plane3& clip_plane : view_clip_planes ) |
| 1708 | { |
nothing calls this directly
no test coverage detected