| 150 | } |
| 151 | |
| 152 | bool PhysCalcGround(vector *ground_point, vector *ground_normal, object *obj, int ground_num) { |
| 153 | poly_model *pm; |
| 154 | vector pnt; |
| 155 | vector normal; |
| 156 | matrix m; |
| 157 | int mn; // submodel number |
| 158 | float normalized_time[MAX_SUBOBJECTS]; |
| 159 | bool f_good_gp = true; |
| 160 | |
| 161 | if (obj->render_type != RT_POLYOBJ && obj->type != OBJ_PLAYER) { |
| 162 | // mprintf(0,"Object type %d is not a polyobj!\n",obj->type); |
| 163 | |
| 164 | if (ground_point) |
| 165 | *ground_point = obj->pos; |
| 166 | if (ground_normal) |
| 167 | *ground_normal = obj->orient.fvec; |
| 168 | |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 173 | |
| 174 | if (pm->n_ground == 0) { |
| 175 | mprintf(0, "WARNING: Object with no weapons is firing.\n", ground_num); |
| 176 | |
| 177 | if (ground_point) |
| 178 | *ground_point = obj->pos; |
| 179 | if (ground_normal) |
| 180 | *ground_normal = obj->orient.fvec; |
| 181 | |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | SetNormalizedTimeObj(obj, normalized_time); |
| 186 | |
| 187 | SetModelAnglesAndPos(pm, normalized_time); |
| 188 | |
| 189 | if (ground_num < 0 || ground_num >= pm->n_ground) { |
| 190 | mprintf(0, "WARNING: Bashing ground num %d to 0.\n", ground_num); |
| 191 | ground_num = 0; |
| 192 | f_good_gp = false; |
| 193 | } |
| 194 | |
| 195 | pnt = pm->ground_slots[ground_num].pnt; |
| 196 | normal = pm->ground_slots[ground_num].norm; |
| 197 | mn = pm->ground_slots[ground_num].parent; |
| 198 | |
| 199 | // Instance up the tree for this ground |
| 200 | while (mn != -1) { |
| 201 | vector tpnt; |
| 202 | |
| 203 | vm_AnglesToMatrix(&m, pm->submodel[mn].angs.p, pm->submodel[mn].angs.h, pm->submodel[mn].angs.b); |
| 204 | vm_TransposeMatrix(&m); |
| 205 | |
| 206 | tpnt = pnt * m; |
| 207 | normal = normal * m; |
| 208 | |
| 209 | pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos; |
no test coverage detected