mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:00:44 +02:00
First working voxel insertion at fingertip
This commit is contained in:
parent
a9139b05e8
commit
ea850368de
5 changed files with 64 additions and 4 deletions
|
@ -1487,6 +1487,44 @@ void Application::doKillLocalVoxels() {
|
||||||
_wantToKillLocalVoxels = true;
|
_wantToKillLocalVoxels = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::createVoxel(glm::vec3 position,
|
||||||
|
float scale,
|
||||||
|
glm::vec3 color,
|
||||||
|
bool isDestructive) {
|
||||||
|
VoxelDetail voxel;
|
||||||
|
voxel.x = position.x / TREE_SCALE;
|
||||||
|
voxel.y = position.y / TREE_SCALE;
|
||||||
|
voxel.z = position.z / TREE_SCALE;
|
||||||
|
voxel.s = scale / TREE_SCALE;
|
||||||
|
voxel.red = color.x;
|
||||||
|
voxel.green = color.y;
|
||||||
|
voxel.blue = color.z;
|
||||||
|
PACKET_TYPE message = isDestructive ? PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL;
|
||||||
|
_voxelEditSender.sendVoxelEditMessage(message, voxel);
|
||||||
|
|
||||||
|
// create the voxel locally so it appears immediately
|
||||||
|
|
||||||
|
_voxels.createVoxel(voxel.x, voxel.y, voxel.z, voxel.s,
|
||||||
|
voxel.red, voxel.green, voxel.blue,
|
||||||
|
isDestructive);
|
||||||
|
|
||||||
|
// Implement voxel fade effect
|
||||||
|
VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f);
|
||||||
|
const float VOXEL_BOUNDS_ADJUST = 0.01f;
|
||||||
|
float slightlyBigger = voxel.s * VOXEL_BOUNDS_ADJUST;
|
||||||
|
fade.voxelDetails.x = voxel.x - slightlyBigger;
|
||||||
|
fade.voxelDetails.y = voxel.y - slightlyBigger;
|
||||||
|
fade.voxelDetails.z = voxel.z - slightlyBigger;
|
||||||
|
fade.voxelDetails.s = voxel.s + slightlyBigger + slightlyBigger;
|
||||||
|
_voxelFades.push_back(fade);
|
||||||
|
|
||||||
|
// inject a sound effect
|
||||||
|
injectVoxelAddedSoundEffect();
|
||||||
|
|
||||||
|
// remember the position for drag detection
|
||||||
|
_justEditedVoxel = true;
|
||||||
|
}
|
||||||
|
|
||||||
const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) {
|
const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) {
|
||||||
return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
||||||
(_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
(_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
||||||
|
@ -4097,6 +4135,8 @@ bool Application::maybeEditVoxelUnderCursor() {
|
||||||
_voxelEditSender.sendVoxelEditMessage(message, _mouseVoxel);
|
_voxelEditSender.sendVoxelEditMessage(message, _mouseVoxel);
|
||||||
|
|
||||||
// create the voxel locally so it appears immediately
|
// create the voxel locally so it appears immediately
|
||||||
|
printf("create voxel from mouse %.4f, %.4f, %.4f, scale %.6f \n", _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
|
||||||
|
|
||||||
_voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
|
_voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s,
|
||||||
_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue,
|
_mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue,
|
||||||
Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel));
|
Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel));
|
||||||
|
|
|
@ -117,6 +117,7 @@ public:
|
||||||
|
|
||||||
void wheelEvent(QWheelEvent* event);
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
|
void createVoxel(glm::vec3 position, float scale, glm::vec3 color, bool isDestructive);
|
||||||
const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel);
|
const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel);
|
||||||
|
|
||||||
QGLWidget* getGLWidget() { return _glWidget; }
|
QGLWidget* getGLWidget() { return _glWidget; }
|
||||||
|
|
|
@ -61,6 +61,24 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
|
|
||||||
updateRaveGloveParticles(deltaTime);
|
updateRaveGloveParticles(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a voxel at fingertip if controller button is pressed
|
||||||
|
const float FINGERTIP_VOXEL_SIZE = 0.0125;
|
||||||
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
|
PalmData& palm = getPalms()[i];
|
||||||
|
if (palm.isActive()) {
|
||||||
|
if (palm.getControllerButtons() & BUTTON_1) {
|
||||||
|
FingerData& finger = palm.getFingers()[0];
|
||||||
|
glm::vec3 newVoxelPosition = finger.getTipPosition();
|
||||||
|
if (glm::length(newVoxelPosition - _lastFingerVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
||||||
|
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
|
||||||
|
glm::vec3 newVoxelColor(paintColor.red(), paintColor.green(), paintColor.blue());
|
||||||
|
Application::getInstance()->createVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE, newVoxelColor, true);
|
||||||
|
_lastFingerVoxel = newVoxelPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::calculateGeometry() {
|
void Hand::calculateGeometry() {
|
||||||
|
@ -166,7 +184,6 @@ void Hand::render() {
|
||||||
if (palm.getTrigger() > 0.f) {
|
if (palm.getTrigger() > 0.f) {
|
||||||
FingerData& finger = palm.getFingers()[0];
|
FingerData& finger = palm.getFingers()[0];
|
||||||
if (finger.isActive() && (palm.getTrigger() > 0.f)) {
|
if (finger.isActive() && (palm.getTrigger() > 0.f)) {
|
||||||
printf("trigger = %.2f\n", palm.getTrigger());
|
|
||||||
glm::vec3 palmPosition = palm.getPosition();
|
glm::vec3 palmPosition = palm.getPosition();
|
||||||
glm::vec3 pointerPosition = palmPosition +
|
glm::vec3 pointerPosition = palmPosition +
|
||||||
glm::normalize(finger.getTipPosition() - palmPosition) *
|
glm::normalize(finger.getTipPosition() - palmPosition) *
|
||||||
|
@ -257,7 +274,7 @@ void Hand::renderLeapHands() {
|
||||||
//const glm::vec3 handColor = _ballColor;
|
//const glm::vec3 handColor = _ballColor;
|
||||||
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
|
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
// Draw the leap balls
|
// Draw the leap balls
|
||||||
|
|
|
@ -82,6 +82,8 @@ private:
|
||||||
std::vector<HandBall> _leapFingerTipBalls;
|
std::vector<HandBall> _leapFingerTipBalls;
|
||||||
std::vector<HandBall> _leapFingerRootBalls;
|
std::vector<HandBall> _leapFingerRootBalls;
|
||||||
|
|
||||||
|
glm::vec3 _lastFingerVoxel;
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
void setLeapHands(const std::vector<glm::vec3>& handPositions,
|
void setLeapHands(const std::vector<glm::vec3>& handPositions,
|
||||||
const std::vector<glm::vec3>& handNormals);
|
const std::vector<glm::vec3>& handNormals);
|
||||||
|
|
|
@ -849,7 +849,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add thrust from hand controllers
|
// Add thrust from hand controllers
|
||||||
const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD * 100.f;
|
const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD / 5.f;
|
||||||
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
|
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
|
||||||
PalmData& palm = getHand().getPalms()[i];
|
PalmData& palm = getHand().getPalms()[i];
|
||||||
if (palm.isActive()) {
|
if (palm.isActive()) {
|
||||||
|
@ -858,7 +858,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
||||||
if (finger.isActive()) {
|
if (finger.isActive()) {
|
||||||
}
|
}
|
||||||
glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition());
|
glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition());
|
||||||
_thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * palm.getTrigger() * _thrustMultiplier * deltaTime;
|
_thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * powf(palm.getTrigger() * 10.f, 2.f) * _thrustMultiplier * deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue