MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CreateSplintersFromBody

Function CreateSplintersFromBody

Descent3/fireball.cpp:1045–1139  ·  view source on GitHub ↗

Creates individual face particles from the main body of an object

Source from the content-addressed store, hash-verified

1043#define MAX_SPLINTERS_PER_OBJECT 10
1044// Creates individual face particles from the main body of an object
1045void CreateSplintersFromBody(object *obj, float explosion_mag, float lifetime) {
1046 ASSERT(obj->flags & OF_POLYGON_OBJECT);
1047 int facenums[MAX_SPLINTERS_PER_OBJECT];
1048 vector rot_vecs[MAX_SUBOBJECTS];
1049 int num_splinters = 0;
1050 int i, t;
1051 int parent_objnum = obj - Objects;
1052 matrix m;
1053 m = obj->orient;
1054 vm_TransposeMatrix(&m);
1055 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
1056 // If submodel 0 not renderable, bail
1057 if (IsNonRenderableSubmodel(pm, 0))
1058 return;
1059 bsp_info *sm = &pm->submodel[0];
1060 if (sm->num_faces < MAX_SPLINTERS_PER_OBJECT) {
1061 for (i = 0; i < sm->num_faces; i++) {
1062 facenums[i] = i;
1063 num_splinters++;
1064 }
1065 } else {
1066 int limit = std::min(sm->num_faces, MAX_SPLINTERS_PER_OBJECT);
1067 for (i = 0; i < limit; i++) {
1068 facenums[i] = ps_rand() % sm->num_faces;
1069 num_splinters++;
1070 }
1071 }
1072 // Now, create those splinters!
1073 for (i = 0; i < num_splinters; i++) {
1074 int facenum = facenums[i];
1075 vector dest, center;
1076 int num_verts = std::min<float>(sm->faces[facenum].nverts, MAX_VERTS_PER_SPLINTER);
1077
1078 vm_MakeZero(&dest);
1079 vm_MakeZero(&center);
1080 // First get the center of this particular face
1081 for (t = 0; t < num_verts; t++) {
1082 vector pnt = sm->verts[sm->faces[facenum].vertnums[t]];
1083 vector temp_vec;
1084
1085 temp_vec = pnt * m;
1086 rot_vecs[t] = temp_vec;
1087 center += temp_vec;
1088 }
1089
1090 center /= num_verts;
1091 dest = center + obj->pos;
1092
1093 // Now create splinter with that faces center position
1094 int s_objnum = ObjCreate(OBJ_SPLINTER, pm - Poly_models, obj->roomnum, &dest, NULL);
1095 if (s_objnum < 0) {
1096 mprintf(0, "Couldn't create splinter object!\n");
1097 return;
1098 } else {
1099 // Fill in relevant info
1100
1101 object *splinter_obj = &Objects[s_objnum];
1102 splinter_obj->ctype.splinter_info.subobj_num = 0;

Callers 1

DestroyObjectFunction · 0.85

Calls 8

IsNonRenderableSubmodelFunction · 0.85
ps_randFunction · 0.85
vm_MakeZeroFunction · 0.85
ObjCreateFunction · 0.85
vm_NormalizeVectorFunction · 0.85
ObjSetOrientFunction · 0.85
SetObjectControlTypeFunction · 0.85
vm_TransposeMatrixFunction · 0.50

Tested by

no test coverage detected