| 1729 | } |
| 1730 | |
| 1731 | bool WeaponCalcGun(vector *gun_point, vector *gun_normal, object *obj, int gun_num) { |
| 1732 | poly_model *pm; |
| 1733 | vector pnt; |
| 1734 | vector normal; |
| 1735 | matrix m; |
| 1736 | int mn; // submodel number |
| 1737 | float normalized_time[MAX_SUBOBJECTS]; |
| 1738 | bool f_good_gp = true; |
| 1739 | |
| 1740 | if (!(obj->flags & OF_POLYGON_OBJECT)) { |
| 1741 | // mprintf(0,"Object type %d is not a polyobj!\n",obj->type); |
| 1742 | |
| 1743 | if (gun_point) |
| 1744 | *gun_point = obj->pos; |
| 1745 | if (gun_normal) |
| 1746 | *gun_normal = obj->orient.fvec; |
| 1747 | |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 1752 | |
| 1753 | if (pm->n_guns == 0) { |
| 1754 | mprintf(0, "WARNING: Object with no weapons is firing.\n", gun_num); |
| 1755 | |
| 1756 | if (gun_point) |
| 1757 | *gun_point = obj->pos; |
| 1758 | if (gun_normal) |
| 1759 | *gun_normal = obj->orient.fvec; |
| 1760 | |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
| 1764 | SetNormalizedTimeObj(obj, normalized_time); |
| 1765 | SetModelAnglesAndPos(pm, normalized_time); |
| 1766 | |
| 1767 | if (gun_num < 0 || gun_num >= pm->n_guns) { |
| 1768 | mprintf(0, "WARNING: Bashing gun num %d to 0.\n", gun_num); |
| 1769 | if (gun_point) |
| 1770 | *gun_point = obj->pos; |
| 1771 | if (gun_normal) |
| 1772 | *gun_normal = obj->orient.fvec; |
| 1773 | return false; |
| 1774 | } |
| 1775 | |
| 1776 | pnt = pm->gun_slots[gun_num].pnt; |
| 1777 | normal = pm->gun_slots[gun_num].norm; |
| 1778 | mn = pm->gun_slots[gun_num].parent; |
| 1779 | |
| 1780 | // Instance up the tree for this gun |
| 1781 | while (mn != -1) { |
| 1782 | vector tpnt; |
| 1783 | |
| 1784 | vm_AnglesToMatrix(&m, pm->submodel[mn].angs.p, pm->submodel[mn].angs.h, pm->submodel[mn].angs.b); |
| 1785 | vm_TransposeMatrix(&m); |
| 1786 | |
| 1787 | if (gun_point) |
| 1788 | tpnt = pnt * m; |
no test coverage detected