MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Move3DPosTo3DPos

Function Move3DPosTo3DPos

TombEngine/Game/collision/collide_item.cpp:480–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480bool Move3DPosTo3DPos(ItemInfo* item, Pose& fromPose, const Pose& toPose, int velocity, short turnRate)
481{
482 auto* lara = GetLaraInfo(item);
483
484 auto direction = toPose.Position - fromPose.Position;
485 float distance = Vector3i::Distance(fromPose.Position, toPose.Position);
486
487 if (velocity < distance)
488 fromPose.Position += direction * (velocity / distance);
489 else
490 fromPose.Position = toPose.Position;
491
492 if (!lara->Control.IsMoving)
493 {
494 bool shouldAnimate = ((distance - velocity) > (velocity * ANIMATED_ALIGNMENT_FRAME_COUNT_THRESHOLD));
495
496 if (shouldAnimate && lara->Control.WaterStatus != WaterStatus::Underwater)
497 {
498 short angle = Geometry::GetOrientToPoint(fromPose.Position.ToVector3(), toPose.Position.ToVector3()).y;
499 int direction = (GetQuadrant(angle) - GetQuadrant(fromPose.Orientation.y)) & 3;
500
501 switch (direction)
502 {
503 default:
504 case NORTH:
505 SetAnimation(item, LA_WALK);
506 break;
507
508 case SOUTH:
509 SetAnimation(item, LA_WALK_BACK);
510 break;
511
512 case EAST:
513 SetAnimation(item, LA_SIDESTEP_RIGHT);
514 break;
515
516 case WEST:
517 SetAnimation(item, LA_SIDESTEP_LEFT);
518 break;
519 }
520
521 lara->Control.HandStatus = HandStatus::Busy;
522 }
523
524 lara->Control.IsMoving = true;
525 lara->Control.Count.PositionAdjust = 0;
526 }
527
528 auto deltaOrient = toPose.Orientation - fromPose.Orientation;
529
530 if (deltaOrient.x > turnRate)
531 fromPose.Orientation.x += turnRate;
532 else if (deltaOrient.x < -turnRate)
533 fromPose.Orientation.x -= turnRate;
534 else
535 fromPose.Orientation.x = toPose.Orientation.x;
536
537 if (deltaOrient.y > turnRate)

Callers 1

MoveLaraPositionFunction · 0.85

Calls 4

GetOrientToPointFunction · 0.85
GetQuadrantFunction · 0.85
SetAnimationFunction · 0.85
ToVector3Method · 0.45

Tested by

no test coverage detected