Smooth the z displacement of entities

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

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

@ -280,9 +280,9 @@ public:
*/
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;

@ -1675,8 +1675,7 @@ void CMoveContainer::reaction (const CCollisionOTInfo& first)
dynInfo->getFirstPrimitive()->enableZOffset(true);
CVectorD first_pos = dynInfo->getFirstPrimitive()->getFinalPosition(dynInfo->getFirstWorldImage());
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()->setZOffset(second_pos.z+dynInfo->getSecondPrimitive()->getHeight()-10.0f);
dynInfo->getFirstPrimitive()->setZFinalPosition(second_pos.z+dynInfo->getSecondPrimitive()->getHeight()-10.0f);
}
}
if (dynInfo->isExit())

@ -740,6 +740,8 @@ void CEntityCL::init()
_EntityName = "Name";
}
_NameId = 0;
_LastSnapToGroup = 0;
_CurrentZOffset = 0;
_PermanentStatutIcon.clear();
@ -1481,6 +1483,17 @@ void CEntityCL::pacsMove(const CVectorD &vect)
_Primitive->enableZOffset(false);
_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
{
@ -1714,11 +1727,42 @@ void CEntityCL::snapToGround()
pos().z = vect.z;
}
if (_Primitive->haveZOffset()) {
//CVectorD prim_pos = _Primitive->getFinalPosition(dynamicWI);
pos().z = _Primitive->getZOffset();
if (_Primitive->haveZOffset())
{
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.
posBox(pos());

@ -241,7 +241,7 @@ public:
/// Return the persistent NPC alias of entity (0 if N/A).
uint32 npcAlias() const {return _NPCAlias; }
/// Set the persistent NPC alias of the entity.
/// Set the persistent NPC alias of the entity.
void npcAlias(uint32 alias) {_NPCAlias = alias; }
/// Method to call to initialize all members of the right class.
@ -702,7 +702,7 @@ public:
// todo handle NPC entities
// Return true if this entity is a NPC (not a fauna)
bool isNPC () const { return Type == NPC; }
// Return true if this entity can have missions icons (humanoid NPCs (including Karavan), Kami or Bot Object)
bool canHaveMissionIcon() const { return isNPC() || isKami() || isUnknownRace(); }
@ -949,6 +949,10 @@ protected:
uint32 _NameId;
// Primitive used for the collision in PACS
NLPACS::UMovePrimitive *_Primitive;
uint64 _LastSnapToGroup;
float _CurrentZOffset;
// 3D Logic info for light request.
CEntityLogicInfo3D _LogicInfo3D;
// Box around the entity.

Loading…
Cancel
Save