mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 01:59:59 +02:00
Drag support for adding/removing (as well as coloring) voxels. I had to
ensure that the "last" voxel edited was the one under the cursor after the operation, not the one operated on.
This commit is contained in:
parent
0f2f4ee8f9
commit
85dc14bb94
2 changed files with 33 additions and 21 deletions
|
@ -138,6 +138,7 @@ Application::Application(int& argc, char** argv) :
|
|||
_mouseY(0),
|
||||
_mousePressed(false),
|
||||
_mouseVoxelScale(1.0f / 1024.0f),
|
||||
_justEditedVoxel(false),
|
||||
_paintOn(false),
|
||||
_dominantColor(0),
|
||||
_perfStatsOn(false),
|
||||
|
@ -737,8 +738,13 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
|
|||
|
||||
// detect drag
|
||||
glm::vec3 mouseVoxelPos(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z);
|
||||
if (_colorVoxelMode->isChecked() && event->buttons().testFlag(Qt::LeftButton) && mouseVoxelPos != _lastMouseVoxelPos) {
|
||||
addVoxelUnderCursor();
|
||||
if (!_justEditedVoxel && mouseVoxelPos != _lastMouseVoxelPos) {
|
||||
if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||
maybeEditVoxelUnderCursor();
|
||||
|
||||
} else if (event->buttons().testFlag(Qt::RightButton) && checkedVoxelModeAction() != 0) {
|
||||
deleteVoxelUnderCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -747,13 +753,8 @@ void Application::mousePressEvent(QMouseEvent* event) {
|
|||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mousePressed = true;
|
||||
|
||||
if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
|
||||
addVoxelUnderCursor();
|
||||
maybeEditVoxelUnderCursor();
|
||||
|
||||
} else if (_deleteVoxelMode->isChecked()) {
|
||||
deleteVoxelUnderCursor();
|
||||
}
|
||||
} else if (event->button() == Qt::RightButton && checkedVoxelModeAction() != 0) {
|
||||
deleteVoxelUnderCursor();
|
||||
}
|
||||
|
@ -926,6 +927,12 @@ void Application::idle() {
|
|||
_mouseVoxel.green = paintColor.green();
|
||||
_mouseVoxel.blue = paintColor.blue();
|
||||
}
|
||||
|
||||
// if we just edited, use the currently selected voxel as the "last" for drag detection
|
||||
if (_justEditedVoxel) {
|
||||
_lastMouseVoxelPos = glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z);
|
||||
_justEditedVoxel = false;
|
||||
}
|
||||
}
|
||||
|
||||
// walking triggers the handControl to stop
|
||||
|
@ -2015,18 +2022,22 @@ void Application::shiftPaintingColor() {
|
|||
_paintingVoxel.blue = (_dominantColor == 2) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
}
|
||||
|
||||
void Application::addVoxelUnderCursor() {
|
||||
if (_mouseVoxel.s != 0) {
|
||||
PACKET_HEADER message = (_destructiveAddVoxel->isChecked() ?
|
||||
PACKET_HEADER_SET_VOXEL_DESTRUCTIVE : PACKET_HEADER_SET_VOXEL);
|
||||
sendVoxelEditMessage(message, _mouseVoxel);
|
||||
void Application::maybeEditVoxelUnderCursor() {
|
||||
if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
|
||||
if (_mouseVoxel.s != 0) {
|
||||
PACKET_HEADER message = (_destructiveAddVoxel->isChecked() ?
|
||||
PACKET_HEADER_SET_VOXEL_DESTRUCTIVE : PACKET_HEADER_SET_VOXEL);
|
||||
sendVoxelEditMessage(message, _mouseVoxel);
|
||||
|
||||
// create the voxel locally so it appears immediately
|
||||
_voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
|
||||
_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, _destructiveAddVoxel->isChecked());
|
||||
|
||||
// create the voxel locally so it appears immediately
|
||||
_voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
|
||||
_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, _destructiveAddVoxel->isChecked());
|
||||
|
||||
// remember the position for drag detection
|
||||
_lastMouseVoxelPos = glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z);
|
||||
// remember the position for drag detection
|
||||
_justEditedVoxel = true;
|
||||
}
|
||||
} else if (_deleteVoxelMode->isChecked()) {
|
||||
deleteVoxelUnderCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2038,7 +2049,7 @@ void Application::deleteVoxelUnderCursor() {
|
|||
_voxels.deleteVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
|
||||
|
||||
// remember the position for drag detection
|
||||
_lastMouseVoxelPos = glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z);
|
||||
_justEditedVoxel = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ private:
|
|||
|
||||
void setupPaintingVoxel();
|
||||
void shiftPaintingColor();
|
||||
void addVoxelUnderCursor();
|
||||
void maybeEditVoxelUnderCursor();
|
||||
void deleteVoxelUnderCursor();
|
||||
|
||||
void resetSensors();
|
||||
|
@ -202,6 +202,7 @@ private:
|
|||
VoxelDetail _mouseVoxel; // details of the voxel under the mouse cursor
|
||||
float _mouseVoxelScale; // the scale for adding/removing voxels
|
||||
glm::vec3 _lastMouseVoxelPos; // the position of the last mouse voxel edit
|
||||
bool _justEditedVoxel; // set when we've just added/deleted/colored a voxel
|
||||
|
||||
bool _paintOn; // Whether to paint voxels as you fly around
|
||||
unsigned char _dominantColor; // The dominant color of the voxel we're painting
|
||||
|
|
Loading…
Reference in a new issue