Finds the position of a attach point on an object The uvec is optional as most attaching objects don't need at complete orientation set (only an fvec)
| 143 | // Finds the position of a attach point on an object |
| 144 | // The uvec is optional as most attaching objects don't need at complete orientation set (only an fvec) |
| 145 | static bool AttachPointPos(object *obj, char ap, bool f_compute_pos, vector *attach_pos, bool f_compute_fvec, |
| 146 | vector *attach_fvec, bool *f_computed_uvec = NULL, vector *attach_uvec = NULL) { |
| 147 | poly_model *pm; |
| 148 | vector pnt; |
| 149 | vector normal; |
| 150 | vector uvec; |
| 151 | matrix m; |
| 152 | int mn; // submodel number |
| 153 | float normalized_time[MAX_SUBOBJECTS]; |
| 154 | |
| 155 | pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 156 | |
| 157 | if (ap < 0 || ap >= pm->n_attach) { |
| 158 | mprintf(0, "WARNING: No ap %d on object %d.\n", ap, OBJNUM(obj)); |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | SetNormalizedTimeObj(obj, normalized_time); |
| 163 | SetModelAnglesAndPos(pm, normalized_time); |
| 164 | |
| 165 | if (f_compute_pos) |
| 166 | pnt = pm->attach_slots[ap].pnt; |
| 167 | |
| 168 | if (f_compute_fvec) { |
| 169 | normal = pm->attach_slots[ap].norm; |
| 170 | // mprintf(0, "Original fvec is %f long.\n", vm_GetMagnitude(&normal)); |
| 171 | } |
| 172 | |
| 173 | if (pm->attach_slots[ap].f_uvec && attach_uvec && f_computed_uvec) { |
| 174 | *f_computed_uvec = true; |
| 175 | uvec = pm->attach_slots[ap].uvec; |
| 176 | |
| 177 | // mprintf(0, "Original uvec is %f long.\n", vm_GetMagnitude(&uvec)); |
| 178 | } else if (f_computed_uvec) { |
| 179 | *f_computed_uvec = false; |
| 180 | } |
| 181 | |
| 182 | mn = pm->attach_slots[ap].parent; |
| 183 | |
| 184 | // Instance up the tree for this gun |
| 185 | while (mn != -1) { |
| 186 | vector tpnt; |
| 187 | |
| 188 | vm_AnglesToMatrix(&m, pm->submodel[mn].angs.p, pm->submodel[mn].angs.h, pm->submodel[mn].angs.b); |
| 189 | vm_TransposeMatrix(&m); |
| 190 | |
| 191 | if (f_compute_pos) |
| 192 | tpnt = pnt * m; |
| 193 | |
| 194 | if (f_compute_fvec) |
| 195 | normal = normal * m; |
| 196 | |
| 197 | if (f_computed_uvec && *f_computed_uvec) { |
| 198 | uvec = uvec * m; |
| 199 | } |
| 200 | |
| 201 | if (f_compute_pos) |
| 202 | pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos; |
no test coverage detected