diff --git a/client/source/gui/InventoryCube.cpp b/client/source/gui/InventoryCube.cpp index 8eeff0e3..ab65b510 100644 --- a/client/source/gui/InventoryCube.cpp +++ b/client/source/gui/InventoryCube.cpp @@ -93,9 +93,9 @@ void InventoryCube::updateVertexBuffer(const Block &block) { }; for(u8 j = 0 ; j < 4 ; j++) { - vertices[j + i * 4].coord3d[0] = vertices[j + i * 4].coord3d[0] * block.boundingBox().width + block.boundingBox().x; - vertices[j + i * 4].coord3d[1] = vertices[j + i * 4].coord3d[1] * block.boundingBox().height + block.boundingBox().y; - vertices[j + i * 4].coord3d[2] = vertices[j + i * 4].coord3d[2] * block.boundingBox().depth + block.boundingBox().z; + vertices[j + i * 4].coord3d[0] = vertices[j + i * 4].coord3d[0] * block.boundingBox().size.x + block.boundingBox().position.x; + vertices[j + i * 4].coord3d[1] = vertices[j + i * 4].coord3d[1] * block.boundingBox().size.y + block.boundingBox().position.y; + vertices[j + i * 4].coord3d[2] = vertices[j + i * 4].coord3d[2] * block.boundingBox().size.z + block.boundingBox().position.z; vertices[j + i * 4].texCoord[0] = faceTexCoords[j * 2]; vertices[j + i * 4].texCoord[1] = faceTexCoords[j * 2 + 1]; diff --git a/client/source/hud/BlockCursor.cpp b/client/source/hud/BlockCursor.cpp index e673e1c5..d82efb7c 100644 --- a/client/source/hud/BlockCursor.cpp +++ b/client/source/hud/BlockCursor.cpp @@ -189,9 +189,9 @@ void BlockCursor::update(const Hotbar &hotbar) { void BlockCursor::updateVertexBuffer(const Block &block) { gk::Vertex vertices[24]; for (u8 i = 0 ; i < 24 ; ++i) { - vertices[i].coord3d[0] = cubeCoords[i * 3] * block.boundingBox().width + block.boundingBox().x; - vertices[i].coord3d[1] = cubeCoords[i * 3 + 1] * block.boundingBox().height + block.boundingBox().y; - vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * block.boundingBox().depth + block.boundingBox().z; + vertices[i].coord3d[0] = cubeCoords[i * 3] * block.boundingBox().size.x + block.boundingBox().position.x; + vertices[i].coord3d[1] = cubeCoords[i * 3 + 1] * block.boundingBox().size.y + block.boundingBox().position.y; + vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * block.boundingBox().size.z + block.boundingBox().position.z; vertices[i].coord3d[3] = -1; } @@ -203,9 +203,9 @@ void BlockCursor::updateVertexBuffer(const Block &block) { void BlockCursor::updateAnimationVertexBuffer(const Block &block, int animationPos) { gk::Vertex vertices[24]; for (u8 i = 0 ; i < 24 ; ++i) { - vertices[i].coord3d[0] = cubeCoords[i * 3] * block.boundingBox().width + block.boundingBox().x; - vertices[i].coord3d[1] = cubeCoords[i * 3 + 1] * block.boundingBox().height + block.boundingBox().y; - vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * block.boundingBox().depth + block.boundingBox().z; + vertices[i].coord3d[0] = cubeCoords[i * 3] * block.boundingBox().size.x + block.boundingBox().position.x; + vertices[i].coord3d[1] = cubeCoords[i * 3 + 1] * block.boundingBox().size.y + block.boundingBox().position.y; + vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * block.boundingBox().size.z + block.boundingBox().position.z; vertices[i].coord3d[3] = -1; } diff --git a/client/source/math/BlockCursorRaycast.cpp b/client/source/math/BlockCursorRaycast.cpp index b2bf4140..b65423ea 100644 --- a/client/source/math/BlockCursorRaycast.cpp +++ b/client/source/math/BlockCursorRaycast.cpp @@ -125,27 +125,24 @@ void BlockCursorRaycast::rayCastToAxis(const Axis axis, const glm::dvec3 &positi if(blockID && block.drawType() != BlockDrawType::Liquid) { // Check bounding box; this should loop over all selection boxes // when they are implemented - gk::FloatBox selBox = block.boundingBox(); - selBox.x += double(nx); - selBox.y += double(ny); - selBox.z += double(nz); + gk::DoubleBox selBox = block.boundingBox() + gk::Vector3d(double(nx), double(ny), double(nz)); bool hit = false; // Check if we hit any of the sides of the inner box - isect = intersectAxisPlane(AXIS_X, (lookAt.x < 0. ? selBox.x + selBox.width : selBox.x), position, lookAt); - if (selBox.y <= isect.y && isect.y <= selBox.y + selBox.height - && selBox.z <= isect.z && isect.z <= selBox.z + selBox.depth) + isect = intersectAxisPlane(AXIS_X, (lookAt.x < 0. ? selBox.position.x + selBox.size.x : selBox.position.x), position, lookAt); + if (selBox.position.y <= isect.y && isect.y <= selBox.position.y + selBox.size.y + && selBox.position.z <= isect.z && isect.z <= selBox.position.z + selBox.size.z) recordHit(position, isect, AXIS_X, lookAt.x < 0., nx, ny, nz, bestX, bestY, bestZ, bestFace, bestDepth, hit); - isect = intersectAxisPlane(AXIS_Y, (lookAt.y < 0. ? selBox.y + selBox.height : selBox.y), position, lookAt); - if (selBox.x <= isect.x && isect.x <= selBox.x + selBox.width - && selBox.z <= isect.z && isect.z <= selBox.z + selBox.depth) + isect = intersectAxisPlane(AXIS_Y, (lookAt.y < 0. ? selBox.position.y + selBox.size.y : selBox.position.y), position, lookAt); + if (selBox.position.x <= isect.x && isect.x <= selBox.position.x + selBox.size.x + && selBox.position.z <= isect.z && isect.z <= selBox.position.z + selBox.size.z) recordHit(position, isect, AXIS_Y, lookAt.y < 0., nx, ny, nz, bestX, bestY, bestZ, bestFace, bestDepth, hit); - isect = intersectAxisPlane(AXIS_Z, (lookAt.z < 0. ? selBox.z + selBox.depth : selBox.z), position, lookAt); - if (selBox.x <= isect.x && isect.x <= selBox.x + selBox.width - && selBox.y <= isect.y && isect.y <= selBox.y + selBox.height) + isect = intersectAxisPlane(AXIS_Z, (lookAt.z < 0. ? selBox.position.z + selBox.size.z : selBox.position.z), position, lookAt); + if (selBox.position.x <= isect.x && isect.x <= selBox.position.x + selBox.size.x + && selBox.position.y <= isect.y && isect.y <= selBox.position.y + selBox.size.y) recordHit(position, isect, AXIS_Z, lookAt.z < 0., nx, ny, nz, bestX, bestY, bestZ, bestFace, bestDepth, hit); if (hit) diff --git a/client/source/world/ChunkBuilder.cpp b/client/source/world/ChunkBuilder.cpp index 81a7df20..3283d26f 100644 --- a/client/source/world/ChunkBuilder.cpp +++ b/client/source/world/ChunkBuilder.cpp @@ -144,17 +144,17 @@ inline void ChunkBuilder::addFace(u8 x, u8 y, u8 z, u8 i, const ClientChunk &chu const gk::FloatBox boundingBox = block->boundingBox(); // Three points of the face - a.x = cubeCoords[i * 12 + 0] * boundingBox.width + boundingBox.x; - a.y = cubeCoords[i * 12 + 1] * boundingBox.height + boundingBox.y; - a.z = cubeCoords[i * 12 + 2] * boundingBox.depth + boundingBox.z; + a.x = cubeCoords[i * 12 + 0] * boundingBox.size.x + boundingBox.position.x; + a.y = cubeCoords[i * 12 + 1] * boundingBox.size.y + boundingBox.position.y; + a.z = cubeCoords[i * 12 + 2] * boundingBox.size.z + boundingBox.position.z; - b.x = cubeCoords[i * 12 + 3] * boundingBox.width + boundingBox.x; - b.y = cubeCoords[i * 12 + 4] * boundingBox.height + boundingBox.y; - b.z = cubeCoords[i * 12 + 5] * boundingBox.depth + boundingBox.z; + b.x = cubeCoords[i * 12 + 3] * boundingBox.size.x + boundingBox.position.x; + b.y = cubeCoords[i * 12 + 4] * boundingBox.size.y + boundingBox.position.y; + b.z = cubeCoords[i * 12 + 5] * boundingBox.size.z + boundingBox.position.z; - c.x = cubeCoords[i * 12 + 6] * boundingBox.width + boundingBox.x; - c.y = cubeCoords[i * 12 + 7] * boundingBox.height + boundingBox.y; - c.z = cubeCoords[i * 12 + 8] * boundingBox.depth + boundingBox.z; + c.x = cubeCoords[i * 12 + 6] * boundingBox.size.x + boundingBox.position.x; + c.y = cubeCoords[i * 12 + 7] * boundingBox.size.y + boundingBox.position.y; + c.z = cubeCoords[i * 12 + 8] * boundingBox.size.z + boundingBox.position.z; // Computing two vectors v1 = b - a; diff --git a/client/source/world/ClientPlayer.cpp b/client/source/world/ClientPlayer.cpp index a4b2d0a3..1635c31a 100644 --- a/client/source/world/ClientPlayer.cpp +++ b/client/source/world/ClientPlayer.cpp @@ -157,12 +157,12 @@ void ClientPlayer::checkCollisions(const ClientWorld &world) { testPoint(world, m_x - 0.2, eyeheight - 0.4, m_z + 0.2, m_velocity); testPoint(world, m_x + 0.2, eyeheight - 0.4, m_z + 0.2, m_velocity); #else - for (float x = m_x + m_hitbox.x ; x <= m_x + m_hitbox.x + m_hitbox.width + 0.1f ; x += 0.2f) { - for (float y = m_y + m_hitbox.y ; y <= m_y + m_hitbox.y + m_hitbox.height + 0.1f ; y += 0.9f) { - for (float z = m_z + m_hitbox.z ; z <= m_z + m_hitbox.z + m_hitbox.depth + 0.1f ; z += 0.2f) { - if (x == m_x + m_hitbox.x || x == m_x + m_hitbox.x + m_hitbox.width - || y == m_y + m_hitbox.y || y == m_y + m_hitbox.y + m_hitbox.height - || z == m_z + m_hitbox.z || z == m_z + m_hitbox.z + m_hitbox.depth) + for (float x = m_x + m_hitbox.position.x ; x <= m_x + m_hitbox.position.x + m_hitbox.size.x + 0.1f ; x += 0.2f) { + for (float y = m_y + m_hitbox.position.y ; y <= m_y + m_hitbox.position.y + m_hitbox.size.y + 0.1f ; y += 0.9f) { + for (float z = m_z + m_hitbox.position.z ; z <= m_z + m_hitbox.position.z + m_hitbox.size.z + 0.1f ; z += 0.2f) { + if (x == m_x + m_hitbox.position.x || x == m_x + m_hitbox.position.x + m_hitbox.size.x + || y == m_y + m_hitbox.position.y || y == m_y + m_hitbox.position.y + m_hitbox.size.y + || z == m_z + m_hitbox.position.z || z == m_z + m_hitbox.position.z + m_hitbox.size.z) testPoint(world, x, y, z, m_velocity); } } diff --git a/common/source/world/Block.cpp b/common/source/world/Block.cpp index cfa2a3cb..145e2a44 100644 --- a/common/source/world/Block.cpp +++ b/common/source/world/Block.cpp @@ -42,8 +42,8 @@ Block::Block(u32 id, const TilesDef &tiles, const std::string &stringID, const s void Block::serialize(sf::Packet &packet) const { packet << u32(m_id) << m_stringID << m_label << u8(m_drawType) << m_hardness << m_harvestRequirements << m_itemDrop << m_itemDropAmount << m_tiles - << m_boundingBox.x << m_boundingBox.y << m_boundingBox.z - << m_boundingBox.width << m_boundingBox.height << m_boundingBox.depth + << m_boundingBox.position.x << m_boundingBox.position.y << m_boundingBox.position.z + << m_boundingBox.size.x << m_boundingBox.size.y << m_boundingBox.size.z << m_isLightSource << m_canUpdate << m_canBeActivated << m_colorMultiplier.r << m_colorMultiplier.g << m_colorMultiplier.b << m_colorMultiplier.a; } @@ -54,8 +54,8 @@ void Block::deserialize(sf::Packet &packet) { packet >> id >> m_stringID >> m_label >> drawType >> m_hardness >> m_harvestRequirements >> m_itemDrop >> m_itemDropAmount >> m_tiles - >> m_boundingBox.x >> m_boundingBox.y >> m_boundingBox.z - >> m_boundingBox.width >> m_boundingBox.height >> m_boundingBox.depth + >> m_boundingBox.position.x >> m_boundingBox.position.y >> m_boundingBox.position.z + >> m_boundingBox.size.x >> m_boundingBox.size.y >> m_boundingBox.size.z >> m_isLightSource >> m_canUpdate >> m_canBeActivated >> m_colorMultiplier.r >> m_colorMultiplier.g >> m_colorMultiplier.b >> m_colorMultiplier.a;