Smooth the z displacement of entities

feature/colissions-stairs
Nuno 3 years ago
parent f0b74071ad
commit 85c80ab0f2

@ -251,16 +251,17 @@ public:
_Height=height; _Height=height;
} }
void setZOffset(float offset) void setZFinalPosition(float pos)
{ {
_ZOffset = offset; _ZFinalPosition = pos;
} }
float getZOffset() float getZFinalPosition()
{ {
return _ZOffset; return _ZFinalPosition;
} }
bool haveZOffset() bool haveZOffset()
{ {
return _HaveZOffset; return _HaveZOffset;
@ -489,6 +490,7 @@ private:
sint32 _IterationCount; sint32 _IterationCount;
float _ZOffset; float _ZOffset;
float _ZFinalPosition;
bool _HaveZOffset; bool _HaveZOffset;
}; };

@ -280,9 +280,9 @@ public:
*/ */
virtual float getHeight () const =0; virtual float getHeight () const =0;
virtual void setZOffset(float offset) =0; virtual void setZFinalPosition(float pos) =0;
virtual float getZOffset() =0; virtual float getZFinalPosition() =0;
virtual bool haveZOffset() =0; virtual bool haveZOffset() =0;

@ -1675,8 +1675,7 @@ void CMoveContainer::reaction (const CCollisionOTInfo& first)
dynInfo->getFirstPrimitive()->enableZOffset(true); dynInfo->getFirstPrimitive()->enableZOffset(true);
CVectorD first_pos = dynInfo->getFirstPrimitive()->getFinalPosition(dynInfo->getFirstWorldImage()); CVectorD first_pos = dynInfo->getFirstPrimitive()->getFinalPosition(dynInfo->getFirstWorldImage());
CVectorD second_pos = dynInfo->getSecondPrimitive()->getFinalPosition(dynInfo->getSecondWorldImage()); CVectorD second_pos = dynInfo->getSecondPrimitive()->getFinalPosition(dynInfo->getSecondWorldImage());
nlinfo("P = %f, C = %f, H = %f, D = %f", first_pos.z, second_pos.z, dynInfo->getSecondPrimitive()->getHeight(), second_pos.z-first_pos.z); dynInfo->getFirstPrimitive()->setZFinalPosition(second_pos.z+dynInfo->getSecondPrimitive()->getHeight()-10.0f);
dynInfo->getFirstPrimitive()->setZOffset(second_pos.z+dynInfo->getSecondPrimitive()->getHeight()-10.0f);
} }
} }
if (dynInfo->isExit()) if (dynInfo->isExit())

@ -740,6 +740,8 @@ void CEntityCL::init()
_EntityName = "Name"; _EntityName = "Name";
} }
_NameId = 0; _NameId = 0;
_LastSnapToGroup = 0;
_CurrentZOffset = 0;
_PermanentStatutIcon.clear(); _PermanentStatutIcon.clear();
@ -1481,6 +1483,17 @@ void CEntityCL::pacsMove(const CVectorD &vect)
_Primitive->enableZOffset(false); _Primitive->enableZOffset(false);
_Primitive->move (deltaPos, dynamicWI); _Primitive->move (deltaPos, dynamicWI);
} }
else
{
// This code force the player to move even when not moving, it's used to trigger special collissions
if (isUser())
{
_HasMoved = true;
deltaPos.x = 0.0001;
_Primitive->move (deltaPos, dynamicWI);
}
}
} }
else else
{ {
@ -1714,11 +1727,42 @@ void CEntityCL::snapToGround()
pos().z = vect.z; pos().z = vect.z;
} }
if (_Primitive->haveZOffset()) { if (_Primitive->haveZOffset())
//CVectorD prim_pos = _Primitive->getFinalPosition(dynamicWI); {
pos().z = _Primitive->getZOffset();
if (_LastSnapToGroup > 0)
{
if (pos().z + _CurrentZOffset < _Primitive->getZFinalPosition())
{
_CurrentZOffset += (ryzomGetLocalTime() - _LastSnapToGroup)/100.0f;
if (pos().z + _CurrentZOffset > _Primitive->getZFinalPosition())
_CurrentZOffset = _Primitive->getZFinalPosition() - pos().z;
} }
if (pos().z + _CurrentZOffset > _Primitive->getZFinalPosition())
{
_CurrentZOffset -= (ryzomGetLocalTime() - _LastSnapToGroup)/100.0f;
if (pos().z + _CurrentZOffset < _Primitive->getZFinalPosition())
_CurrentZOffset = _Primitive->getZFinalPosition() - pos().z;
}
pos().z += _CurrentZOffset;
}
}
else
{
if (_CurrentZOffset > 0)
{
_CurrentZOffset -= (ryzomGetLocalTime() - _LastSnapToGroup)/100.0f;
if (_CurrentZOffset < 0)
_CurrentZOffset = 0;
pos().z += _CurrentZOffset;
}
}
_LastSnapToGroup = ryzomGetLocalTime();
// Set the box position. // Set the box position.
posBox(pos()); posBox(pos());

@ -949,6 +949,10 @@ protected:
uint32 _NameId; uint32 _NameId;
// Primitive used for the collision in PACS // Primitive used for the collision in PACS
NLPACS::UMovePrimitive *_Primitive; NLPACS::UMovePrimitive *_Primitive;
uint64 _LastSnapToGroup;
float _CurrentZOffset;
// 3D Logic info for light request. // 3D Logic info for light request.
CEntityLogicInfo3D _LogicInfo3D; CEntityLogicInfo3D _LogicInfo3D;
// Box around the entity. // Box around the entity.

Loading…
Cancel
Save