Added stairs collisions

feature/colissions-stairs
Nuno 3 years ago
parent 2304445c39
commit 8ea4ff53cb

@ -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,27 @@ public:
_Height=height;
}
void setZOffset(float offset)
{
_ZOffset = offset;
}
float getZOffset()
{
return _ZOffset;
}
bool haveZOffset()
{
return _HaveZOffset;
}
void enableZOffset(bool enabled)
{
_HaveZOffset = enabled;
}
/**
* Set the cylinder size. Only for cylinder.
*
@ -466,6 +487,10 @@ private:
// Iteration count
sint32 _IterationCount;
float _ZOffset;
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 setZOffset(float offset) =0;
virtual float getZOffset() =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,18 @@ 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());
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()-1.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;

@ -1024,9 +1024,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()+CVector(0, 0, 0.5f), dynamicWI);
}
else
{
primitive->setReactionType(UMovePrimitive::Slide);
primitive->setTriggerType(UMovePrimitive::NotATrigger);
primitive->setGlobalPosition(instance.getPos(), dynamicWI);
}
}
}

@ -1478,6 +1478,7 @@ 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);
}
}
@ -1713,6 +1714,12 @@ void CEntityCL::snapToGround()
pos().z = vect.z;
}
if (_Primitive->haveZOffset()) {
//CVectorD prim_pos = _Primitive->getFinalPosition(dynamicWI);
pos().z = _Primitive->getZOffset();
}
// Set the box position.
posBox(pos());
}// snapToGround //

@ -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::Blue;
isStairs = true;
position.z -= 1.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