From 85c80ab0f2bb7ed7fcc20dba668bdcb1c3fb4786 Mon Sep 17 00:00:00 2001 From: Nuno Date: Fri, 26 Nov 2021 19:13:53 +0100 Subject: [PATCH] Smooth the z displacement of entities --- nel/include/nel/pacs/move_primitive.h | 10 +++-- nel/include/nel/pacs/u_move_primitive.h | 4 +- nel/src/pacs/move_container.cpp | 3 +- ryzom/client/src/entity_cl.cpp | 50 +++++++++++++++++++++++-- ryzom/client/src/entity_cl.h | 8 +++- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/nel/include/nel/pacs/move_primitive.h b/nel/include/nel/pacs/move_primitive.h index d77517a7d..928ed10fc 100644 --- a/nel/include/nel/pacs/move_primitive.h +++ b/nel/include/nel/pacs/move_primitive.h @@ -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; }; diff --git a/nel/include/nel/pacs/u_move_primitive.h b/nel/include/nel/pacs/u_move_primitive.h index e067c3e6b..cba266174 100644 --- a/nel/include/nel/pacs/u_move_primitive.h +++ b/nel/include/nel/pacs/u_move_primitive.h @@ -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; diff --git a/nel/src/pacs/move_container.cpp b/nel/src/pacs/move_container.cpp index 4d093ae6a..c313fefb9 100644 --- a/nel/src/pacs/move_container.cpp +++ b/nel/src/pacs/move_container.cpp @@ -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()) diff --git a/ryzom/client/src/entity_cl.cpp b/ryzom/client/src/entity_cl.cpp index c523449a1..616363f0b 100644 --- a/ryzom/client/src/entity_cl.cpp +++ b/ryzom/client/src/entity_cl.cpp @@ -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()); diff --git a/ryzom/client/src/entity_cl.h b/ryzom/client/src/entity_cl.h index f2f99b347..092a85dd3 100644 --- a/ryzom/client/src/entity_cl.h +++ b/ryzom/client/src/entity_cl.h @@ -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.