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

Function ResetGroundObject

editor/HObject.cpp:429–474  ·  view source on GitHub ↗

Adjusts an object so it's at the ground level (for when the ground has moved)

Source from the content-addressed store, hash-verified

427
428// Adjusts an object so it's at the ground level (for when the ground has moved)
429void ResetGroundObject(object *objp) {
430 poly_model *pm;
431 vector surface_norm;
432 vector pos;
433 matrix groundplane_orient, surface_orient, object_orient;
434
435 // Make sure object is outside
436 if (!OBJECT_OUTSIDE(objp)) {
437 Int3(); // object is not outside
438 return;
439 }
440
441 // Make sure object has a ground plane
442 if (!((objp->render_type == RT_POLYOBJ) && ((pm = GetPolymodelPointer(objp->rtype.pobj_info.model_num))->n_ground))) {
443 Int3(); // object doesn't have a ground plane
444 return;
445 }
446
447 // Get terrain height and normal at current object location
448 pos = objp->pos;
449 pos.y = GetTerrainGroundPoint(&pos, &surface_norm);
450
451 // Place the object's ground point on our placement point
452 vector ground_point;
453 vector ground_normal;
454 vector to_ground;
455 float dist;
456
457 PhysCalcGround(&ground_point, &ground_normal, objp, 0);
458 to_ground = objp->pos - ground_point;
459 dist = ground_normal * to_ground;
460 pos += dist * surface_norm;
461
462 // Compute source and destination matrices
463 vm_VectorToMatrix(&groundplane_orient, &pm->ground_slots[0].norm, NULL, NULL);
464 vm_VectorToMatrix(&surface_orient, &surface_norm);
465
466 // Compute orientation matrix
467 vm_MatrixMulTMatrix(&object_orient, &surface_orient, &groundplane_orient);
468
469 // Move the object
470 ObjSetPos(objp, &pos, objp->roomnum, &object_orient, false);
471
472 // Set flag
473 World_changed = 1;
474}
475
476void HObjectMove(int objnum, float dx, float dy, float dz) {
477 matrix *mat;

Callers 2

Calls 6

GetPolymodelPointerFunction · 0.85
GetTerrainGroundPointFunction · 0.85
PhysCalcGroundFunction · 0.85
ObjSetPosFunction · 0.85
vm_VectorToMatrixFunction · 0.50
vm_MatrixMulTMatrixFunction · 0.50

Tested by

no test coverage detected