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

Function MoveObject

editor/HObject.cpp:574–609  ·  view source on GitHub ↗

Attempt to set new object position. May only move part of the way, or maybe not at all. Use FVI to find new object position Return: TRUE if moved, FALSE if can't move

Source from the content-addressed store, hash-verified

572// Use FVI to find new object position
573// Return: TRUE if moved, FALSE if can't move
574bool MoveObject(object *obj, vector *newpos) {
575 fvi_query fq;
576 fvi_info hit_info;
577 int fate;
578
579 // Use radius if this is a physics object
580 bool use_radius = (obj->movement_type == MT_PHYSICS) ? true : false;
581
582 // Follow vector from start position to desired end position, & move as far as we can
583 fq.p0 = &obj->pos;
584 fq.startroom = obj->roomnum;
585 fq.p1 = newpos;
586 fq.thisobjnum = OBJNUM(obj);
587 fq.ignore_obj_list = NULL;
588 fq.flags = FQ_IGNORE_RENDER_THROUGH_PORTALS;
589 fq.rad = use_radius ? obj->size : 0.0f;
590
591 if (f_allow_objects_to_be_pushed_through_walls) {
592 fq.flags |= (FQ_IGNORE_WALLS | FQ_IGNORE_TERRAIN | FQ_IGNORE_EXTERNAL_ROOMS);
593 }
594
595 fate = fvi_FindIntersection(&fq, &hit_info);
596
597 mprintf(0, "fate = %d\n", fate);
598
599 // Check for object can't move, meaning it's stuck in the wall
600 if (fate == HIT_WALL)
601 if (vm_VectorDistance(&obj->pos, &hit_info.hit_pnt) < MOVE_EPSILON)
602 return 0; // didn't move
603
604 // Set object position on where FVI told us we are
605 ObjSetPos(obj, &hit_info.hit_pnt, hit_info.hit_room, NULL, false);
606
607 // Say object moved
608 return 1;
609}
610
611bool RotateObject(int objnum, angle p, angle h, angle b) {
612 object *obj = &Objects[objnum];

Callers 3

HObjectPlaceFunction · 0.85
HObjectMoveFunction · 0.85
HObjectMoveToViewerFunction · 0.85

Calls 3

fvi_FindIntersectionFunction · 0.85
ObjSetPosFunction · 0.85
vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected