Check a line against the model for collision
| 1824 | |
| 1825 | // Check a line against the model for collision |
| 1826 | int Model::lineCheck(const vec3 &p1, const vec3 &p2, vec3 *p, vec3 *normal, bool backface) const { |
| 1827 | if (!sphere_line_intersection(p1, p2, bounding_sphere_origin, bounding_sphere_radius)) return -1; |
| 1828 | |
| 1829 | float distance; |
| 1830 | float olddistance = 0; |
| 1831 | int intersecting = 0; |
| 1832 | int firstintersecting = -1; |
| 1833 | vec3 point; |
| 1834 | vec3 end = p2; |
| 1835 | int face_index, vert_index; |
| 1836 | vec3 points[3]; |
| 1837 | for (int j = 0, len = faces.size() / 3; j < len; j++) { |
| 1838 | face_index = j * 3; |
| 1839 | for (unsigned k = 0; k < 3; ++k) { |
| 1840 | vert_index = faces[face_index + k] * 3; |
| 1841 | points[k][0] = vertices[vert_index + 0]; |
| 1842 | points[k][1] = vertices[vert_index + 1]; |
| 1843 | points[k][2] = vertices[vert_index + 2]; |
| 1844 | } |
| 1845 | intersecting = LineFacet(p1, end, points[0], points[1], points[2], &point, face_normals[j]); |
| 1846 | if (intersecting) { |
| 1847 | distance = distance_squared(p1, point); |
| 1848 | if (distance < olddistance || firstintersecting == -1) { |
| 1849 | olddistance = distance; |
| 1850 | firstintersecting = j; |
| 1851 | if (p) *p = point; |
| 1852 | end = point; |
| 1853 | if (normal) *normal = face_normals[j]; |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | if (firstintersecting != -1) return firstintersecting; |
| 1858 | |
| 1859 | return -1; |
| 1860 | } |
| 1861 | |
| 1862 | // Check a line against the model for collision against front face only |
| 1863 | int Model::lineCheckNoBackface(const vec3 &p1, const vec3 &p2, vec3 *p, vec3 *normal) const { |
nothing calls this directly
no test coverage detected