Camera dob updated in frame update

This commit is contained in:
lawnjelly 2020-01-14 11:17:59 +00:00 committed by GitHub
parent 3aa5f77182
commit 3d5945fd5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 12 deletions

View File

@ -27,18 +27,24 @@
// get distance behind all planes and return the smallest..
// if inside this will be negative, if outside, positive
float LBound::GetClosestDistance(const Vector3 &pt) const
float LBound::GetSmallestPenetrationDistance(const Vector3 &pt) const
{
assert (m_Planes.size());
float closest = FLT_MAX;
float closest = -FLT_MAX;
for (int n=0; n<m_Planes.size(); n++)
{
float d = m_Planes[n].distance_to(pt);
// if in front of plane, outside the convex hull
if (d < closest)
if (d > 0.1f) // some large epsilon .. we would rather classify in a nearby cell than not in any cell
{
// outside the convex hull, don't use
return FLT_MAX;
}
if (d > closest)
closest = d;
}

View File

@ -34,7 +34,7 @@ public:
// get distance behind all planes and return the smallest..
// if inside this will be negative, if outside, positive
float GetClosestDistance(const Vector3 &pt) const;
float GetSmallestPenetrationDistance(const Vector3 &pt) const;
// the bound is optional .. not all rooms have a bound
bool IsActive() const {return m_Planes.size() != 0;}

View File

@ -25,10 +25,10 @@
#ifdef DEBUG_ENABLED
#pragma message ("LPortal DEBUG_ENABLED")
#define LPRINT_RUN(a, b) {String sz;\
#define LPRINT_RUN(a, b) {if (!Lawn::LDebug::m_bRunning) {String sz;\
for (int n=0; n<Lawn::LDebug::m_iTabDepth; n++)\
sz += "\t";\
LPRINT(a, sz + b);}
LPRINT(a, sz + b);}}
//#define LPRINT_RUN(a, b) ;
@ -36,13 +36,20 @@ LPRINT(a, sz + b);}
#define LPRINT_RUN(a, b) ;
#endif
#define LPRINT(a, b) if (!Lawn::LDebug::m_bRunning) {\
#ifdef LDEBUG_VERBOSE
#define LPRINT(a, b) {LPRINT_IMPL(a, b);}
#else
#define LPRINT(a, b) {if (!Lawn::LDebug::m_bRunning) {LPRINT_IMPL(a, b);}}
#endif
#define LPRINT_IMPL(a, b) {\
if (a >= Lawn::LDebug::m_iLoggingLevel)\
{\
Lawn::LDebug::print(b);\
}\
}
#define LWARN(a, b) if (a >= Lawn::LDebug::m_iWarningLevel)\
{\
Lawn::LDebug::print(String("\tWARNING : ") + b);\

View File

@ -51,16 +51,23 @@ void LHidable::Show(bool bShow)
if (m_bDetach)
{
//String sz = "";
if (bShow)
{
//sz = "show ";
// add to tree
m_pParent->add_child(m_pNode);
}
else
{
//sz = "hide ";
// remove from tree
m_pParent->remove_child(m_pNode);
}
//sz += m_pParent->get_name();
//sz += "->";
//sz += m_pNode->get_name();
//print_line(sz);
}
else
{

View File

@ -1,10 +1,14 @@
// defines
// extra verbose print_lines
//#define LDEBUG_VERBOSE
// frame debug strings
#define LDEBUG_CAMERA
#define LDEBUG_LIGHTS
#define LDEBUG_LIGHT_AFFECTED_ROOMS
//#define LDEBUG_UNMERGE
// single compilation unit

View File

@ -423,6 +423,14 @@ void LRoomConverter::GetWorldVertsFromMesh(const MeshInstance &mi, Vector<Vector
// some godot jiggery pokery to get the mesh verts in local space
Ref<Mesh> rmesh = mi.get_mesh();
Array arrays = rmesh->surface_get_arrays(0);
// possible to have a meshinstance with no geometry .. don't want to crash
if (!arrays.size())
{
WARN_PRINT_ONCE("Warning : LRoomConverter::GetWorldVertsFromMesh MeshInstance with no mesh, ignoring");
return;
}
PoolVector<Vector3> p_vertices = arrays[VS::ARRAY_VERTEX];
// convert to world space

View File

@ -116,7 +116,7 @@ int LRoomManager::FindClosestRoom(const Vector3 &pt) const
if (lroom.m_AABB.has_point(pt))
{
// is it within the convex hull?
float dist = lroom.m_Bound.GetClosestDistance(pt);
float dist = lroom.m_Bound.GetSmallestPenetrationDistance(pt);
// find the lowest within distance of the nearby room convex hulls
if (dist < within_dist)
@ -417,7 +417,7 @@ bool LRoomManager::dob_register(Node * pDOB, float radius)
return false;
}
LPRINT(3, "dob_register " + pDOB->get_name());
LPRINT(3, "dob_register " + pDOB->get_name() + " instance ID " + itos(pDOB->get_instance_id()));
Spatial * pSpat = Object::cast_to<Spatial>(pDOB);
if (!pSpat)
@ -454,6 +454,8 @@ int LRoomManager::dob_update(Node * pDOB)
int iRoomNum = pNewRoom->m_RoomID;
// get dob data to move to new room
//unsigned int uidob_instance_id = pDOB->get_instance_id();
unsigned int dob_id = pRoom->DOB_Find(pDOB);
// if (dob_id == -1)
// {
@ -517,6 +519,8 @@ bool LRoomManager::dob_teleport_hint(Node * pDOB, Node * pRoom)
bool LRoomManager::DobTeleport(Spatial * pDOB, int iNewRoomID)
{
print_line("teleporting " + pDOB->get_name() + " to room " + itos(iNewRoomID));
// old room
LRoom * pOldRoom = GetRoomFromDOB(pDOB);
if (!pOldRoom)
@ -535,6 +539,12 @@ bool LRoomManager::DobTeleport(Spatial * pDOB, int iNewRoomID)
if (!pNewRoom)
return false;
// special case, if teleporting within the same room, no op
// (if we do try and move from same room to same room we get data corruption because of
// const ref)
if (pOldRoom == pNewRoom)
return true;
// detach from old room, add to new room
// get dob data to move to new room
unsigned int dob_id = pOldRoom->DOB_Find(pDOB);
@ -1202,7 +1212,16 @@ bool LRoomManager::rooms_set_camera(Node * pCam)
return false;
}
m_ID_camera = pCam->get_instance_id();
int id = pCam->get_instance_id();
// was this a change in camera?
if (id != m_ID_camera)
{
m_ID_camera = id;
// make sure the camera room is correct by doing a teleport
dob_teleport(pCam);
}
// new .. select the cull layer
// 1 is for showing objects outside the room system
@ -1567,7 +1586,7 @@ bool LRoomManager::FrameUpdate()
// we keep a frame counter to prevent visiting things multiple times on the same frame in recursive functions
m_uiFrameCounter++;
LPRINT(5, "\nFRAME " + itos(m_uiFrameCounter));
LPRINT_RUN(5, "\nFRAME " + itos(m_uiFrameCounter));
FrameUpdate_Prepare();
@ -1578,6 +1597,11 @@ bool LRoomManager::FrameUpdate()
{
Object *pObj = ObjectDB::get_instance(m_ID_camera);
pCamera = Object::cast_to<Camera>(pObj);
// always doing dob update here for camera, this ensures it is not one frame behind
// depending on scene tree, which can cause camera lroom id to be the old one after crossing
// a portal plane, causing a flicker on changing room...
dob_update(pCamera);
}
else
// camera not set .. do nothing

View File

@ -443,7 +443,7 @@ void LTrace::Trace_Recursive(int depth, LRoom &room, const LVector<Plane> &plane
// plane the camera is on! If it is behind, the portal can be seen through, if in front, it can't! :)
float dist_cam = port.m_Plane.distance_to(m_pCamera->m_ptPos);
LPRINT_RUN(2, "\tPORTAL " + itos (port_num) + " (" + itos(port_id) + ") " + port.get_name());
if (dist_cam > 0.0f)
if (dist_cam >= 0.0f) // was >
{
LPRINT_RUN(2, "\t\tCULLED (back facing)");
continue;