Compare commits

...

3 Commits

@ -244,7 +244,7 @@ private:
CCollisionOTStaticInfo *staticColInfo);
// Add a trigger in the trigger array
void newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc, uint triggerType);
bool newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc, uint triggerType);
// Clear modified primitive list
void clearModifiedList (uint8 worldImage);

@ -251,6 +251,28 @@ public:
_Height=height;
}
void setZFinalPosition(float pos)
{
_ZFinalPosition = pos;
}
float getZFinalPosition()
{
return _ZFinalPosition;
}
bool haveZOffset()
{
return _HaveZOffset;
}
void enableZOffset(bool enabled)
{
_HaveZOffset = enabled;
}
/**
* Set the cylinder size. Only for cylinder.
*
@ -466,6 +488,11 @@ private:
// Iteration count
sint32 _IterationCount;
float _ZOffset;
float _ZFinalPosition;
bool _HaveZOffset;
};
} // NLPACS

@ -114,6 +114,12 @@ public:
* This is an overlap trigger. This trigger is actived each time the object overlap the trigger.
*/
OverlapTrigger=0x400,
/**
* This is an stairs trigger. This trigger is actived each time the object overlap the trigger and change Z position.
*/
OverlapStairsTrigger=0x800,
};
/**
@ -274,6 +280,14 @@ public:
*/
virtual float getHeight () const =0;
virtual void setZFinalPosition(float pos) =0;
virtual float getZFinalPosition() =0;
virtual bool haveZOffset() =0;
virtual void enableZOffset(bool enabled) =0;
/**
* Set the cylinder size. Only for cylinder.
*

@ -918,8 +918,10 @@ bool CMoveContainer::evalPrimAgainstPrimCollision (double beginTime, CMovePrimit
|| (otherPrimitive->getTriggerType()&UMovePrimitive::EnterTrigger));
bool exit = (beginTime<=lastTime) && (lastTime<_DeltaTime) && ((primitive->getTriggerType()&UMovePrimitive::ExitTrigger)
|| (otherPrimitive->getTriggerType()&UMovePrimitive::ExitTrigger));
bool overlap = (firstTime<=beginTime) && (lastTime>_DeltaTime) && ((primitive->getTriggerType()&UMovePrimitive::OverlapTrigger)
|| (otherPrimitive->getTriggerType()&UMovePrimitive::OverlapTrigger));
bool overlap = ((firstTime<=beginTime) && (lastTime>_DeltaTime) && ((primitive->getTriggerType()&UMovePrimitive::OverlapTrigger)
|| (otherPrimitive->getTriggerType()&UMovePrimitive::OverlapTrigger)) ||
(firstTime<=beginTime) && (lastTime>_DeltaTime) && ((primitive->getTriggerType()&UMovePrimitive::OverlapStairsTrigger)
|| (otherPrimitive->getTriggerType()&UMovePrimitive::OverlapStairsTrigger)));
bool contact = ( beginTime<((firstTime+lastTime)/2) ) && (firstTime<=_DeltaTime);
bool collision = contact && (primitive->isObstacle() && otherPrimitive->isObstacle ());
@ -1211,7 +1213,7 @@ void CMoveContainer::newCollision (CMovePrimitive* first, const CCollisionSurfac
// ***************************************************************************
void CMoveContainer::newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc, uint triggerType)
bool CMoveContainer::newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc, uint triggerType)
{
// Element index
uint index=(uint)_Triggers.size();
@ -1224,6 +1226,14 @@ void CMoveContainer::newTrigger (CMovePrimitive* first, CMovePrimitive* second,
_Triggers[index].Object1=second->UserData;
_Triggers[index].CollisionDesc=desc;
_Triggers[index].CollisionType = uint8(triggerType);
if (second->_StaticFlags&UMovePrimitive::OverlapStairsTrigger) {
nlinfo("Col Stairs height %f", second->getHeight());
return true;
}
return false;
}
// ***************************************************************************
@ -1659,8 +1669,17 @@ void CMoveContainer::reaction (const CCollisionOTInfo& first)
newTrigger (dynInfo->getFirstPrimitive (), dynInfo->getSecondPrimitive (), dynInfo->getCollisionDesc (), UTriggerInfo::In);
if (dynInfo->isExit())
newTrigger (dynInfo->getFirstPrimitive (), dynInfo->getSecondPrimitive (), dynInfo->getCollisionDesc (), UTriggerInfo::Out);
if (dynInfo->isInside())
newTrigger (dynInfo->getFirstPrimitive (), dynInfo->getSecondPrimitive (), dynInfo->getCollisionDesc (), UTriggerInfo::Inside);
if (dynInfo->isInside()) {
if (newTrigger (dynInfo->getFirstPrimitive (), dynInfo->getSecondPrimitive (), dynInfo->getCollisionDesc (), UTriggerInfo::Inside))
{
dynInfo->getFirstPrimitive()->enableZOffset(true);
CVectorD first_pos = dynInfo->getFirstPrimitive()->getFinalPosition(dynInfo->getFirstWorldImage());
CVectorD second_pos = dynInfo->getSecondPrimitive()->getFinalPosition(dynInfo->getSecondWorldImage());
dynInfo->getFirstPrimitive()->setZFinalPosition(second_pos.z+dynInfo->getSecondPrimitive()->getHeight()-10.0f);
}
}
if (dynInfo->isExit())
newTrigger (dynInfo->getFirstPrimitive (), dynInfo->getSecondPrimitive (), dynInfo->getCollisionDesc (), UTriggerInfo::Out);
}
}
}

@ -49,6 +49,8 @@ CMovePrimitive::CMovePrimitive (CMoveContainer* container, uint8 firstWorldImage
_StaticFlags=0;
_RootOTInfo=NULL;
_LastTestTime=0xffffffff;
_ZOffset = 0;
_HaveZOffset = false;
// Ptr table alloc
_WorldImages=_Container->allocateWorldImagesPtrs (numWorldImage);
@ -149,6 +151,11 @@ bool CMovePrimitive::isTriggered (CMovePrimitive& second, bool enter, bool exit)
{
// Generate a trigger ?
// Is one of them is a stairs trigger ?
if ( second._StaticFlags&OverlapStairsTrigger )
return true;
// Is the two are not triggers ?
if ( ( (_StaticFlags&TriggerMask) == NotATrigger ) && ( (second._StaticFlags&TriggerMask) == NotATrigger ) )
return false;

@ -426,7 +426,7 @@ void CCharacterCL::computePrimitive()
// Initialize the primitive.
if (_Sheet)
{
initPrimitive(_Sheet->ColRadius*getScale(), _Sheet->ColHeight*getScale(), _Sheet->ColLength, _Sheet->ColWidth, UMovePrimitive::DoNothing, UMovePrimitive::NotATrigger, MaskColNpc, MaskColNone, _Sheet->ClipRadius, _Sheet->ClipHeight);
initPrimitive(_Sheet->ColRadius*getScale(), _Sheet->ColHeight*getScale(), _Sheet->ColLength, _Sheet->ColWidth, UMovePrimitive::DoNothing, (UMovePrimitive::TTrigger)(UMovePrimitive::OverlapTrigger | UMovePrimitive::EnterTrigger), MaskColNpc, MaskColDoor, _Sheet->ClipRadius, _Sheet->ClipHeight);
}
else
{
@ -976,7 +976,7 @@ bool CCharacterCL::build(const CEntitySheet *sheet) // virtual
_CustomScalePos *= getScale();
// Create PACS Primitive.
initPrimitive(_Sheet->ColRadius*getScale(), _Sheet->ColHeight*getScale(), _Sheet->ColLength, _Sheet->ColWidth, UMovePrimitive::DoNothing, UMovePrimitive::NotATrigger, MaskColNpc, MaskColNone, _Sheet->ClipRadius, _Sheet->ClipHeight);
initPrimitive(_Sheet->ColRadius*getScale(), _Sheet->ColHeight*getScale(), _Sheet->ColLength, _Sheet->ColWidth, UMovePrimitive::DoNothing, (UMovePrimitive::TTrigger)(UMovePrimitive::OverlapTrigger | UMovePrimitive::EnterTrigger), MaskColNpc, MaskColDoor, _Sheet->ClipRadius, _Sheet->ClipHeight);
// Compute the element to be able to snap the entity to the ground.
computeCollisionEntity();

@ -945,6 +945,8 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
float height = primitive->getHeight();
CVector size = CVector(width, depth, height);
if (primitive->getTriggerType() == UMovePrimitive::OverlapStairsTrigger)
size.z -= 10.0f;
float v;
if (getRelativeFloatFromString(values[i], v))
{
@ -954,6 +956,8 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
{
updateVector(param, size, v, false);
}
if (primitive->getTriggerType() == UMovePrimitive::OverlapStairsTrigger)
size.z += 10.0f;
primitive->setSize(size.x, size.y);
primitive->setHeight(size.z);
}
@ -1024,9 +1028,23 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
fromString(values[i], active);
primitive->setObstacle(active);
}
else if (param == "col obstacle")
else if (param == "col stairs")
{
bool active;
fromString(values[i], active);
primitive->setObstacle(!active);
if (active)
{
primitive->setReactionType(UMovePrimitive::DoNothing);
primitive->setTriggerType(UMovePrimitive::OverlapStairsTrigger);
primitive->setGlobalPosition(instance.getPos(), dynamicWI);
}
else
{
primitive->setReactionType(UMovePrimitive::Slide);
primitive->setTriggerType(UMovePrimitive::NotATrigger);
primitive->setGlobalPosition(instance.getPos(), dynamicWI);
}
}
}

@ -740,6 +740,8 @@ void CEntityCL::init()
_EntityName = "Name";
}
_NameId = 0;
_LastSnapToGroup = 0;
_CurrentZOffset = 0;
_PermanentStatutIcon.clear();
@ -1478,8 +1480,20 @@ void CEntityCL::pacsMove(const CVectorD &vect)
if ((fabs (deltaPos.x) > 0.05) || (fabs (deltaPos.y) > 0.05))
{
_HasMoved = true;
_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
{
@ -1713,6 +1727,43 @@ void CEntityCL::snapToGround()
pos().z = vect.z;
}
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());
}// snapToGround //

@ -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.

@ -2982,15 +2982,41 @@ CVector PacsBox[PacsBoxPointCount] =
CVector( 0.5f, 0.5f, 0), CVector( -0.5f, 0.5f, 0),
CVector( -0.5f, 0.5f, 0), CVector( -0.5f, -0.5f, 0),
CVector( -0.5f, -0.5f, 0), CVector( -0.5f, -0.5f, 1),
CVector( 0.5f, -0.5f, 0), CVector( 0.5f, -0.5f, 1),
CVector( 0.5f, 0.5f, 0), CVector( 0.5f, 0.5f, 1),
CVector( -0.5f, 0.5f, 0), CVector( -0.5f, 0.5f, 1),
CVector( -0.5f, -0.5f, 1), CVector( 0.5f, -0.5f, 1),
CVector( 0.5f, -0.5f, 1), CVector( 0.5f, 0.5f, 1),
CVector( 0.5f, 0.5f, 1), CVector( -0.5f, 0.5f, 1),
CVector( -0.5f, 0.5f, 1), CVector( -0.5f, -0.5f, 1),
};
const uint PacsStairPointCount = 32;
CVector PacsStair[PacsStairPointCount] =
{
CVector( -0.5f, -0.5f, 0), CVector( 0.5f, -0.5f, 0),
CVector( 0.5f, -0.5f, 0), CVector( 0.5f, 0.5f, 0),
CVector( 0.5f, 0.5f, 0), CVector( -0.5f, 0.5f, 0),
CVector( -0.5f, 0.5f, 0), CVector( -0.5f, -0.5f, 0),
CVector( -0.5f, -0.5f, 0), CVector( -0.5f, -0.5f, 1),
CVector( 0.5f, -0.5f, 0), CVector( 0.5f, -0.5f, 1),
CVector( 0.5f, 0.5f, 0), CVector( 0.5f, 0.5f, 1),
CVector( -0.5f, 0.5f, 0), CVector( -0.5f, 0.5f, 1),
CVector( -0.5f, -0.5f, 1), CVector( 0.5f, -0.5f, 1),
CVector( 0.5f, -0.5f, 1), CVector( 0.5f, 0.5f, 1),
CVector( 0.5f, 0.5f, 1), CVector( -0.5f, 0.5f, 1),
CVector( -0.5f, 0.5f, 1), CVector( -0.5f, -0.5f, 1),
CVector( -0.5f, -0.5f, 1), CVector( 0.5f, 0.5f, 1),
CVector( -0.5f, 0.5f, 1), CVector( 0.5f, -0.5f, 1),
CVector( -0.5f, 0, 1), CVector( 0.5f, 0, 1),
CVector( 0, - 0.5f, 1), CVector( 0, 0.5f, 1),
};
const uint PacsCylPointCount = 48;
@ -3044,6 +3070,7 @@ void displayPACSPrimitive()
// Distance
CVector position = prim->getFinalPosition(wI);
bool isStairs = false;
if ((position-UserEntity->pos()).sqrnorm() < (200*200))
{
// Choose a color
@ -3051,8 +3078,14 @@ void displayPACSPrimitive()
if (prim->isCollisionable())
{
// Static collision
if (prim->getReactionType() == UMovePrimitive::DoNothing)
if (prim->getTriggerType() == UMovePrimitive::OverlapStairsTrigger)
{
line.Color0 = CRGBA::Green;
isStairs = true;
position.z -= 10.0f;
}
else if (prim->getReactionType() == UMovePrimitive::DoNothing)
{
line.Color0 = CRGBA::Red;
}
else
@ -3082,8 +3115,16 @@ void displayPACSPrimitive()
// Draw the primitive
if (prim->getPrimitiveType() == UMovePrimitive::_2DOrientedBox)
{
lines = PacsBox;
linecount = PacsBoxPointCount/2;
if (isStairs)
{
lines = PacsStair;
linecount = PacsStairPointCount/2;
}
else
{
lines = PacsBox;
linecount = PacsBoxPointCount/2;
}
float width;
float depth;
prim->getSize (width, depth);

Loading…
Cancel
Save