More checks for DOBs moving outside current room

This commit is contained in:
lawnjelly 2020-01-27 19:56:46 +00:00 committed by GitHub
parent 277fe59930
commit 533c40baa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 4 deletions

View File

@ -52,14 +52,14 @@ float LBound::GetSmallestPenetrationDistance(const Vector3 &pt) const
} }
bool LBound::IsPointWithin(const Vector3 &pt) const bool LBound::IsPointWithin(const Vector3 &pt, float epsilon) const
{ {
for (int n=0; n<m_Planes.size(); n++) for (int n=0; n<m_Planes.size(); n++)
{ {
float d = m_Planes[n].distance_to(pt); float d = m_Planes[n].distance_to(pt);
// if in front of plane, outside the convex hull // if in front of plane, outside the convex hull
if (d > 0.0f) if (d > epsilon)
return false; return false;
} }

View File

@ -30,7 +30,7 @@
class LBound class LBound
{ {
public: public:
bool IsPointWithin(const Vector3 &pt) const; bool IsPointWithin(const Vector3 &pt, float epsilon = 0.0f) const;
// get distance behind all planes and return the smallest.. // get distance behind all planes and return the smallest..
// if inside this will be negative, if outside, positive // if inside this will be negative, if outside, positive

View File

@ -99,6 +99,20 @@ LRoom * LRoom::DOB_Update(LRoomManager &manager, Spatial * pDOB)
if (bCamera) if (bCamera)
slop = 0.0f; slop = 0.0f;
// deal with the case that the DOB has moved way outside the room
if (!m_Bound.IsPointWithin(pt, 1.0f))
{
// revert to expensive method (may have been teleported etc)
int iRoomNum = manager.FindClosestRoom(pt);
//print_line("dob_teleport closest room " + itos(iRoomNum));
if (iRoomNum == -1)
return 0;
return manager.GetRoom(iRoomNum);
}
// the camera can't have slop because we might end up front side of a door without entering the room, // the camera can't have slop because we might end up front side of a door without entering the room,
// hence can't see into the room through the portal! // hence can't see into the room through the portal!
// if (bCamera) // if (bCamera)

View File

@ -219,7 +219,7 @@ void LRoomConverter::Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &l
// ignore invisible // ignore invisible
Spatial * pSpatialChild = Object::cast_to<Spatial>(pChild); Spatial * pSpatialChild = Object::cast_to<Spatial>(pChild);
if (pSpatialChild && (pSpatialChild->is_visible_in_tree() == false)) if (pSpatialChild && (Convert_IsVisibleInRooms(pSpatialChild) == false))
{ {
pSpatialChild->queue_delete(); pSpatialChild->queue_delete();
continue; continue;
@ -287,6 +287,29 @@ void LRoomConverter::Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &l
} }
bool LRoomConverter::Convert_IsVisibleInRooms(const Node * pNode) const
{
const Spatial * pS = Object::cast_to<Spatial>(pNode);
const Spatial * pRoomList = Object::cast_to<Spatial>(LROOMLIST);
while (pS)
{
if (!pS->is_visible())
{
return false;
}
pS = pS->get_parent_spatial();
// terminate
if (pS == pRoomList)
return true;
}
return true;
}
// areaID could be -1 if unset // areaID could be -1 if unset
bool LRoomConverter::Convert_Room(Spatial * pNode, int lroomID, int areaID) bool LRoomConverter::Convert_Room(Spatial * pNode, int lroomID, int areaID)
{ {

View File

@ -94,6 +94,7 @@ private:
bool Convert_Room(Spatial * pNode, int lroomID, int areaID); bool Convert_Room(Spatial * pNode, int lroomID, int areaID);
void Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &lroom, LAABB &bb_room); void Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &lroom, LAABB &bb_room);
void Convert_Room_SetDefaultCullMask_Recursive(Node * pParent); void Convert_Room_SetDefaultCullMask_Recursive(Node * pParent);
bool Convert_IsVisibleInRooms(const Node * pNode) const;
void Convert_Portals(); void Convert_Portals();
void Convert_Bounds(); void Convert_Bounds();