mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Entities: Merge duplicate functions calculating relative positions - remove CalculatePassengerPosition/CalculatePassengerOffset from TransportBase class
This commit is contained in:
@@ -1849,13 +1849,8 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
|
||||
TransportBase* transport = summoner ? summoner->GetTransport() : nullptr;
|
||||
if (transport)
|
||||
{
|
||||
float x, y, z, o;
|
||||
pos.GetPosition(x, y, z, o);
|
||||
transport->CalculatePassengerOffset(x, y, z, &o);
|
||||
summon->m_movementInfo.transport.pos.Relocate(x, y, z, o);
|
||||
|
||||
// This object must be added to transport before adding to map for the client to properly display it
|
||||
transport->AddPassenger(summon);
|
||||
transport->AddPassenger(summon, transport->GetPositionOffsetTo(pos));
|
||||
}
|
||||
|
||||
if (summoner && !(properties && properties->GetFlags().HasFlag(SummonPropertiesFlags::IgnoreSummonerPhase)))
|
||||
|
||||
@@ -33,9 +33,9 @@ bool Position::operator==(Position const& a) const
|
||||
|
||||
void Position::RelocateOffset(Position const& offset)
|
||||
{
|
||||
m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + float(M_PI)));
|
||||
m_positionY = GetPositionY() + (offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation()));
|
||||
m_positionZ = GetPositionZ() + offset.GetPositionZ();
|
||||
m_positionX += offset.GetPositionX() * std::cos(GetOrientation()) - offset.GetPositionY() * std::sin(GetOrientation());
|
||||
m_positionY += offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation());
|
||||
m_positionZ += offset.GetPositionZ();
|
||||
SetOrientation(GetOrientation() + offset.GetOrientation());
|
||||
}
|
||||
|
||||
@@ -44,15 +44,18 @@ bool Position::IsPositionValid() const
|
||||
return Trinity::IsValidMapCoord(m_positionX, m_positionY, m_positionZ, m_orientation);
|
||||
}
|
||||
|
||||
void Position::GetPositionOffsetTo(Position const& endPos, Position& retOffset) const
|
||||
Position Position::GetPositionOffsetTo(Position const& endPos) const
|
||||
{
|
||||
float dx = endPos.GetPositionX() - GetPositionX();
|
||||
float dy = endPos.GetPositionY() - GetPositionY();
|
||||
|
||||
retOffset.m_positionX = (dx + dy * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation()));
|
||||
retOffset.m_positionY = (dy - dx * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation()));
|
||||
retOffset.m_positionZ = endPos.GetPositionZ() - GetPositionZ();
|
||||
retOffset.SetOrientation(endPos.GetOrientation() - GetOrientation());
|
||||
return
|
||||
{
|
||||
(dx + dy * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation())),
|
||||
(dy - dx * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation())),
|
||||
endPos.GetPositionZ() - GetPositionZ(),
|
||||
endPos.GetOrientation() - GetOrientation()
|
||||
};
|
||||
}
|
||||
|
||||
Position Position::GetPositionWithOffset(Position const& offset) const
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
float GetExactDist(Position const& pos) const { return GetExactDist(pos.m_positionX, pos.m_positionY, pos.m_positionZ); }
|
||||
float GetExactDist(Position const* pos) const { return GetExactDist(*pos); }
|
||||
|
||||
void GetPositionOffsetTo(Position const & endPos, Position & retOffset) const;
|
||||
Position GetPositionOffsetTo(Position const & endPos) const;
|
||||
Position GetPositionWithOffset(Position const& offset) const;
|
||||
|
||||
float GetAbsoluteAngle(float x, float y) const
|
||||
|
||||
Reference in New Issue
Block a user