move hydra finger painting from c++ to js

This commit is contained in:
ZappoMan 2014-03-03 01:06:48 -08:00
parent 2c7d9d7a06
commit d8d61c7361
3 changed files with 49 additions and 27 deletions

View file

@ -1277,12 +1277,61 @@ function touchEndEvent(event) {
}
}
var lastFingerAddVoxel = { x: -1, y: -1, z: -1}; // off of the build-able area
var lastFingerDeleteVoxel = { x: -1, y: -1, z: -1}; // off of the build-able area
function checkControllers() {
var controllersPerPalm = 2; // palm and finger
for (var palm = 0; palm < 2; palm++) {
var palmController = palm * controllersPerPalm;
var palmPosition = Controller.getSpatialControlPosition(palmController);
var fingerTipController = palmController + 1;
var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController);
var BUTTON_COUNT = 6;
var BUTTON_BASE = palm * BUTTON_COUNT;
var BUTTON_0 = BUTTON_BASE + 0; // the skinny button between 1 and 2
var BUTTON_1 = BUTTON_BASE + 1;
var BUTTON_2 = BUTTON_BASE + 2;
var BUTTON_3 = BUTTON_BASE + 3;
var BUTTON_4 = BUTTON_BASE + 4;
var BUTTON_FWD = BUTTON_BASE + 5;
var FINGERTIP_VOXEL_SIZE = 0.05;
if (Controller.isButtonPressed(BUTTON_1)) {
if (Vec3.length(Vec3.subtract(fingerTipPosition,lastFingerAddVoxel)) > (FINGERTIP_VOXEL_SIZE / 2)) {
if (whichColor == -1) {
newColor = { red: colors[0].red, green: colors[0].green, blue: colors[0].blue };
} else {
newColor = { red: colors[whichColor].red, green: colors[whichColor].green, blue: colors[whichColor].blue };
}
Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE);
Voxels.setVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE,
newColor.red, newColor.green, newColor.blue);
lastFingerAddVoxel = fingerTipPosition;
}
} else if (Controller.isButtonPressed(BUTTON_2)) {
if (Vec3.length(Vec3.subtract(fingerTipPosition,lastFingerDeleteVoxel)) > (FINGERTIP_VOXEL_SIZE / 2)) {
Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE);
lastFingerDeleteVoxel = fingerTipPosition;
}
}
}
}
function update() {
var newWindowDimensions = Controller.getViewportDimensions();
if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) {
windowDimensions = newWindowDimensions;
moveTools();
}
if (editToolsOn) {
checkControllers();
}
}
function wheelEvent(event) {

View file

@ -82,9 +82,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
_viewFrustum = Application::getInstance()->getViewFrustum();
connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
_useVoxelShader = false;
_voxelsAsPoints = false;
_voxelShaderModeWhenVoxelsAsPointsEnabled = false;
@ -1185,9 +1182,6 @@ void VoxelSystem::changeTree(VoxelTree* newTree) {
_tree->setDirtyBit();
_tree->getRoot()->setVoxelSystem(this);
connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
setupNewVoxelsForDrawing();
}

View file

@ -20,7 +20,6 @@
using namespace std;
const float FINGERTIP_COLLISION_RADIUS = 0.01f;
const float FINGERTIP_VOXEL_SIZE = 0.05f;
const float PALM_COLLISION_RADIUS = 0.03f;
@ -57,26 +56,6 @@ void Hand::simulate(float deltaTime, bool isMine) {
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
glm::vec3 fingerTipPosition = finger.getTipPosition();
if (palm.getControllerButtons() & BUTTON_1) {
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
// TODO: we need to move this code to JS so it can access the editVoxels.js color palette
QColor paintColor(128,128,128);
Application::getInstance()->makeVoxel(fingerTipPosition,
FINGERTIP_VOXEL_SIZE,
paintColor.red(),
paintColor.green(),
paintColor.blue(),
true);
_lastFingerAddVoxel = fingerTipPosition;
}
} else if (palm.getControllerButtons() & BUTTON_2) {
if (glm::length(fingerTipPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
Application::getInstance()->removeVoxel(fingerTipPosition, FINGERTIP_VOXEL_SIZE);
_lastFingerDeleteVoxel = fingerTipPosition;
}
}
// Voxel Drumming with fingertips if enabled
if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) {
OctreeElement* fingerElement = Application::getInstance()->getVoxelTree()->getElementEnclosingPoint(