History

Return the box face, as well as the distance, from the ray intersection test. Use it to determine which voxel neighbor we create when adding.

Andrzej Kapolka committed 13 years ago

Commit 7ff8b841 parent 2b9c2ca7 files · +68 −19Browse files

Showing the changes to interface/src/main.cpp (1 of 7 files). Show all

Unified · Split

interface/src/main.cpp+30−6
@@ -1489,11 +1489,34 @@ void addVoxelUnderCursor() { · 1488 unmodified lines
14891489
14901490 VoxelDetail detail;
14911491 float distance;
1492− if (voxels.findRayIntersection(origin, direction, detail, distance)) {
1493− // get the hit location relative to the center of the voxel
1494− float half = detail.s * 0.5f;
1495− glm::vec3 hit = origin + distance*direction - glm::vec3(detail.x + half, detail.y + half, detail.z + half);
1496−
1492+ BoxFace face;
1493+ if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
1494+ // use the face to determine the side on which to create a neighbor
1495+ switch (face) {
1496+ case MIN_X_FACE:
1497+ detail.x -= detail.s;
1498+ break;
1499+
1500+ case MAX_X_FACE:
1501+ detail.x += detail.s;
1502+ break;
1503+
1504+ case MIN_Y_FACE:
1505+ detail.y -= detail.s;
1506+ break;
1507+
1508+ case MAX_Y_FACE:
1509+ detail.y += detail.s;
1510+ break;
1511+
1512+ case MIN_Z_FACE:
1513+ detail.z -= detail.s;
1514+ break;
1515+
1516+ case MAX_Z_FACE:
1517+ detail.z += detail.s;
1518+ break;
1519+ }
14971520 unsigned char* bufferOut;
14981521 int sizeOut;
14991522
@@ -1510,7 +1533,8 @@ void deleteVoxelUnderCursor() { · 10 unmodified lines
15101533
15111534 VoxelDetail detail;
15121535 float distance;
1513− if (voxels.findRayIntersection(origin, direction, detail, distance)) {
1536+ BoxFace face;
1537+ if (voxels.findRayIntersection(origin, direction, detail, distance, face)) {
15141538 unsigned char* bufferOut;
15151539 int sizeOut;
15161540