From a544c0238ba4c94d78692a7592107f8e510893ee Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Wed, 13 Aug 2014 18:53:23 +0200 Subject: Implement ability to push minecarts on curved rails --- src/Entities/Minecart.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index d4eadc5d5..19eaa207f 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -871,11 +871,79 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) return true; } case E_META_RAIL_CURVED_ZM_XM: + case E_META_RAIL_CURVED_ZP_XP: + { + Vector3d Distance( + MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(), + 0, + MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() + ); + + if ( Distance.z == 0. ) Distance.z = 0.0001; + if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) ) + { + if ( (-GetSpeedX() * 0.4) < 0.01 ) + { + AddSpeedX( -4/sqrt(2) ); + AddSpeedZ( 4/sqrt(2) ); + } + else + { + SetSpeedX( -GetSpeedX() * 0.4 ); + SetSpeedZ( GetSpeedZ() * 0.4 ); + } + } + else + { + if ((GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX( 4/sqrt(2) ); + AddSpeedZ( -4/sqrt(2) ); + } + else + { + SetSpeedX( GetSpeedX() * 0.4 ); + SetSpeedZ( -GetSpeedZ() * 0.4 ); + } + } + break; + } case E_META_RAIL_CURVED_ZM_XP: case E_META_RAIL_CURVED_ZP_XM: - case E_META_RAIL_CURVED_ZP_XP: { - // TODO - simply can't be bothered right now + Vector3d Distance( + MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(), + 0, + MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() + ); + + if ( Distance.z == 0. ) Distance.z = 0.0001; + if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) ) + { + if ( (GetSpeedX() * 0.4) < 0.01 ) + { + AddSpeedX( 4/sqrt(2) ); + AddSpeedZ( 4/sqrt(2) ); + } + else + { + SetSpeedX( GetSpeedX() * 0.4 ); + SetSpeedZ( GetSpeedZ() * 0.4 ); + } + } + else + { + if ((-GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX( -4/sqrt(2) ); + AddSpeedZ( -4/sqrt(2) ); + } + else + { + SetSpeedX( -GetSpeedX() * 0.4 ); + SetSpeedZ( -GetSpeedZ() * 0.4 ); + } + } break; } default: break; -- cgit v1.2.3 From 3698c5c8295e6a6a0f37b17f3c04bb118cc58bf6 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Wed, 13 Aug 2014 19:16:00 +0200 Subject: Fixed braces and intendation errors --- src/Entities/Minecart.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 19eaa207f..5cf56d3d2 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -879,8 +879,12 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() ); - if ( Distance.z == 0. ) Distance.z = 0.0001; - if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) ) + if ( Distance.z == 0. ) + { + Distance.z = 0.0001; + } + + if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) ) { if ( (-GetSpeedX() * 0.4) < 0.01 ) { @@ -917,7 +921,11 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() ); - if ( Distance.z == 0. ) Distance.z = 0.0001; + if ( Distance.z == 0. ) + { + Distance.z = 0.0001; + } + if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) ) { if ( (GetSpeedX() * 0.4) < 0.01 ) -- cgit v1.2.3 From 3f117897fbda4eec95ad5cdd728f197840dd7224 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Wed, 13 Aug 2014 19:18:11 +0200 Subject: Another intendation error --- src/Entities/Minecart.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 5cf56d3d2..cd5e2adaa 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -881,9 +881,9 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) if ( Distance.z == 0. ) { - Distance.z = 0.0001; + Distance.z = 0.0001; } - + if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) ) { if ( (-GetSpeedX() * 0.4) < 0.01 ) -- cgit v1.2.3 From 2d2d4ff33b74eefe053cce4d9a5daada65ed496b Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Wed, 13 Aug 2014 19:47:43 +0200 Subject: Further fixing of coding style errors --- src/Entities/Minecart.cpp | 48 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index cd5e2adaa..45b9782f3 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -879,14 +879,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() ); - if ( Distance.z == 0. ) + if (Distance.z == 0.) { Distance.z = 0.0001; } - if ( ((Distance.z>=0)&&((Distance.x/Distance.z)>=1)) || ((Distance.z<0)&&((Distance.x/Distance.z)<=1)) ) + 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) < 0.01) { AddSpeedX( -4/sqrt(2) ); AddSpeedZ( 4/sqrt(2) ); @@ -897,18 +898,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) SetSpeedZ( GetSpeedZ() * 0.4 ); } } + else if ((GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX( 4/sqrt(2) ); + AddSpeedZ( -4/sqrt(2) ); + } else { - if ((GetSpeedX() * 0.4) < 0.01) - { - AddSpeedX( 4/sqrt(2) ); - AddSpeedZ( -4/sqrt(2) ); - } - else - { - SetSpeedX( GetSpeedX() * 0.4 ); - SetSpeedZ( -GetSpeedZ() * 0.4 ); - } + SetSpeedX( GetSpeedX() * 0.4 ); + SetSpeedZ( -GetSpeedZ() * 0.4 ); } break; } @@ -921,14 +919,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() ); - if ( Distance.z == 0. ) + if (Distance.z == 0.) { Distance.z = 0.0001; } - if ( ((Distance.z>=0)&&((Distance.x/Distance.z)<=-1)) || ((Distance.z<0)&&((Distance.x/Distance.z)>=-1)) ) + 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) < 0.01) { AddSpeedX( 4/sqrt(2) ); AddSpeedZ( 4/sqrt(2) ); @@ -939,18 +938,15 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) SetSpeedZ( GetSpeedZ() * 0.4 ); } } + else if ((-GetSpeedX() * 0.4) < 0.01) + { + AddSpeedX( -4/sqrt(2) ); + AddSpeedZ( -4/sqrt(2) ); + } else { - if ((-GetSpeedX() * 0.4) < 0.01) - { - AddSpeedX( -4/sqrt(2) ); - AddSpeedZ( -4/sqrt(2) ); - } - else - { - SetSpeedX( -GetSpeedX() * 0.4 ); - SetSpeedZ( -GetSpeedZ() * 0.4 ); - } + SetSpeedX( -GetSpeedX() * 0.4 ); + SetSpeedZ( -GetSpeedZ() * 0.4 ); } break; } -- cgit v1.2.3 From e3a74f379fc103f40e6bf85e626d7bac7db236af Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Thu, 14 Aug 2014 14:29:46 +0200 Subject: Further changes in coding style --- src/Entities/Minecart.cpp | 66 ++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 45b9782f3..8e11d8a07 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -873,80 +873,70 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) case E_META_RAIL_CURVED_ZM_XM: case E_META_RAIL_CURVED_ZP_XP: { - Vector3d Distance( - MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(), - 0, - MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() - ); + Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ()); - if (Distance.z == 0.) - { - Distance.z = 0.0001; - } + Distance.z = std::max(Distance.z, 0.001); - if (((Distance.z >= 0) && ((Distance.x / Distance.z) >= 1)) || - ((Distance.z<0) && ((Distance.x / Distance.z) <= 1))) + if ( + ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) || + ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1)) + ) { if ((-GetSpeedX() * 0.4) < 0.01) { - AddSpeedX( -4/sqrt(2) ); - AddSpeedZ( 4/sqrt(2) ); + AddSpeedX(-4/sqrt(2)); + AddSpeedZ(4/sqrt(2)); } else { - SetSpeedX( -GetSpeedX() * 0.4 ); - SetSpeedZ( GetSpeedZ() * 0.4 ); + SetSpeedX(-GetSpeedX() * 0.4); + SetSpeedZ(GetSpeedZ() * 0.4); } } else if ((GetSpeedX() * 0.4) < 0.01) { - AddSpeedX( 4/sqrt(2) ); - AddSpeedZ( -4/sqrt(2) ); + AddSpeedX(4/sqrt(2)); + AddSpeedZ(-4/sqrt(2)); } else { - SetSpeedX( GetSpeedX() * 0.4 ); - SetSpeedZ( -GetSpeedZ() * 0.4 ); + SetSpeedX(GetSpeedX() * 0.4); + SetSpeedZ(-GetSpeedZ() * 0.4); } break; } case E_META_RAIL_CURVED_ZM_XP: case E_META_RAIL_CURVED_ZP_XM: { - Vector3d Distance( - MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(), - 0, - MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ() - ); + Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ()); - if (Distance.z == 0.) - { - Distance.z = 0.0001; - } + Distance.z = std::max(Distance.z, 0.001); - if (((Distance.z >= 0) && ((Distance.x / Distance.z) <= -1)) || - ((Distance.z<0) && ((Distance.x / Distance.z) >= -1))) + if ( + ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) || + ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1)) + ) { if ((GetSpeedX() * 0.4) < 0.01) { - AddSpeedX( 4/sqrt(2) ); - AddSpeedZ( 4/sqrt(2) ); + AddSpeedX(4/sqrt(2)); + AddSpeedZ(4/sqrt(2)); } else { - SetSpeedX( GetSpeedX() * 0.4 ); - SetSpeedZ( GetSpeedZ() * 0.4 ); + SetSpeedX(GetSpeedX() * 0.4); + SetSpeedZ(GetSpeedZ() * 0.4); } } else if ((-GetSpeedX() * 0.4) < 0.01) { - AddSpeedX( -4/sqrt(2) ); - AddSpeedZ( -4/sqrt(2) ); + AddSpeedX(-4/sqrt(2)); + AddSpeedZ(-4/sqrt(2)); } else { - SetSpeedX( -GetSpeedX() * 0.4 ); - SetSpeedZ( -GetSpeedZ() * 0.4 ); + SetSpeedX(-GetSpeedX() * 0.4); + SetSpeedZ(-GetSpeedZ() * 0.4); } break; } -- cgit v1.2.3 From 0f631febfc3f670e8e9eb60ec4f89659ad7d0c71 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Fri, 15 Aug 2014 13:40:56 +0200 Subject: Add some comments --- src/Entities/Minecart.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 8e11d8a07..0455c9ab3 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -875,17 +875,23 @@ 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)); + AddSpeedX(-4 / sqrt(2)); + AddSpeedZ(4 / sqrt(2)); } else { @@ -893,10 +899,10 @@ 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)); + AddSpeedX(4 / sqrt(2)); + AddSpeedZ(-4 / sqrt(2)); } else { @@ -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)) @@ -919,8 +930,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) { if ((GetSpeedX() * 0.4) < 0.01) { - AddSpeedX(4/sqrt(2)); - AddSpeedZ(4/sqrt(2)); + AddSpeedX(4 / sqrt(2)); + AddSpeedZ(4 / sqrt(2)); } else { @@ -930,8 +941,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) } else if ((-GetSpeedX() * 0.4) < 0.01) { - AddSpeedX(-4/sqrt(2)); - AddSpeedZ(-4/sqrt(2)); + AddSpeedX(-4 / sqrt(2)); + AddSpeedZ(-4 / sqrt(2)); } else { -- cgit v1.2.3 From be03b84048a49e04db11aa6ce80b3d18fff313b1 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Fri, 15 Aug 2014 13:43:45 +0200 Subject: End of comment moved away from new line --- src/Entities/Minecart.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 0455c9ab3..f190d972e 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -881,8 +881,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) /* 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. - */ + 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)) -- cgit v1.2.3 From c473d8cfb82009411f5a3977b7041ee49ba08003 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Fri, 15 Aug 2014 14:00:51 +0200 Subject: Clarify comment message --- src/Entities/Minecart.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index f190d972e..4753f720d 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -880,7 +880,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) /* 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. + The minecart moves along the line x = -z, the perpendicular line to this is x = z. 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)) || @@ -920,7 +920,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) /* 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. + The minecart moves along the line x = z, the perpendicular line to this is x = -z. 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)) || -- cgit v1.2.3 From 72c02ceb171949acd07338e77c8ee0d3439f8173 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Fri, 15 Aug 2014 17:54:43 +0200 Subject: Added a lot of comments --- src/Entities/Minecart.cpp | 66 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 4753f720d..9420eca02 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -876,7 +876,10 @@ 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); + if (abs(Distance.z) < 0.001) + { + 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). @@ -886,27 +889,27 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) || ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1)) ) - { - if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) - { + { // Moving -X + Z + if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ speedX >= 0 + { // Immobile or not moving in the "right" direction. Give it a bump! AddSpeedX(-4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } - else - { - SetSpeedX(-GetSpeedX() * 0.4); - SetSpeedZ(GetSpeedZ() * 0.4); + else // ~ SpeedX < 0 + { // Moving in the "right" direction. Only accelerate it a bit. + SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); + SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } - } - else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) - { + } // Moving +X -Z + else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ SpeedX <= 0 + { // Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } - else - { - SetSpeedX(GetSpeedX() * 0.4); - SetSpeedZ(-GetSpeedZ() * 0.4); + else // ~ SpeedX > 0 + { // Moving in the "right" direction + SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); + SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } break; } @@ -916,37 +919,40 @@ 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); + if (abs(Distance.z) < 0.001) + { + 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 x = z, the perpendicular line to this is x = -z. 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 ( + if ( // Moving +X +Z ((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) < 0.01) // ~ SpeedX <= 0 + { // Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } - else - { - SetSpeedX(GetSpeedX() * 0.4); - SetSpeedZ(GetSpeedZ() * 0.4); + else // SpeedX > 0 + { // Moving in the "right" direction + SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); + SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } - } - else if ((-GetSpeedX() * 0.4) < 0.01) - { + } // Moving -X -Z + else if ((-GetSpeedX() * 0.4) < 0.01) // ~ SpeedX >= 0 + { // Immobile or not moving in the "right" direction AddSpeedX(-4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } - else - { - SetSpeedX(-GetSpeedX() * 0.4); - SetSpeedZ(-GetSpeedZ() * 0.4); + else // ~ SpeedX < 0 + { // Moving in the "right" direction + SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); + SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } break; } -- cgit v1.2.3 From c70886a7124e5940b67cb4f1b4593f103f2707d8 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Mon, 18 Aug 2014 01:57:44 +0200 Subject: Adjust comment formatting --- src/Entities/Minecart.cpp | 60 +++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 9420eca02..13469edb3 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -889,25 +889,35 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) || ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1)) ) - { // Moving -X + Z - if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ speedX >= 0 - { // Immobile or not moving in the "right" direction. Give it a bump! + // Moving -X +Z + { + if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) + // ~ speedX >= 0 + { + // Immobile or not moving in the "right" direction. Give it a bump! AddSpeedX(-4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } - else // ~ SpeedX < 0 - { // Moving in the "right" direction. Only accelerate it a bit. + else + // ~ SpeedX < 0 + { + // Moving in the "right" direction. Only accelerate it a bit. SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } - } // Moving +X -Z - else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ SpeedX <= 0 - { // Immobile or not moving in the "right" direction + } + else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) + // Moving +X -Z + // ~ SpeedX <= 0 + { + // Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } - else // ~ SpeedX > 0 - { // Moving in the "right" direction + else + // ~ SpeedX > 0 + { + // Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } @@ -928,29 +938,39 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) Let's consider a z-x-coordinate system where the minecart is the center (0/0). The minecart moves along the line x = z, the perpendicular line to this is x = -z. 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 ( // Moving +X +Z + if ( ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) || ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1)) ) + // Moving +X +Z { - if ((GetSpeedX() * 0.4) < 0.01) // ~ SpeedX <= 0 - { // Immobile or not moving in the "right" direction + if ((GetSpeedX() * 0.4) < 0.01) + // ~ SpeedX <= 0 + { + // Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } - else // SpeedX > 0 - { // Moving in the "right" direction + else + // SpeedX > 0 + { + // Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } - } // Moving -X -Z - else if ((-GetSpeedX() * 0.4) < 0.01) // ~ SpeedX >= 0 - { // Immobile or not moving in the "right" direction + } + else if ((-GetSpeedX() * 0.4) < 0.01) + // Moving -X -Z + // ~ SpeedX >= 0 + { + // Immobile or not moving in the "right" direction AddSpeedX(-4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } - else // ~ SpeedX < 0 - { // Moving in the "right" direction + else + // ~ SpeedX < 0 + { + // Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } -- cgit v1.2.3 From a56634799e1fb7eef3d2817bd7d9c1b42969e934 Mon Sep 17 00:00:00 2001 From: Christophe Piveteau Date: Sun, 24 Aug 2014 15:03:02 +0200 Subject: Change comment formatting --- src/Entities/Minecart.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 13469edb3..f43c4d163 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -889,35 +889,31 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) || ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1)) ) - // Moving -X +Z { + // Moving -X +Z if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) - // ~ speedX >= 0 { - // Immobile or not moving in the "right" direction. Give it a bump! + // ~ SpeedX >= 0 Immobile or not moving in the "right" direction. Give it a bump! AddSpeedX(-4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } else - // ~ SpeedX < 0 { - // Moving in the "right" direction. Only accelerate it a bit. + // ~ SpeedX < 0 Moving in the "right" direction. Only accelerate it a bit. SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } } else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) - // Moving +X -Z - // ~ SpeedX <= 0 { - // Immobile or not moving in the "right" direction + // Moving +X -T + // ~ SpeedX <= 0 Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } else - // ~ SpeedX > 0 { - // Moving in the "right" direction + // ~ SpeedX > 0 Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } @@ -942,35 +938,31 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) || ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1)) ) - // Moving +X +Z { + // Moving +X +Z if ((GetSpeedX() * 0.4) < 0.01) - // ~ SpeedX <= 0 { - // Immobile or not moving in the "right" direction + // ~ SpeedX <= 0 Immobile or not moving in the "right" direction AddSpeedX(4 / sqrt(2)); AddSpeedZ(4 / sqrt(2)); } else - // SpeedX > 0 { - // Moving in the "right" direction + // ~ SpeedX > 0 Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } } else if ((-GetSpeedX() * 0.4) < 0.01) - // Moving -X -Z - // ~ SpeedX >= 0 { - // Immobile or not moving in the "right" direction + // Moving -X -Z + // ~ SpeedX >= 0 Immobile or not moving in the "right" direction AddSpeedX(-4 / sqrt(2)); AddSpeedZ(-4 / sqrt(2)); } else - // ~ SpeedX < 0 { - // Moving in the "right" direction + // ~ SpeedX < 0 Moving in the "right" direction SetSpeedX(GetSpeedX() * 0.4 / sqrt(2)); SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2)); } -- cgit v1.2.3