From f6fcdd78b21e3ee29eae11a6c2f4a0c3145dc70f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 10 May 2013 09:53:53 -0700 Subject: [PATCH] Adding/removing voxels at different sizes. --- interface/src/main.cpp | 21 ++++++++++++++++++++- libraries/voxels/src/VoxelTree.cpp | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2eb761d65d..57a4b457fb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -178,6 +178,7 @@ int mousePressed = 0; // true if mouse has been pressed (clear when finished) enum MouseMode { ADD_VOXEL_MODE, DELETE_VOXEL_MODE, COLOR_VOXEL_MODE }; MouseMode mouseMode = ADD_VOXEL_MODE; VoxelDetail mouseVoxel; // details of the voxel under the mouse cursor +float mouseVoxelScale = 1.0f / 1024.0f; // the scale for adding/removing voxels Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu @@ -1510,7 +1511,7 @@ void addVoxelInFrontOfAvatar() { VoxelDetail detail; glm::vec3 position = (myAvatar.getPosition() + myAvatar.getCameraDirection()) * (1.0f / TREE_SCALE); - detail.s = 1.0f / 1024; + detail.s = ::mouseVoxelScale; detail.x = detail.s * floor(position.x / detail.s); detail.y = detail.s * floor(position.y / detail.s); @@ -1655,6 +1656,8 @@ void key(unsigned char k, int x, int y) { if (k == '2') ::mouseMode = DELETE_VOXEL_MODE; if (k == '3') ::mouseMode = COLOR_VOXEL_MODE; if (k == '4') addVoxelInFrontOfAvatar(); + if (k == '5') ::mouseVoxelScale /= 2; + if (k == '6') ::mouseVoxelScale *= 2; if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise @@ -1790,6 +1793,22 @@ void idle(void) { BoxFace face; ::mouseVoxel.s = 0.0f; if (voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) { + // find the nearest voxel with the desired scale + if (::mouseVoxelScale > ::mouseVoxel.s) { + ::mouseVoxel.x = ::mouseVoxelScale * floorf(::mouseVoxel.x / ::mouseVoxelScale); + ::mouseVoxel.y = ::mouseVoxelScale * floorf(::mouseVoxel.y / ::mouseVoxelScale); + ::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale); + ::mouseVoxel.s = ::mouseVoxelScale; + + } else if (::mouseVoxelScale < ::mouseVoxel.s) { + glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE - + getFaceVector(face) * (::mouseVoxelScale * 0.5f); + ::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale); + ::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale); + ::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale); + ::mouseVoxel.s = ::mouseVoxelScale; + } + if (::mouseMode == ADD_VOXEL_MODE) { // use the face to determine the side on which to create a neighbor glm::vec3 offset = getFaceVector(face); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index bb55f01bc2..14cc92881e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -620,7 +620,8 @@ bool findRayOperation(VoxelNode* node, void* extraData) { if (!node->isLeaf()) { return true; // recurse on children } - if (!args->found || distance < args->distance) { + distance *= TREE_SCALE; + if (node->getShouldRender() && (!args->found || distance < args->distance)) { args->node = node; args->distance = distance; args->face = face;