Returns true if passed in point collides with a nodes polygon
| 1074 | |
| 1075 | // Returns true if passed in point collides with a nodes polygon |
| 1076 | static inline int BSPPointInPolygon(vector *pos, bspnode *node) { |
| 1077 | if (node->node_subnum < 0) // Room face |
| 1078 | { |
| 1079 | room *rp = &Rooms[node->node_roomnum]; |
| 1080 | face *fp = &rp->faces[node->node_facenum]; |
| 1081 | if (!(BSPInMinMax(pos, &fp->min_xyz, &fp->max_xyz))) |
| 1082 | return 0; |
| 1083 | |
| 1084 | // Test to see if this point in inside the polygon |
| 1085 | vector verts[MAX_VERTS_PER_FACE], *vertp[MAX_VERTS_PER_FACE]; |
| 1086 | for (int i = 0; i < fp->num_verts; i++) { |
| 1087 | verts[i] = rp->verts[fp->face_verts[i]]; |
| 1088 | vertp[i] = &verts[i]; |
| 1089 | } |
| 1090 | |
| 1091 | if ((check_point_to_face(pos, &fp->normal, fp->num_verts, vertp))) |
| 1092 | return 0; |
| 1093 | |
| 1094 | return 1; |
| 1095 | } else // Object face |
| 1096 | { |
| 1097 | object *obj = &Objects[node->node_roomnum]; |
| 1098 | |
| 1099 | if (!(BSPInMinMax(pos, &obj->min_xyz, &obj->max_xyz))) |
| 1100 | return 0; |
| 1101 | |
| 1102 | // Test to see if this point in inside the polygon |
| 1103 | vector verts[MAX_VERTS_PER_FACE], *vertp[MAX_VERTS_PER_FACE]; |
| 1104 | vector norm; |
| 1105 | poly_model *po = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 1106 | bsp_info *sm = &po->submodel[node->node_subnum]; |
| 1107 | |
| 1108 | for (int i = 0; i < sm->faces[node->node_facenum].nverts; i++) { |
| 1109 | GetObjectPointInWorld(&verts[i], obj, node->node_subnum, sm->faces[node->node_facenum].vertnums[i]); |
| 1110 | vertp[i] = &verts[i]; |
| 1111 | } |
| 1112 | |
| 1113 | norm.x = node->plane.a; |
| 1114 | norm.y = node->plane.b; |
| 1115 | norm.z = node->plane.c; |
| 1116 | |
| 1117 | if ((check_point_to_face(pos, &norm, sm->faces[node->node_facenum].nverts, vertp))) |
| 1118 | return 0; |
| 1119 | |
| 1120 | return 1; |
| 1121 | } |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | // Runs a ray through the bsp tree |
| 1127 | // Returns true if a ray is occludes |
no test coverage detected