1
0

Add some comments

This commit is contained in:
Christophe Piveteau 2014-08-15 13:40:56 +02:00
parent e3a74f379f
commit 0f631febfc

View File

@ -875,14 +875,20 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
Distance.z = std::max(Distance.z, 0.001);
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line z = -x, the perpendicular line to this is z = x.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located.
*/
if (
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
)
{
if ((-GetSpeedX() * 0.4) < 0.01)
if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
{
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
@ -893,7 +899,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
SetSpeedZ(GetSpeedZ() * 0.4);
}
}
else if ((GetSpeedX() * 0.4) < 0.01)
else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
{
AddSpeedX(4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
@ -910,8 +916,13 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
Distance.z = std::max(Distance.z, 0.001);
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line z = x, the perpendicular line to this is z = -x.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
if (
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))