summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-01-06 20:32:40 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-01-06 20:32:40 +0100
commit8798c529d2505885f921c0422bb3a3314d2fe058 (patch)
tree8a7d39a0e0f5f13f97b4b0b352d6e7f45206e965
parentAdded version 1.4.7 to the list of supported versions. (diff)
downloadcuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar.gz
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar.bz2
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar.lz
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar.xz
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.tar.zst
cuberite-8798c529d2505885f921c0422bb3a3314d2fe058.zip
-rw-r--r--source/Pickup.cpp70
1 files changed, 40 insertions, 30 deletions
diff --git a/source/Pickup.cpp b/source/Pickup.cpp
index b2290ab73..1dce2f2ea 100644
--- a/source/Pickup.cpp
+++ b/source/Pickup.cpp
@@ -102,19 +102,20 @@ void cPickup::HandlePhysics(float a_Dt)
{
m_ResultingSpeed.Set(0.f, 0.f, 0.f);
cWorld * World = GetWorld();
+
+ a_Dt /= 1000; // Go from msec to sec, so that physics formulas work
- if( m_bOnGround ) // check if it's still on the ground
+ if (m_bOnGround) // check if it's still on the ground
{
- int BlockX = (m_Pos.x)<0 ? (int)m_Pos.x-1 : (int)m_Pos.x;
- int BlockZ = (m_Pos.z)<0 ? (int)m_Pos.z-1 : (int)m_Pos.z;
- char BlockBelow = World->GetBlock( BlockX, (int)m_Pos.y -1, BlockZ );
- //Not only air, falls through water ;)
- if( BlockBelow == E_BLOCK_AIR || IsBlockWater(BlockBelow))
+ int BlockX = (m_Pos.x < 0) ? (int)m_Pos.x - 1 : (int)m_Pos.x;
+ int BlockZ = (m_Pos.z < 0) ? (int)m_Pos.z - 1 : (int)m_Pos.z;
+ char BlockBelow = World->GetBlock(BlockX, (int)m_Pos.y - 1, BlockZ);
+ if (BlockBelow == E_BLOCK_AIR || IsBlockWater(BlockBelow))
{
m_bOnGround = false;
}
- char Block = World->GetBlock( BlockX, (int)m_Pos.y - (int)m_bOnGround, BlockZ );
- char BlockIn = World->GetBlock( BlockX, (int)m_Pos.y, BlockZ );
+ char Block = World->GetBlock(BlockX, (int)m_Pos.y - (int)m_bOnGround, BlockZ );
+ char BlockIn = World->GetBlock(BlockX, (int)m_Pos.y, BlockZ );
if( IsBlockLava(Block) || Block == E_BLOCK_FIRE
|| IsBlockLava(BlockIn) || BlockIn == E_BLOCK_FIRE)
@@ -130,10 +131,10 @@ void cPickup::HandlePhysics(float a_Dt)
m_Pos.y += 0.2;
m_bReplicated = false;
}
- m_Speed.x *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed.x) < 0.05 ) m_Speed.x = 0;
- m_Speed.z *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed.z) < 0.05 ) m_Speed.z = 0;
+ m_Speed.x *= 0.7f / (1 + a_Dt);
+ if (fabs(m_Speed.x) < 0.05) m_Speed.x = 0;
+ m_Speed.z *= 0.7f / (1 + a_Dt);
+ if (fabs(m_Speed.z) < 0.05) m_Speed.z = 0;
}
// get flowing direction
@@ -165,34 +166,43 @@ void cPickup::HandlePhysics(float a_Dt)
}
m_ResultingSpeed += m_WaterSpeed;
-
- if( !m_bOnGround )
+ if (!m_bOnGround)
{
- float Gravity = -9.81f*a_Dt;
+ float Gravity = -9.81f * a_Dt;
+ if (Gravity < -3) // Cap gravity-caused speed at 3 m / sec
+ {
+ Gravity = -3;
+ }
m_Speed.y += Gravity;
// Set to hit position
m_ResultingSpeed += m_Speed;
-
- cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( m_Pos, m_Speed, 2 );
- if( Ret ) // Oh noez! we hit something
+
+ /*
+ LOGD("Pickup #%d speed: {%.03f, %.03f, %.03f}, pos {%.02f, %.02f, %.02f}",
+ m_UniqueID,
+ m_ResultingSpeed.x, m_ResultingSpeed.y, m_ResultingSpeed.z,
+ m_Pos.x, m_Pos.y, m_Pos.z
+ );
+ */
+
+ cTracer Tracer(GetWorld());
+ int Ret = Tracer.Trace(m_Pos, m_Speed, 2);
+ if (Ret) // Oh noez! we hit something
{
-
-
- if( (Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength() )
+ if ((Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength())
{
m_bReplicated = false; // It's only interesting to replicate when we actually hit something...
- if( Ret == 1 )
+ if (Ret == 1)
{
- if( Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
- if( Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
- if( Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
+ if (Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
+ if (Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
+ if (Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
- if( Tracer.HitNormal.y > 0 ) // means on ground
+ if (Tracer.HitNormal.y > 0) // means on ground
{
m_bOnGround = true;
}
@@ -202,15 +212,15 @@ void cPickup::HandlePhysics(float a_Dt)
}
else
- m_Pos += m_ResultingSpeed*a_Dt;
+ m_Pos += m_ResultingSpeed * a_Dt;
}
else
{ // We didn't hit anything, so move =]
m_Pos += m_ResultingSpeed * a_Dt;
}
}
- //Usable for debugging
- //SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
+ // Usable for debugging
+ SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
}