summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-01 23:39:37 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-01 23:39:37 +0200
commit284c1c0514168e30338f2ad372b7e7f185dba0c4 (patch)
tree66e9ef12dda74a3c5e48b0ce8aa96427e903ff40 /src
parentImplemented Vector3<>::Floor() (diff)
downloadcuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar.gz
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar.bz2
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar.lz
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar.xz
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.tar.zst
cuberite-284c1c0514168e30338f2ad372b7e7f185dba0c4.zip
Diffstat (limited to 'src')
-rw-r--r--src/Entities/ArrowEntity.cpp12
-rw-r--r--src/Vector3.h33
2 files changed, 24 insertions, 21 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index 2d6683f0a..7e96a666d 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -69,14 +69,18 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
Vector3d Hit = a_HitPos;
- Vector3d SinkMovement = GetSpeed() / 800;
- SinkMovement.Clamp(0.001, 0.001, 0.001, 0.05, 0.05, 0.05);
+ Vector3d SinkMovement = GetSpeed() / 800; // Base value for arrow penetration
+ SinkMovement = Clamp( // Adjust the movement so that fast arrows don't go through blocks (though in reality they would, in addition to exploding into fragments :P)
+ SinkMovement,
+ (SinkMovement * 0.001) / SinkMovement.Length(),
+ (SinkMovement * 0.05) / SinkMovement.Length()
+ );
Hit += SinkMovement; // Make arrow sink into block a little
super::OnHitSolidBlock(Hit, a_HitFace);
- Hit.Floor();
+ Vector3i BlockHit = Hit.Floor();
- int X = Hit.x, Y = Hit.y, Z = Hit.z;
+ int X = BlockHit.x, Y = BlockHit.y, Z = BlockHit.z;
m_HitBlockPos = Vector3i(X, Y, Z);
// Broadcast arrow hit sound
diff --git a/src/Vector3.h b/src/Vector3.h
index b5ddc705a..faf7fe43c 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -135,19 +135,13 @@ public:
}
/** Runs each value of the vector through std::floor() */
- inline void Floor(void)
+ inline Vector3<T> Floor(void) const
{
- x = (T)floor(x);
- y = (T)floor(y);
- z = (T)floor(z);
- }
-
- /** Clamps each value in the vector to within a specified range */
- inline void Clamp(T a_MinX, T a_MinY, T a_MinZ, T a_MaxX, T a_MaxY, T a_MaxZ)
- {
- x = Clamp(x, (T)copysign(a_MinX, x), (T)copysign(a_MaxX, x));
- y = Clamp(y, (T)copysign(a_MinY, y), (T)copysign(a_MaxY, y));
- z = Clamp(z, (T)copysign(a_MinZ, z), (T)copysign(a_MaxZ, z));
+ return Vector3<T>(
+ (T)floor(x),
+ (T)floor(y),
+ (T)floor(z)
+ );
}
// tolua_end
@@ -162,6 +156,16 @@ public:
return Equals(a_Rhs);
}
+ inline bool operator > (const Vector3<T> & a_Rhs) const
+ {
+ return (SqrLength() > a_Rhs.SqrLength());
+ }
+
+ inline bool operator < (const Vector3<T> & a_Rhs) const
+ {
+ return (SqrLength() < a_Rhs.SqrLength());
+ }
+
inline void operator += (const Vector3<T> & a_Rhs)
{
x += a_Rhs.x;
@@ -305,11 +309,6 @@ protected:
return (a_Value < 0) ? -a_Value : a_Value;
}
- /** Clamp X to the specified range. */
- T Clamp(T a_Value, T a_Min, T a_Max)
- {
- return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
- }
};
// tolua_end