Core/Transports: Refactored methods used to calculate passenger offsets (made orientation argument optional)
This commit is contained in:
1 parent
3a955f5141
commit
3a697d4c9f
7 files changed
+33
-30
No files matched your search
@@ -692,30 +692,34 @@ void Transport::UpdatePassengerPositions()
|
||||
|
||||
float x, y, z, o;
|
||||
npc->m_movementInfo.t_pos.GetPosition(x, y, z, o);
|
||||
CalculatePassengerPosition(x, y, z, o);
|
||||
CalculatePassengerPosition(x, y, z, &o);
|
||||
GetMap()->CreatureRelocation(npc, x, y, z, o, false);
|
||||
npc->GetTransportHomePosition(x, y, z, o);
|
||||
CalculatePassengerPosition(x, y, z, o);
|
||||
CalculatePassengerPosition(x, y, z, &o);
|
||||
npc->SetHomePosition(x, y, z, o);
|
||||
}
|
||||
}
|
||||
|
||||
void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& o) const
|
||||
void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= NULL*/) const
|
||||
{
|
||||
float inx = x, iny = y, inz = z, ino = o;
|
||||
o = GetOrientation() + ino;
|
||||
float inx = x, iny = y, inz = z;
|
||||
if (o)
|
||||
*o = Position::NormalizeOrientation(GetOrientation() + *o);
|
||||
|
||||
x = GetPositionX() + inx * std::cos(GetOrientation()) - iny * std::sin(GetOrientation());
|
||||
y = GetPositionY() + iny * std::cos(GetOrientation()) + inx * std::sin(GetOrientation());
|
||||
z = GetPositionZ() + inz;
|
||||
}
|
||||
|
||||
void Transport::CalculatePassengerOffset(float& x, float& y, float& z, float& o) const
|
||||
void Transport::CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= NULL*/) const
|
||||
{
|
||||
o -= GetOrientation();
|
||||
if (o)
|
||||
*o = Position::NormalizeOrientation(*o - GetOrientation());
|
||||
|
||||
z -= GetPositionZ();
|
||||
y -= GetPositionY(); // y = searchedY * std::cos(o) + searchedX * std::sin(o)
|
||||
x -= GetPositionX(); // x = searchedX * std::cos(o) + searchedY * std::sin(o + pi)
|
||||
float inx = x, iny = y;
|
||||
y = (iny - inx * tan(GetOrientation())) / (cos(GetOrientation()) + std::sin(GetOrientation()) * tan(GetOrientation()));
|
||||
x = (inx + iny * tan(GetOrientation())) / (cos(GetOrientation()) + std::sin(GetOrientation()) * tan(GetOrientation()));
|
||||
y = (iny - inx * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation()));
|
||||
x = (inx + iny * std::tan(GetOrientation())) / (std::cos(GetOrientation()) + std::sin(GetOrientation()) * std::tan(GetOrientation()));
|
||||
}
|
||||
@@ -50,10 +50,10 @@ class Transport : public GameObject, public TransportBase
|
||||
void UpdatePassengerPositions();
|
||||
|
||||
/// This method transforms supplied transport offsets into global coordinates
|
||||
void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const;
|
||||
void CalculatePassengerPosition(float& x, float& y, float& z, float* o = NULL) const;
|
||||
|
||||
/// This method transforms supplied global coordinates into local offsets
|
||||
void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const;
|
||||
void CalculatePassengerOffset(float& x, float& y, float& z, float* o = NULL) const;
|
||||
|
||||
void BuildStartMovePacket(Map const* targetMap);
|
||||
void BuildStopMovePacket(Map const* targetMap);
|
||||
|
||||
@@ -414,7 +414,7 @@ void Unit::UpdateSplineMovement(uint32 t_diff)
|
||||
pos.m_orientation = loc.orientation;
|
||||
|
||||
if (TransportBase* transport = GetDirectTransport())
|
||||
transport->CalculatePassengerPosition(loc.x, loc.y, loc.z, loc.orientation);
|
||||
transport->CalculatePassengerPosition(loc.x, loc.y, loc.z, &loc.orientation);
|
||||
}
|
||||
|
||||
if (HasUnitState(UNIT_STATE_CANNOT_TURN))
|
||||
|
||||
@@ -557,7 +557,7 @@ void Vehicle::RelocatePassengers()
|
||||
|
||||
float px, py, pz, po;
|
||||
passenger->m_movementInfo.t_pos.GetPosition(px, py, pz, po);
|
||||
CalculatePassengerPosition(px, py, pz, po);
|
||||
CalculatePassengerPosition(px, py, pz, &po);
|
||||
passenger->UpdatePosition(px, py, pz, po);
|
||||
}
|
||||
}
|
||||
@@ -675,24 +675,28 @@ uint8 Vehicle::GetAvailableSeatCount() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Vehicle::CalculatePassengerPosition(float& x, float& y, float& z, float& o) const
|
||||
void Vehicle::CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= NULL*/) const
|
||||
{
|
||||
float inx = x, iny = y, inz = z, ino = o;
|
||||
o = GetBase()->GetOrientation() + ino;
|
||||
float inx = x, iny = y, inz = z;
|
||||
if (o)
|
||||
*o = Position::NormalizeOrientation(GetBase()->GetOrientation() + *o);
|
||||
|
||||
x = GetBase()->GetPositionX() + inx * std::cos(GetBase()->GetOrientation()) - iny * std::sin(GetBase()->GetOrientation());
|
||||
y = GetBase()->GetPositionY() + iny * std::cos(GetBase()->GetOrientation()) + inx * std::sin(GetBase()->GetOrientation());
|
||||
z = GetBase()->GetPositionZ() + inz;
|
||||
}
|
||||
|
||||
void Vehicle::CalculatePassengerOffset(float& x, float& y, float& z, float& o) const
|
||||
void Vehicle::CalculatePassengerOffset(float& x, float& y, float& z, float* o /*= NULL*/) const
|
||||
{
|
||||
o -= GetBase()->GetOrientation();
|
||||
if (o)
|
||||
*o = Position::NormalizeOrientation(*o - GetBase()->GetOrientation());
|
||||
|
||||
z -= GetBase()->GetPositionZ();
|
||||
y -= GetBase()->GetPositionY(); // y = searchedY * std::cos(o) + searchedX * std::sin(o)
|
||||
x -= GetBase()->GetPositionX(); // x = searchedX * std::cos(o) + searchedY * std::sin(o + pi)
|
||||
float inx = x, iny = y;
|
||||
y = (iny - inx * tan(GetBase()->GetOrientation())) / (cos(GetBase()->GetOrientation()) + std::sin(GetBase()->GetOrientation()) * tan(GetBase()->GetOrientation()));
|
||||
x = (inx + iny * tan(GetBase()->GetOrientation())) / (cos(GetBase()->GetOrientation()) + std::sin(GetBase()->GetOrientation()) * tan(GetBase()->GetOrientation()));
|
||||
y = (iny - inx * std::tan(GetBase()->GetOrientation())) / (std::cos(GetBase()->GetOrientation()) + std::sin(GetBase()->GetOrientation()) * std::tan(GetBase()->GetOrientation()));
|
||||
x = (inx + iny * std::tan(GetBase()->GetOrientation())) / (std::cos(GetBase()->GetOrientation()) + std::sin(GetBase()->GetOrientation()) * std::tan(GetBase()->GetOrientation()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -89,10 +89,10 @@ class Vehicle : public TransportBase
|
||||
void InitMovementInfoForBase();
|
||||
|
||||
/// This method transforms supplied transport offsets into global coordinates
|
||||
void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const;
|
||||
void CalculatePassengerPosition(float& x, float& y, float& z, float* o = NULL) const;
|
||||
|
||||
/// This method transforms supplied global coordinates into local offsets
|
||||
void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const;
|
||||
void CalculatePassengerOffset(float& x, float& y, float& z, float* o = NULL) const;
|
||||
|
||||
void RemovePendingEvent(VehicleJoinEvent* e);
|
||||
void RemovePendingEventsForSeat(int8 seatId);
|
||||
|
||||
@@ -83,10 +83,10 @@ protected:
|
||||
|
||||
public:
|
||||
/// This method transforms supplied transport offsets into global coordinates
|
||||
virtual void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const = 0;
|
||||
virtual void CalculatePassengerPosition(float& x, float& y, float& z, float* o = NULL) const = 0;
|
||||
|
||||
/// This method transforms supplied global coordinates into local offsets
|
||||
virtual void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const = 0;
|
||||
virtual void CalculatePassengerOffset(float& x, float& y, float& z, float* o = NULL) const = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -175,13 +175,8 @@ namespace Movement
|
||||
Vector3 TransportPathTransform::operator()(Vector3 input)
|
||||
{
|
||||
if (_transformForTransport)
|
||||
{
|
||||
if (TransportBase* transport = _owner->GetDirectTransport())
|
||||
{
|
||||
float unused = 0.0f; // need reference
|
||||
transport->CalculatePassengerOffset(input.x, input.y, input.z, unused);
|
||||
}
|
||||
}
|
||||
transport->CalculatePassengerOffset(input.x, input.y, input.z);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user