Voxel editing with hands, flying and rotation with hands

This commit is contained in:
Philip Rosedale 2013-12-02 00:17:06 -08:00
parent 2456c26207
commit 7ab9cc9c14
7 changed files with 58 additions and 18 deletions

View file

@ -1487,6 +1487,19 @@ void Application::doKillLocalVoxels() {
_wantToKillLocalVoxels = true;
}
void Application::removeVoxel(glm::vec3 position,
float scale) {
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;
_voxelEditSender.sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, voxel);
// delete it locally to see the effect immediately (and in case no voxel server is present)
_voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s);
}
void Application::makeVoxel(glm::vec3 position,
float scale,
unsigned char red,

View file

@ -123,6 +123,9 @@ public:
unsigned char green,
unsigned char blue,
bool isDestructive);
void removeVoxel(glm::vec3 position, float scale);
const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel);
QGLWidget* getGLWidget() { return _glWidget; }

View file

@ -67,10 +67,10 @@ void Hand::simulate(float deltaTime, bool isMine) {
for (size_t i = 0; i < getNumPalms(); ++i) {
PalmData& palm = getPalms()[i];
if (palm.isActive()) {
FingerData& finger = palm.getFingers()[0];
glm::vec3 newVoxelPosition = finger.getTipPosition();
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)) {
if (glm::length(newVoxelPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
Application::getInstance()->makeVoxel(newVoxelPosition,
FINGERTIP_VOXEL_SIZE,
@ -78,7 +78,12 @@ void Hand::simulate(float deltaTime, bool isMine) {
paintColor.green(),
paintColor.blue(),
true);
_lastFingerVoxel = newVoxelPosition;
_lastFingerAddVoxel = newVoxelPosition;
}
} else if (palm.getControllerButtons() & BUTTON_2) {
if (glm::length(newVoxelPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
Application::getInstance()->removeVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE);
_lastFingerDeleteVoxel = newVoxelPosition;
}
}
}
@ -185,17 +190,27 @@ void Hand::render() {
PalmData& palm = getPalms()[i];
// If trigger pulled, thrust in that direction and draw beam
const float MAX_THRUSTER_BEAM_LENGTH = 5.f;
if (palm.getTrigger() > 0.f) {
const float THRUSTER_MARKER_SIZE = 0.0125f;
if (palm.getJoystickY() != 0.f) {
FingerData& finger = palm.getFingers()[0];
if (finger.isActive() && (palm.getTrigger() > 0.f)) {
if (finger.isActive()) {
if (palm.getJoystickY() > 0.f) {
glColor3f(0, 1, 0);
} else {
glColor3f(1, 0, 0);
}
glm::vec3 palmPosition = palm.getPosition();
glm::vec3 pointerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
(0.01f + palm.getTrigger()) * MAX_THRUSTER_BEAM_LENGTH;
glColor4f(1, 0, 0, 0.5);
MAX_THRUSTER_BEAM_LENGTH;
glPushMatrix();
glTranslatef(pointerPosition.x, pointerPosition.y, pointerPosition.z);
glutSolidSphere(0.05, 10, 10);
glm::vec3 markerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
MAX_THRUSTER_BEAM_LENGTH *
(0.5f + palm.getJoystickY() / 2.f);
glTranslatef(markerPosition.x, markerPosition.y, markerPosition.z);
glutSolidSphere(THRUSTER_MARKER_SIZE, 10, 10);
glPopMatrix();
glLineWidth(2.0);
glBegin(GL_LINES);
@ -279,7 +294,7 @@ void Hand::renderLeapHands() {
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glDepthMask(GL_TRUE);
glPushMatrix();
// Draw the leap balls
for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) {

View file

@ -82,7 +82,7 @@ private:
std::vector<HandBall> _leapFingerTipBalls;
std::vector<HandBall> _leapFingerRootBalls;
glm::vec3 _lastFingerVoxel;
glm::vec3 _lastFingerAddVoxel, _lastFingerDeleteVoxel;
// private methods
void setLeapHands(const std::vector<glm::vec3>& handPositions,

View file

@ -848,17 +848,21 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
up;
}
}
// Add thrust from hand controllers
const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD / 5.f;
// Add thrust and rotation from hand controllers
const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD;
const float JOYSTICK_YAW_MAG = YAW_MAG;
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
PalmData& palm = getHand().getPalms()[i];
if (palm.isActive()) {
if (palm.getTrigger() > 0.f) {
if (palm.getJoystickY() != 0.f) {
FingerData& finger = palm.getFingers()[0];
if (finger.isActive()) {
}
glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition());
_thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * powf(palm.getTrigger() * 10.f, 2.f) * _thrustMultiplier * deltaTime;
_thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * palm.getJoystickY() * _thrustMultiplier * deltaTime;
}
if (palm.getJoystickX() != 0.f) {
_bodyYawDelta -= palm.getJoystickX() * JOYSTICK_YAW_MAG * deltaTime;
}
}
}

View file

@ -50,9 +50,10 @@ void SixenseManager::update(float deltaTime) {
// Compute current velocity from position change
palm.setVelocity((position - palm.getPosition()) / deltaTime);
// Read controller buttons into the hand
// Read controller buttons and joystick into the hand
palm.setControllerButtons(data.buttons);
palm.setTrigger(data.trigger);
palm.setJoystick(data.joystick_x, data.joystick_y);
// Adjust for distance between acquisition 'orb' and the user's torso
// (distance to the right of body center, distance below torso, distance behind torso)

View file

@ -163,6 +163,9 @@ public:
void setTrigger(float trigger) { _trigger = trigger; }
float getTrigger() { return _trigger; }
void setJoystick(float joystickX, float joystickY) { _joystickX = joystickX; _joystickY = joystickY; }
float getJoystickX() { return _joystickX; }
float getJoystickY() { return _joystickY; }
private:
std::vector<FingerData> _fingers;
@ -170,7 +173,8 @@ private:
glm::vec3 _rawNormal;
glm::vec3 _velocity;
int _controllerButtons;
float _trigger;
float _trigger;
float _joystickX, _joystickY;
bool _isActive; // This has current valid data
int _leapID; // the Leap's serial id for this tracked object