mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: sent intersected primitive volume index to click handler
Click handler should be notified about the primitive volume that the ray collided with, which will make selecting objects in the world a lot more reliable and easier.
This commit is contained in:
parent
9e46c8be75
commit
2a2b05c42a
@ -998,7 +998,7 @@ void CrowdTool::handleMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrowdTool::handleClick(const float* s, const float* p, bool shift)
|
void CrowdTool::handleClick(const float* s, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
if (!m_editor) return;
|
if (!m_editor) return;
|
||||||
if (!m_state) return;
|
if (!m_state) return;
|
||||||
|
@ -430,10 +430,10 @@ void Editor::handleCommonSettings()
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::handleClick(const float* s, const float* p, bool shift)
|
void Editor::handleClick(const float* s, const float* p, const int v, bool shift)
|
||||||
{
|
{
|
||||||
if (m_tool)
|
if (m_tool)
|
||||||
m_tool->handleClick(s, p, shift);
|
m_tool->handleClick(s, p, v, shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::handleToggle()
|
void Editor::handleToggle()
|
||||||
|
@ -339,10 +339,10 @@ const float* Editor_Debug::getBoundsMax()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor_Debug::handleClick(const float* s, const float* p, bool shift)
|
void Editor_Debug::handleClick(const float* s, const float* p, const int v, bool shift)
|
||||||
{
|
{
|
||||||
if (m_tool)
|
if (m_tool)
|
||||||
m_tool->handleClick(s, p, shift);
|
m_tool->handleClick(s, p, v, shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor_Debug::handleToggle()
|
void Editor_Debug::handleToggle()
|
||||||
|
@ -641,7 +641,7 @@ public:
|
|||||||
m_drawType = DRAWDETAIL_MESH;
|
m_drawType = DRAWDETAIL_MESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleClick(const float* /*s*/, const float* p, bool /*shift*/)
|
virtual void handleClick(const float* /*s*/, const float* p, const int /*v*/, bool /*shift*/)
|
||||||
{
|
{
|
||||||
m_hitPosSet = true;
|
m_hitPosSet = true;
|
||||||
rdVcopy(m_hitPos,p);
|
rdVcopy(m_hitPos,p);
|
||||||
@ -727,7 +727,7 @@ public:
|
|||||||
ImGui::Text("Shift+LMB to remove an obstacle.");
|
ImGui::Text("Shift+LMB to remove an obstacle.");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift)
|
virtual void handleClick(const float* s, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
if (m_editor)
|
if (m_editor)
|
||||||
{
|
{
|
||||||
|
@ -236,7 +236,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleClick(const float* /*s*/, const float* p, bool shift)
|
virtual void handleClick(const float* /*s*/, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
m_hitPosSet = true;
|
m_hitPosSet = true;
|
||||||
rdVcopy(m_hitPos,p);
|
rdVcopy(m_hitPos,p);
|
||||||
|
@ -514,8 +514,11 @@ bool InputGeom::saveGeomSet(const BuildSettings* settings)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputGeom::raycastMesh(const float* src, const float* dst, const unsigned int mask, float* tmin) const
|
bool InputGeom::raycastMesh(const float* src, const float* dst, const unsigned int mask, int* vidx, float* tmin) const
|
||||||
{
|
{
|
||||||
|
if (vidx)
|
||||||
|
*vidx = -1;
|
||||||
|
|
||||||
// Prune hit ray.
|
// Prune hit ray.
|
||||||
float btmin = 0, btmax = 1;
|
float btmin = 0, btmax = 1;
|
||||||
if (!rdIntersectSegmentAABB(src, dst, m_meshBMin, m_meshBMax, btmin, btmax))
|
if (!rdIntersectSegmentAABB(src, dst, m_meshBMin, m_meshBMax, btmin, btmax))
|
||||||
@ -528,6 +531,7 @@ bool InputGeom::raycastMesh(const float* src, const float* dst, const unsigned i
|
|||||||
const bool traceTrigger = mask & TRACE_TRIGGER;
|
const bool traceTrigger = mask & TRACE_TRIGGER;
|
||||||
|
|
||||||
float isectTmin = 1.0f;
|
float isectTmin = 1.0f;
|
||||||
|
int isectVolIdx = -1;
|
||||||
|
|
||||||
for (int i = 0; i < nvol; i++)
|
for (int i = 0; i < nvol; i++)
|
||||||
{
|
{
|
||||||
@ -561,17 +565,25 @@ bool InputGeom::raycastMesh(const float* src, const float* dst, const unsigned i
|
|||||||
{
|
{
|
||||||
hit = true;
|
hit = true;
|
||||||
|
|
||||||
// Caller isn't interested in finding the closest intersection; return out.
|
// Caller isn't interested in finding the closest intersection; break out.
|
||||||
if (!tmin)
|
if (!tmin)
|
||||||
return true;
|
{
|
||||||
|
isectVolIdx = i;
|
||||||
if (tsmin < isectTmin)
|
break;
|
||||||
|
}
|
||||||
|
else if (tsmin < isectTmin)
|
||||||
|
{
|
||||||
isectTmin = tsmin;
|
isectTmin = tsmin;
|
||||||
|
isectVolIdx = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hit)
|
if (hit)
|
||||||
{
|
{
|
||||||
|
if (vidx)
|
||||||
|
*vidx = isectVolIdx;
|
||||||
|
|
||||||
if (tmin)
|
if (tmin)
|
||||||
*tmin = isectTmin;
|
*tmin = isectTmin;
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ void NavMeshPruneTool::handleMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift)
|
void NavMeshPruneTool::handleClick(const float* s, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
rdIgnoreUnused(s);
|
rdIgnoreUnused(s);
|
||||||
rdIgnoreUnused(shift);
|
rdIgnoreUnused(shift);
|
||||||
|
@ -459,7 +459,7 @@ void NavMeshTesterTool::handleMenu()
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshTesterTool::handleClick(const float* /*s*/, const float* p, bool shift)
|
void NavMeshTesterTool::handleClick(const float* /*s*/, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
if (!shift)
|
if (!shift)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ void OffMeshConnectionTool::handleMenu()
|
|||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffMeshConnectionTool::handleClick(const float* /*s*/, const float* p, bool shift)
|
void OffMeshConnectionTool::handleClick(const float* /*s*/, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
if (!m_editor) return;
|
if (!m_editor) return;
|
||||||
InputGeom* geom = m_editor->getInputGeom();
|
InputGeom* geom = m_editor->getInputGeom();
|
||||||
|
@ -351,7 +351,7 @@ void ShapeVolumeTool::handleMenu()
|
|||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeVolumeTool::handleClick(const float* /*s*/, const float* p, bool shift)
|
void ShapeVolumeTool::handleClick(const float* /*s*/, const float* p, const int /*v*/, bool shift)
|
||||||
{
|
{
|
||||||
if (!m_editor) return;
|
if (!m_editor) return;
|
||||||
InputGeom* geom = m_editor->getInputGeom();
|
InputGeom* geom = m_editor->getInputGeom();
|
||||||
|
@ -138,7 +138,7 @@ public:
|
|||||||
virtual void init(Editor* editor);
|
virtual void init(Editor* editor);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void handleMenu();
|
virtual void handleMenu();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleUpdate(const float dt);
|
virtual void handleUpdate(const float dt);
|
||||||
|
@ -210,7 +210,7 @@ struct EditorTool
|
|||||||
virtual void init(class Editor* editor) = 0;
|
virtual void init(class Editor* editor) = 0;
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
virtual void handleMenu() = 0;
|
virtual void handleMenu() = 0;
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift) = 0;
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift) = 0;
|
||||||
virtual void handleRender() = 0;
|
virtual void handleRender() = 0;
|
||||||
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0;
|
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0;
|
||||||
virtual void handleToggle() = 0;
|
virtual void handleToggle() = 0;
|
||||||
@ -306,7 +306,7 @@ public:
|
|||||||
virtual void handleSettings();
|
virtual void handleSettings();
|
||||||
virtual void handleTools();
|
virtual void handleTools();
|
||||||
virtual void handleDebugMode();
|
virtual void handleDebugMode();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleRender();
|
virtual void handleRender();
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
virtual void handleSettings();
|
virtual void handleSettings();
|
||||||
virtual void handleTools();
|
virtual void handleTools();
|
||||||
virtual void handleDebugMode();
|
virtual void handleDebugMode();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleRender();
|
virtual void handleRender();
|
||||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||||
|
@ -165,7 +165,7 @@ public:
|
|||||||
|
|
||||||
const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
|
const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
|
||||||
const BuildSettings* getBuildSettings() const { return m_hasBuildSettings ? &m_buildSettings : 0; }
|
const BuildSettings* getBuildSettings() const { return m_hasBuildSettings ? &m_buildSettings : 0; }
|
||||||
bool raycastMesh(const float* src, const float* dst, const unsigned int mask, float* tmin = nullptr) const;
|
bool raycastMesh(const float* src, const float* dst, const unsigned int mask, int* vol = nullptr, float* tmin = nullptr) const;
|
||||||
|
|
||||||
/// @name Off-Mesh connections.
|
/// @name Off-Mesh connections.
|
||||||
///@{
|
///@{
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
virtual void init(Editor* editor);
|
virtual void init(Editor* editor);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void handleMenu();
|
virtual void handleMenu();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleUpdate(const float dt);
|
virtual void handleUpdate(const float dt);
|
||||||
|
@ -104,7 +104,7 @@ public:
|
|||||||
virtual void init(Editor* editor);
|
virtual void init(Editor* editor);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void handleMenu();
|
virtual void handleMenu();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleUpdate(const float dt);
|
virtual void handleUpdate(const float dt);
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
virtual void init(Editor* editor);
|
virtual void init(Editor* editor);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void handleMenu();
|
virtual void handleMenu();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleUpdate(const float dt);
|
virtual void handleUpdate(const float dt);
|
||||||
|
@ -62,7 +62,7 @@ public:
|
|||||||
virtual void init(Editor* editor);
|
virtual void init(Editor* editor);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void handleMenu();
|
virtual void handleMenu();
|
||||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
virtual void handleClick(const float* s, const float* p, const int v, bool shift);
|
||||||
virtual void handleToggle();
|
virtual void handleToggle();
|
||||||
virtual void handleStep();
|
virtual void handleStep();
|
||||||
virtual void handleUpdate(const float dt);
|
virtual void handleUpdate(const float dt);
|
||||||
|
@ -771,7 +771,9 @@ int not_main(int argc, char** argv)
|
|||||||
if (processHitTest && geom && editor)
|
if (processHitTest && geom && editor)
|
||||||
{
|
{
|
||||||
float hitTime;
|
float hitTime;
|
||||||
bool hit = geom->raycastMesh(rayStart, rayEnd, TRACE_ALL, &hitTime);
|
int volumeIndex;
|
||||||
|
|
||||||
|
bool hit = geom->raycastMesh(rayStart, rayEnd, TRACE_ALL, &volumeIndex, &hitTime);
|
||||||
|
|
||||||
if (hit)
|
if (hit)
|
||||||
{
|
{
|
||||||
@ -789,7 +791,7 @@ int not_main(int argc, char** argv)
|
|||||||
pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
||||||
pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
||||||
pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
||||||
editor->handleClick(rayStart, pos, processHitTestShift);
|
editor->handleClick(rayStart, pos, volumeIndex, processHitTestShift);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user