fix drag selection selecting objects behind camera and add objects bounding radius
This commit is contained in:
@@ -209,6 +209,11 @@ void ModelInstance::recalcExtents()
|
||||
|
||||
size_cat = glm::distance(bounding_of_rotated_points.max, bounding_of_rotated_points.min);
|
||||
|
||||
// Calculate bounding radius
|
||||
// glm::vec3 center = (extents[0] + extents[1]) / 2.0f;
|
||||
glm::vec3 halfExtents = (extents[1] - extents[0]) / 2.0f;
|
||||
bounding_radius = glm::length(halfExtents);
|
||||
|
||||
_need_recalc_extents = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
[[nodiscard]]
|
||||
virtual std::array<glm::vec3, 2> const& getExtents() { ensureExtents(); return extents; }
|
||||
|
||||
[[nodiscard]]
|
||||
float const& getBoundingRadius() { ensureExtents(); return bounding_radius; }
|
||||
|
||||
glm::vec3 const getServerPos() { return glm::vec3(ZEROPOINT - pos.z, ZEROPOINT - pos.x, pos.y); }
|
||||
|
||||
bool _grouped = false;
|
||||
@@ -89,6 +92,7 @@ protected:
|
||||
glm::mat4x4 _transform_mat = glm::mat4x4();
|
||||
glm::mat4x4 _transform_mat_inverted = glm::mat4x4();
|
||||
std::array<glm::vec3, 2> extents;
|
||||
float bounding_radius;
|
||||
|
||||
Noggit::NoggitRenderContext _context;
|
||||
|
||||
|
||||
@@ -282,6 +282,11 @@ void WMOInstance::recalcExtents()
|
||||
extents[0] = wmo_aabb.min;
|
||||
extents[1] = wmo_aabb.max;
|
||||
|
||||
// Calculate bounding radius
|
||||
// glm::vec3 center = (extents[0] + extents[1]) / 2.0f;
|
||||
glm::vec3 halfExtents = (extents[1] - extents[0]) / 2.0f;
|
||||
bounding_radius = glm::length(halfExtents);
|
||||
|
||||
_need_recalc_extents = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3607,9 +3607,15 @@ void World::select_objects_in_area(
|
||||
{
|
||||
for (auto& instance : pair.second)
|
||||
{
|
||||
auto model = instance->transformMatrix();
|
||||
// auto transform_mat = instance->transformMatrix();
|
||||
glm::mat4 VPmatrix = projection * view;
|
||||
glm::vec4 screenPos = VPmatrix * glm::vec4(instance->pos, 1.0f);
|
||||
|
||||
// if screenPos.w < 0.0f, object is behind camera
|
||||
// check object bounding radius instead to compare the object's size, if it clips with the camera.
|
||||
if (screenPos.w < -instance->getBoundingRadius())
|
||||
continue;
|
||||
|
||||
screenPos.x /= screenPos.w;
|
||||
screenPos.y /= screenPos.w;
|
||||
|
||||
@@ -3620,13 +3626,13 @@ void World::select_objects_in_area(
|
||||
screenPos.x *= viewport_width;
|
||||
screenPos.y *= viewport_height;
|
||||
|
||||
auto depth = glm::distance(camera_position, instance->pos);
|
||||
float depth = glm::distance(camera_position, instance->pos);
|
||||
if (depth <= user_depth)
|
||||
{
|
||||
const glm::vec2 screenPos2D = glm::vec2(screenPos);
|
||||
if (misc::pointInside(screenPos2D, selection_box))
|
||||
{
|
||||
auto uid = instance->uid;
|
||||
unsigned int uid = instance->uid;
|
||||
auto modelInstance = _model_instance_storage.get_instance(uid);
|
||||
if (modelInstance && modelInstance.value().index() == eEntry_Object) {
|
||||
auto obj = std::get<selected_object_type>(modelInstance.value());
|
||||
|
||||
Reference in New Issue
Block a user