diff --git a/irr/include/CMeshBuffer.h b/irr/include/CMeshBuffer.h index d0c41ccfab..b5ed6d2ef3 100644 --- a/irr/include/CMeshBuffer.h +++ b/irr/include/CMeshBuffer.h @@ -134,7 +134,7 @@ public: //! Index buffer SIndexBuffer *Indices; //! Bounding box of this meshbuffer. - core::aabbox3d BoundingBox; + core::aabbox3d BoundingBox{{0, 0, 0}}; //! Primitive type used for rendering (triangles, lines, ...) E_PRIMITIVE_TYPE PrimitiveType; }; diff --git a/irr/include/IMeshManipulator.h b/irr/include/IMeshManipulator.h index 54770c6f71..c9d989cae8 100644 --- a/irr/include/IMeshManipulator.h +++ b/irr/include/IMeshManipulator.h @@ -108,7 +108,7 @@ public: if (!mesh) return true; bool result = true; - core::aabbox3df bufferbox; + core::aabbox3df bufferbox{{0, 0, 0}}; for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) { result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate); if (boundingBoxUpdate) { @@ -136,7 +136,7 @@ protected: if (!buffer) return true; - core::aabbox3df bufferbox; + core::aabbox3df bufferbox{{0, 0, 0}}; for (u32 i = 0; i < buffer->getVertexCount(); ++i) { switch (buffer->getVertexType()) { case video::EVT_STANDARD: { diff --git a/irr/include/SAnimatedMesh.h b/irr/include/SAnimatedMesh.h index 8f71562365..dcc65410f7 100644 --- a/irr/include/SAnimatedMesh.h +++ b/irr/include/SAnimatedMesh.h @@ -154,7 +154,7 @@ struct SAnimatedMesh final : public IAnimatedMesh std::vector Meshes; //! The bounding box of this mesh - core::aabbox3d Box; + core::aabbox3d Box{{0.0f, 0.0f, 0.0f}}; //! Default animation speed of this mesh. f32 FramesPerSecond; diff --git a/irr/include/SMesh.h b/irr/include/SMesh.h index c9a76b0519..5e76fafc51 100644 --- a/irr/include/SMesh.h +++ b/irr/include/SMesh.h @@ -133,7 +133,7 @@ struct SMesh final : public IMesh std::vector TextureSlots; //! The bounding box of this mesh - core::aabbox3d BoundingBox; + core::aabbox3d BoundingBox{{0, 0, 0}}; }; } // end namespace scene diff --git a/irr/include/SSkinMeshBuffer.h b/irr/include/SSkinMeshBuffer.h index 82c0d9f37e..eb3f7371ff 100644 --- a/irr/include/SSkinMeshBuffer.h +++ b/irr/include/SSkinMeshBuffer.h @@ -228,7 +228,7 @@ public: video::SMaterial Material; video::E_VERTEX_TYPE VertexType; - core::aabbox3d BoundingBox; + core::aabbox3d BoundingBox{{0, 0, 0}}; //! Primitive type used for rendering (triangles, lines, ...) E_PRIMITIVE_TYPE PrimitiveType; diff --git a/irr/include/SViewFrustum.h b/irr/include/SViewFrustum.h index cd898e032a..c03707d4ff 100644 --- a/irr/include/SViewFrustum.h +++ b/irr/include/SViewFrustum.h @@ -117,7 +117,7 @@ struct SViewFrustum core::plane3d planes[VF_PLANE_COUNT]; //! bounding box around the view frustum - core::aabbox3d boundingBox; + core::aabbox3d boundingBox{{0, 0, 0}}; private: //! Hold a copy of important transform matrices diff --git a/irr/include/SkinnedMesh.h b/irr/include/SkinnedMesh.h index 4cf5905c99..c9ea993657 100644 --- a/irr/include/SkinnedMesh.h +++ b/irr/include/SkinnedMesh.h @@ -137,7 +137,7 @@ public: //! Moves the mesh into static position. void resetAnimation(); - virtual void updateBoundingBox(); + void updateBoundingBox(); //! Recovers the joints from the mesh void recoverJointsFromMesh(std::vector &jointChildSceneNodes); @@ -370,7 +370,7 @@ protected: // doesn't allow taking a reference to individual elements. std::vector> Vertices_Moved; - core::aabbox3d BoundingBox; + core::aabbox3d BoundingBox{{0, 0, 0}}; f32 EndFrame; f32 FramesPerSecond; diff --git a/irr/include/aabbox3d.h b/irr/include/aabbox3d.h index 81c2293ade..cc5aebcc50 100644 --- a/irr/include/aabbox3d.h +++ b/irr/include/aabbox3d.h @@ -20,9 +20,7 @@ template class aabbox3d { public: - //! Default Constructor. - constexpr aabbox3d() : - MinEdge(-1, -1, -1), MaxEdge(1, 1, 1) {} + constexpr aabbox3d() = delete; //! Constructor with min edge and max edge. constexpr aabbox3d(const vector3d &min, const vector3d &max) : MinEdge(min), MaxEdge(max) {} diff --git a/irr/src/CAnimatedMeshSceneNode.h b/irr/src/CAnimatedMeshSceneNode.h index 047a4030fc..5149f7618f 100644 --- a/irr/src/CAnimatedMeshSceneNode.h +++ b/irr/src/CAnimatedMeshSceneNode.h @@ -145,7 +145,7 @@ private: void beginTransition(); core::array Materials; - core::aabbox3d Box; + core::aabbox3d Box{{0.0f, 0.0f, 0.0f}}; IAnimatedMesh *Mesh; f32 StartFrame; diff --git a/irr/src/CBillboardSceneNode.h b/irr/src/CBillboardSceneNode.h index f0d7f9dcfb..2b11cc8f4d 100644 --- a/irr/src/CBillboardSceneNode.h +++ b/irr/src/CBillboardSceneNode.h @@ -104,7 +104,7 @@ private: /** Note that we can't use the real boundingbox for culling because at that point the camera which is used to calculate the billboard is not yet updated. So we only know the real boundingbox after rendering - which is too late for culling. */ - core::aabbox3d BBoxSafe; + core::aabbox3d BBoxSafe{{0.0f, 0.0f, 0.0f}}; scene::SMeshBuffer *Buffer; }; diff --git a/irr/src/CBoneSceneNode.h b/irr/src/CBoneSceneNode.h index 8e1a0f7a1d..d900570db0 100644 --- a/irr/src/CBoneSceneNode.h +++ b/irr/src/CBoneSceneNode.h @@ -60,7 +60,7 @@ private: u32 BoneIndex; - core::aabbox3d Box; + core::aabbox3d Box{-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f}; E_BONE_ANIMATION_MODE AnimationMode; E_BONE_SKINNING_SPACE SkinningSpace; diff --git a/irr/src/CDummyTransformationSceneNode.h b/irr/src/CDummyTransformationSceneNode.h index 86fda36396..a03ed07fa9 100644 --- a/irr/src/CDummyTransformationSceneNode.h +++ b/irr/src/CDummyTransformationSceneNode.h @@ -48,7 +48,7 @@ private: void setPosition(const core::vector3df &newpos) override; core::matrix4 RelativeTransformationMatrix; - core::aabbox3d Box; + core::aabbox3d Box{{0, 0, 0}}; }; } // end namespace scene diff --git a/irr/src/CEmptySceneNode.h b/irr/src/CEmptySceneNode.h index c89ad59ae4..bf5c48e9bd 100644 --- a/irr/src/CEmptySceneNode.h +++ b/irr/src/CEmptySceneNode.h @@ -33,7 +33,7 @@ public: ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override; private: - core::aabbox3d Box; + core::aabbox3d Box{{0, 0, 0}}; }; } // end namespace scene diff --git a/irr/src/CMeshSceneNode.h b/irr/src/CMeshSceneNode.h index a009287482..6791a34844 100644 --- a/irr/src/CMeshSceneNode.h +++ b/irr/src/CMeshSceneNode.h @@ -72,7 +72,7 @@ protected: void copyMaterials(); core::array Materials; - core::aabbox3d Box; + core::aabbox3d Box{{0, 0, 0}}; video::SMaterial ReadOnlyMaterial; IMesh *Mesh; diff --git a/irr/src/CSceneManager.cpp b/irr/src/CSceneManager.cpp index 94b6c24a7b..d8a147b345 100644 --- a/irr/src/CSceneManager.cpp +++ b/irr/src/CSceneManager.cpp @@ -307,7 +307,7 @@ const core::aabbox3d &CSceneManager::getBoundingBox() const { _IRR_DEBUG_BREAK_IF(true) // Bounding Box of Scene Manager should never be used. - static const core::aabbox3d dummy; + static const core::aabbox3d dummy{{0.0f, 0.0f, 0.0f}}; return dummy; } diff --git a/irr/src/SkinnedMesh.cpp b/irr/src/SkinnedMesh.cpp index 64b25205e3..ebf84cec5a 100644 --- a/irr/src/SkinnedMesh.cpp +++ b/irr/src/SkinnedMesh.cpp @@ -573,7 +573,7 @@ SkinnedMesh *SkinnedMeshBuilder::finalize() return this; } -void SkinnedMesh::updateBoundingBox(void) +void SkinnedMesh::updateBoundingBox() { if (!SkinningBuffers) return; diff --git a/src/client/activeobjectmgr.cpp b/src/client/activeobjectmgr.cpp index 1867fc78b3..eab53dd7fb 100644 --- a/src/client/activeobjectmgr.cpp +++ b/src/client/activeobjectmgr.cpp @@ -101,7 +101,7 @@ std::vector ActiveObjectMgr::getActiveSelectableObje if (!obj) continue; - aabb3f selection_box; + aabb3f selection_box{{0.0f, 0.0f, 0.0f}}; if (!obj->getSelectionBox(&selection_box)) continue; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index bda9fc8703..42a31ae8cd 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -430,7 +430,7 @@ void ClientEnvironment::getSelectedActiveObjects( for (const auto &allObject : allObjects) { ClientActiveObject *obj = allObject.obj; - aabb3f selection_box; + aabb3f selection_box{{0.0f, 0.0f, 0.0f}}; if (!obj->getSelectionBox(&selection_box)) continue; diff --git a/src/client/clouds.h b/src/client/clouds.h index 950327aa25..d081a48539 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -160,7 +160,7 @@ private: // Was the mesh ever generated? bool m_mesh_valid = false; - aabb3f m_box; + aabb3f m_box{{0.0f, 0.0f, 0.0f}}; v2f m_origin; u16 m_cloud_radius_i; u32 m_seed; diff --git a/src/client/game.cpp b/src/client/game.cpp index 97b50183ce..3098ca57ca 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3200,7 +3200,7 @@ PointedThing Game::updatePointedThing( hud->pointing_at_object = true; runData.selected_object = client->getEnv().getActiveObject(result.object_id); - aabb3f selection_box; + aabb3f selection_box{{0.0f, 0.0f, 0.0f}}; if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox() && runData.selected_object->getSelectionBox(&selection_box)) { v3f pos = runData.selected_object->getPosition(); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 53a9db810b..1fea74238f 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -75,10 +75,8 @@ static aabb3f getNodeBoundingBox(const std::vector &nodeboxes) if (nodeboxes.empty()) return aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); - aabb3f b_max; - - std::vector::const_iterator it = nodeboxes.begin(); - b_max = aabb3f(it->MinEdge, it->MaxEdge); + auto it = nodeboxes.begin(); + aabb3f b_max(it->MinEdge, it->MaxEdge); ++it; for (; it != nodeboxes.end(); ++it) diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index eb56d3580e..cd2e9a91d5 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -105,8 +105,7 @@ void scaleMesh(scene::IMesh *mesh, v3f scale) if (mesh == NULL) return; - aabb3f bbox; - bbox.reset(0, 0, 0); + aabb3f bbox{{0.0f, 0.0f, 0.0f}}; u32 mc = mesh->getMeshBufferCount(); for (u32 j = 0; j < mc; j++) { @@ -134,8 +133,7 @@ void translateMesh(scene::IMesh *mesh, v3f vec) if (mesh == NULL) return; - aabb3f bbox; - bbox.reset(0, 0, 0); + aabb3f bbox{{0.0f, 0.0f, 0.0f}}; u32 mc = mesh->getMeshBufferCount(); for (u32 j = 0; j < mc; j++) { @@ -296,8 +294,7 @@ void rotateMeshBy6dFacedir(scene::IMesh *mesh, u8 facedir) void recalculateBoundingBox(scene::IMesh *src_mesh) { - aabb3f bbox; - bbox.reset(0,0,0); + aabb3f bbox{{0.0f, 0.0f, 0.0f}}; for (u16 j = 0; j < src_mesh->getMeshBufferCount(); j++) { scene::IMeshBuffer *buf = src_mesh->getMeshBuffer(j); buf->recalculateBoundingBox(); diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 472ac0321e..cd9b9b7366 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -619,15 +619,22 @@ const core::aabbox3df &ParticleBuffer::getBoundingBox() const if (!m_bounding_box_dirty) return m_mesh_buffer->BoundingBox; - core::aabbox3df box; + core::aabbox3df box{{0, 0, 0}}; + bool first = true; for (u16 i = 0; i < m_count; i++) { // check if this index is used static_assert(quad_indices[1] != 0); if (m_mesh_buffer->getIndices()[6 * i + 1] == 0) continue; - for (u16 j = 0; j < 4; j++) - box.addInternalPoint(m_mesh_buffer->getPosition(i * 4 + j)); + for (u16 j = 0; j < 4; j++) { + const auto pos = m_mesh_buffer->getPosition(i * 4 + j); + if (first) + box.reset(pos); + else + box.addInternalPoint(pos); + first = false; + } } m_mesh_buffer->BoundingBox = box; diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 2722d3284f..2c9e4234d9 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -50,8 +50,6 @@ Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShade m_seed = (u64)myrand() << 32 | myrand(); setAutomaticCulling(scene::EAC_OFF); - m_box.MaxEdge.set(0, 0, 0); - m_box.MinEdge.set(0, 0, 0); m_sky_params = SkyboxDefaults::getSkyDefaults(); m_sun_params = SkyboxDefaults::getSunDefaults(); diff --git a/src/client/sky.h b/src/client/sky.h index 0ba3ee62cf..7d3cdba3da 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -122,7 +122,7 @@ public: } private: - aabb3f m_box; + aabb3f m_box{{0.0f, 0.0f, 0.0f}}; video::SMaterial m_materials[SKY_MATERIAL_COUNT]; // How much sun & moon transition should affect horizon color float m_horizon_blend() diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index bb3d91f7ea..4239c4121a 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -195,8 +195,7 @@ WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id): else g_extrusion_mesh_cache->grab(); - // Disable bounding box culling for this scene node - // since we won't calculate the bounding box. + // This class doesn't render anything, so disable culling. setAutomaticCulling(scene::EAC_OFF); // Create the child scene node diff --git a/src/client/wieldmesh.h b/src/client/wieldmesh.h index 5a5a6957a8..6e92af9f69 100644 --- a/src/client/wieldmesh.h +++ b/src/client/wieldmesh.h @@ -134,7 +134,7 @@ private: // Bounding box culling is disabled for this type of scene node, // so this variable is just required so we can implement // getBoundingBox() and is set to an empty box. - aabb3f m_bounding_box; + aabb3f m_bounding_box{{0, 0, 0}}; ShadowRenderer *m_shadow; }; diff --git a/src/collision.cpp b/src/collision.cpp index 4ee9d5ed89..7dae43a0c1 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -262,7 +262,7 @@ static void add_object_boxes(Environment *env, { auto process_object = [&cinfo] (ActiveObject *object) { if (object && object->collideWithObjects()) { - aabb3f box; + aabb3f box{{0.0f, 0.0f, 0.0f}}; if (object->getCollisionBox(&box)) cinfo.emplace_back(object, 0, box); } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2f0307d11c..899818b218 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -121,7 +121,7 @@ void NodeBox::deSerialize(std::istream &is) case NODEBOX_LEVELED: { u16 fixed_count = readU16(is); while(fixed_count--) { - aabb3f box; + aabb3f box{{0.0f, 0.0f, 0.0f}}; box.MinEdge = readV3F32(is); box.MaxEdge = readV3F32(is); fixed.push_back(box); diff --git a/src/nodedef.h b/src/nodedef.h index ab33628726..d819be8158 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -115,9 +115,9 @@ struct NodeBox // NODEBOX_FIXED std::vector fixed; // NODEBOX_WALLMOUNTED - aabb3f wall_top; - aabb3f wall_bottom; - aabb3f wall_side; // being at the -X side + aabb3f wall_top = dummybox; + aabb3f wall_bottom = dummybox; + aabb3f wall_side = dummybox; // being at the -X side // NODEBOX_CONNECTED // (kept externally to not bloat the structure) std::shared_ptr connected; @@ -139,6 +139,10 @@ struct NodeBox void reset(); void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); + +private: + /// @note the actual defaults are in reset(), see nodedef.cpp + static constexpr aabb3f dummybox = aabb3f({0, 0, 0}); }; struct MapNode; @@ -810,14 +814,14 @@ private: * The union of all nodes' selection boxes. * Might be larger if big nodes are removed from the manager. */ - aabb3f m_selection_box_union; + aabb3f m_selection_box_union{{0.0f, 0.0f, 0.0f}}; /*! * The smallest box in integer node coordinates that * contains all nodes' selection boxes. * Might be larger if big nodes are removed from the manager. */ - core::aabbox3d m_selection_box_int_union; + core::aabbox3d m_selection_box_int_union{{0, 0, 0}}; /*! * NodeResolver instances to notify once node registration has finished. diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index afd9986104..656abf9014 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -302,7 +302,7 @@ private: v3s16 m_start; /**< source position */ v3s16 m_destination; /**< destination position */ - core::aabbox3d m_limits; /**< position limits in real map coordinates */ + core::aabbox3d m_limits{{0, 0, 0}}; /**< position limits in real map coordinates */ /** contains all map data already collected and analyzed. Access it via the getIndexElement/getIdxElem methods. */ diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index a6fa2f068c..4e9175f533 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -326,7 +326,8 @@ bool is_color_table(lua_State *L, int index) aabb3f read_aabb3f(lua_State *L, int index, f32 scale) { - aabb3f box; + // default value for accidental/historical reasons + aabb3f box{-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f}; if(lua_istable(L, index)){ lua_rawgeti(L, index, 1); box.MinEdge.X = lua_tonumber(L, -1) * scale; diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 34c276353a..df47e3b280 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -85,7 +85,19 @@ bool read_color (lua_State *L, int index, video::SColor *color); bool is_color_table (lua_State *L, int index); +/** + * Read a floating-point axis-aligned box from Lua. + * + * @param L the Lua state + * @param index the index of the Lua variable to read the box from. The + * variable must contain a table of the form + * {minx, miny, minz, maxx, maxy, maxz}. + * @param scale factor to scale the bounding box by + * + * @return the box corresponding to lua table + */ aabb3f read_aabb3f (lua_State *L, int index, f32 scale); + v3s16 read_v3s16 (lua_State *L, int index); std::vector read_aabb3f_vector (lua_State *L, int index, f32 scale); size_t read_stringlist (lua_State *L, int index, diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 3c985e1b96..04104d517e 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1847,7 +1847,7 @@ void ServerEnvironment::getSelectedActiveObjects( auto process = [&] (ServerActiveObject *obj) -> bool { if (obj->isGone()) return false; - aabb3f selection_box; + aabb3f selection_box{{0.0f, 0.0f, 0.0f}}; if (!obj->getSelectionBox(&selection_box)) return false;