Add a distance check for selected voxels.

This commit is contained in:
Geenz 2013-06-07 16:34:10 -04:00
parent 1c8d4f7717
commit 65ec02044e

View file

@ -786,6 +786,7 @@ static glm::vec3 getFaceVector(BoxFace face) {
}
const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;
const float MAX_VOXEL_EDIT_DISTANCE = 20.0f;
void Application::idle() {
timeval check;
@ -830,6 +831,8 @@ void Application::idle() {
float distance;
BoxFace face;
if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) {
if (distance < MAX_VOXEL_EDIT_DISTANCE) {
// find the nearest voxel with the desired scale
if (_mouseVoxelScale > _mouseVoxel.s) {
// choose the larger voxel that encompasses the one selected
@ -856,6 +859,10 @@ void Application::idle() {
_mouseVoxel.z += faceVector.z * _mouseVoxel.s;
}
}
} else {
// We're not within range. Don't render the selection.
_mouseVoxel.s = 0;
}
} else if (_addVoxelMode->isChecked() || _selectVoxelMode->isChecked()) {
// place the voxel a fixed distance away
float worldMouseVoxelScale = _mouseVoxelScale * TREE_SCALE;