| 5878 | //---------------------------------------------------------------------------- |
| 5879 | |
| 5880 | bool Player::castRay(const Point3F &start, const Point3F &end, RayInfo* info) |
| 5881 | { |
| 5882 | if (getDamageState() != Enabled) |
| 5883 | return false; |
| 5884 | |
| 5885 | // Collide against bounding box. Need at least this for the editor. |
| 5886 | F32 st,et,fst = 0.0f,fet = 1.0f; |
| 5887 | F32 *bmin = &mObjBox.minExtents.x; |
| 5888 | F32 *bmax = &mObjBox.maxExtents.x; |
| 5889 | F32 const *si = &start.x; |
| 5890 | F32 const *ei = &end.x; |
| 5891 | |
| 5892 | for (S32 i = 0; i < 3; i++) { |
| 5893 | if (*si < *ei) { |
| 5894 | if (*si > *bmax || *ei < *bmin) |
| 5895 | return false; |
| 5896 | F32 di = *ei - *si; |
| 5897 | st = (*si < *bmin)? (*bmin - *si) / di: 0.0f; |
| 5898 | et = (*ei > *bmax)? (*bmax - *si) / di: 1.0f; |
| 5899 | } |
| 5900 | else { |
| 5901 | if (*ei > *bmax || *si < *bmin) |
| 5902 | return false; |
| 5903 | F32 di = *ei - *si; |
| 5904 | st = (*si > *bmax)? (*bmax - *si) / di: 0.0f; |
| 5905 | et = (*ei < *bmin)? (*bmin - *si) / di: 1.0f; |
| 5906 | } |
| 5907 | if (st > fst) fst = st; |
| 5908 | if (et < fet) fet = et; |
| 5909 | if (fet < fst) |
| 5910 | return false; |
| 5911 | bmin++; bmax++; |
| 5912 | si++; ei++; |
| 5913 | } |
| 5914 | |
| 5915 | info->normal = start - end; |
| 5916 | info->normal.normalizeSafe(); |
| 5917 | getTransform().mulV( info->normal ); |
| 5918 | |
| 5919 | info->t = fst; |
| 5920 | info->object = this; |
| 5921 | info->point.interpolate(start,end,fst); |
| 5922 | info->material = 0; |
| 5923 | return true; |
| 5924 | } |
| 5925 | |
| 5926 | |
| 5927 | //---------------------------------------------------------------------------- |
no test coverage detected