mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 20:44:14 +02:00
Working on voxel editing.
This commit is contained in:
parent
4e789dcfbf
commit
785e55e06f
3 changed files with 58 additions and 1 deletions
|
@ -613,3 +613,18 @@ void VoxelSystem::removeOutOfView() {
|
|||
_nodeCount = 0;
|
||||
_tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)this);
|
||||
}
|
||||
|
||||
bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelDetail& detail, float& distance) {
|
||||
VoxelNode* node;
|
||||
if (!_tree->findRayIntersection(origin, direction, node, distance)) {
|
||||
return false;
|
||||
}
|
||||
detail.x = node->getCorner().x;
|
||||
detail.y = node->getCorner().y;
|
||||
detail.z = node->getCorner().z;
|
||||
detail.s = node->getScale();
|
||||
detail.red = node->getColor()[0];
|
||||
detail.green = node->getColor()[1];
|
||||
detail.blue = node->getColor()[2];
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "InterfaceConfig.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <SharedUtil.h>
|
||||
#include <UDPSocket.h>
|
||||
#include <AgentData.h>
|
||||
#include <VoxelTree.h>
|
||||
|
@ -64,6 +65,8 @@ public:
|
|||
void removeOutOfView();
|
||||
bool hasViewChanged();
|
||||
|
||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelDetail& detail, float& distance);
|
||||
|
||||
private:
|
||||
int _callsToTreesToArrays;
|
||||
VoxelNodeBag _removedVoxels;
|
||||
|
|
|
@ -70,7 +70,6 @@
|
|||
#include "Oscilloscope.h"
|
||||
#include "UDPSocket.h"
|
||||
#include "SerialInterface.h"
|
||||
#include <SharedUtil.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <AvatarData.h>
|
||||
#include <PerfStat.h>
|
||||
|
@ -1457,6 +1456,44 @@ void setupPaintingVoxel() {
|
|||
shiftPaintingColor();
|
||||
}
|
||||
|
||||
void addVoxelUnderCursor() {
|
||||
glm::vec3 origin, direction;
|
||||
viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
|
||||
|
||||
VoxelDetail detail;
|
||||
float distance;
|
||||
if (voxels.findRayIntersection(origin, direction, detail, distance)) {
|
||||
// get the hit location relative to the center of the voxel
|
||||
float half = detail.s * 0.5f;
|
||||
glm::vec3 hit = origin + distance*direction - glm::vec3(detail.x + half, detail.y + half, detail.z + half);
|
||||
|
||||
unsigned char* bufferOut;
|
||||
int sizeOut;
|
||||
|
||||
if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
|
||||
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||
delete bufferOut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deleteVoxelUnderCursor() {
|
||||
glm::vec3 origin, direction;
|
||||
viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction);
|
||||
|
||||
VoxelDetail detail;
|
||||
float distance;
|
||||
if (voxels.findRayIntersection(origin, direction, detail, distance)) {
|
||||
unsigned char* bufferOut;
|
||||
int sizeOut;
|
||||
|
||||
if (createVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){
|
||||
AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1);
|
||||
delete bufferOut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const float KEYBOARD_YAW_RATE = 0.8;
|
||||
const float KEYBOARD_PITCH_RATE = 0.6;
|
||||
const float KEYBOARD_STRAFE_RATE = 0.03;
|
||||
|
@ -1574,6 +1611,8 @@ void key(unsigned char k, int x, int y) {
|
|||
if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant
|
||||
if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server
|
||||
if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server
|
||||
if (k == '1') ::addVoxelUnderCursor();
|
||||
if (k == '2') ::deleteVoxelUnderCursor();
|
||||
if (k == 'n' || k == 'N')
|
||||
{
|
||||
noiseOn = !noiseOn; // Toggle noise
|
||||
|
|
Loading…
Reference in a new issue