From abf8e83c335e297a9044c5a884656f090d09c5b2 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 5 Jan 2014 11:09:16 -0800 Subject: [PATCH] change Voxels JS interface to be more clear --- examples/gun.js | 46 +++++++++---------- interface/src/Application.cpp | 4 +- libraries/script-engine/src/ScriptEngine.cpp | 2 - .../voxels/src/VoxelsScriptingInterface.cpp | 14 +++--- .../voxels/src/VoxelsScriptingInterface.h | 10 ++-- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index e9b1472700..c9554594c2 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -24,7 +24,7 @@ function checkController() { var numberOfTriggers = Controller.getNumberOfTriggers(); var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; - + // this is expected for hydras if (numberOfTriggers == 2 && controllersPerTrigger == 2) { for (var t = 0; t < numberOfTriggers; t++) { @@ -43,38 +43,38 @@ function checkController() { shootABullet = true; } } - + if (shootABullet) { - var palmController = t * controllersPerTrigger; + var palmController = t * controllersPerTrigger; var palmPosition = Controller.getSpatialControlPosition(palmController); - var fingerTipController = palmController + 1; + var fingerTipController = palmController + 1; var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); - + var bulletSize = 0.25/TREE_SCALE; - var palmInParticleSpace = - { x: palmPosition.x/TREE_SCALE, - y: palmPosition.y/TREE_SCALE, + var palmInParticleSpace = + { x: palmPosition.x/TREE_SCALE, + y: palmPosition.y/TREE_SCALE, z: palmPosition.z/TREE_SCALE }; - - var tipInParticleSpace = - { x: fingerTipPosition.x/TREE_SCALE, - y: fingerTipPosition.y/TREE_SCALE, + + var tipInParticleSpace = + { x: fingerTipPosition.x/TREE_SCALE, + y: fingerTipPosition.y/TREE_SCALE, z: fingerTipPosition.z/TREE_SCALE }; - var palmToFingerTipVector = + var palmToFingerTipVector = { x: (tipInParticleSpace.x - palmInParticleSpace.x), y: (tipInParticleSpace.y - palmInParticleSpace.y), z: (tipInParticleSpace.z - palmInParticleSpace.z) }; - + // just off the front of the finger tip - var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2, - y: tipInParticleSpace.y + palmToFingerTipVector.y/2, - z: tipInParticleSpace.z + palmToFingerTipVector.z/2}; + var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2, + y: tipInParticleSpace.y + palmToFingerTipVector.y/2, + z: tipInParticleSpace.z + palmToFingerTipVector.z/2}; var linearVelocity = 50; // 50 meters per second - + var velocity = { x: palmToFingerTipVector.x * linearVelocity, y: palmToFingerTipVector.y * linearVelocity, z: palmToFingerTipVector.z * linearVelocity }; @@ -85,7 +85,7 @@ function checkController() { var inHand = false; // This is the script for the particles that this gun shoots. - var script = + var script = " function collisionWithVoxel(voxel) { " + " print('collisionWithVoxel(voxel)... '); " + " print('myID=' + Particle.getID() + '\\n'); " + @@ -96,17 +96,17 @@ function checkController() { " Particle.setColor(voxelColor); " + " var voxelAt = voxel.getPosition();" + " var voxelScale = voxel.getScale();" + - " Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " + - " print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " + + " Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " + + " print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " + " } " + " Particle.collisionWithVoxel.connect(collisionWithVoxel); "; - + Particles.queueParticleAdd(position, bulletSize, color, velocity, gravity, damping, inHand, script); } } } } - + // register the call back so it fires before each data send Agent.willSendVisualDataCallback.connect(checkController); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 64a50a5b99..40de415c94 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1561,8 +1561,8 @@ void Application::shootParticle() { " Particle.setColor(voxelColor); " " var voxelAt = voxel.getPosition();" " var voxelScale = voxel.getScale();" - " Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " - " print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " + " Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " + " print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " " } " " Particle.collisionWithVoxel.connect(collisionWithVoxel); " ); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 86b6e8884e..3410b59d86 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -145,7 +145,6 @@ void ScriptEngine::evaluate() { } QScriptValue result = _engine.evaluate(_scriptContents); - qDebug() << "Evaluated script.\n"; if (_engine.hasUncaughtException()) { int line = _engine.uncaughtExceptionLineNumber(); @@ -160,7 +159,6 @@ void ScriptEngine::run() { _isRunning = true; QScriptValue result = _engine.evaluate(_scriptContents); - qDebug() << "Evaluated script.\n"; if (_engine.hasUncaughtException()) { int line = _engine.uncaughtExceptionLineNumber(); diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index b17e40c036..df5dad8231 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -12,28 +12,28 @@ void VoxelsScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDet getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails); } -void VoxelsScriptingInterface::queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { +void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { // setup a VoxelDetail struct with the data VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; - + // queue the packet queueVoxelAdd(PACKET_TYPE_VOXEL_SET, addVoxelDetail); } -void VoxelsScriptingInterface::queueDestructiveVoxelAdd(float x, float y, float z, float scale, +void VoxelsScriptingInterface::destructiveSetVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { // setup a VoxelDetail struct with the data VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; - + // queue the destructive add queueVoxelAdd(PACKET_TYPE_VOXEL_SET_DESTRUCTIVE, addVoxelDetail); } -void VoxelsScriptingInterface::queueVoxelDelete(float x, float y, float z, float scale) { - +void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale) { + // setup a VoxelDetail struct with data VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0}; - + getVoxelPacketSender()->queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail); } diff --git a/libraries/voxels/src/VoxelsScriptingInterface.h b/libraries/voxels/src/VoxelsScriptingInterface.h index c725b93493..ea9f6a4205 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.h +++ b/libraries/voxels/src/VoxelsScriptingInterface.h @@ -33,8 +33,8 @@ public slots: /// \param red the R value for RGB color of voxel /// \param green the G value for RGB color of voxel /// \param blue the B value for RGB color of voxel - void queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); - + void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + /// queues the destructive creation of a voxel which will be sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in VS space) /// \param y the y-coordinate of the voxel (in VS space) @@ -43,14 +43,14 @@ public slots: /// \param red the R value for RGB color of voxel /// \param green the G value for RGB color of voxel /// \param blue the B value for RGB color of voxel - void queueDestructiveVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); - + void destructiveSetVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + /// queues the deletion of a voxel, sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in VS space) /// \param y the y-coordinate of the voxel (in VS space) /// \param z the z-coordinate of the voxel (in VS space) /// \param scale the scale of the voxel (in VS space) - void queueVoxelDelete(float x, float y, float z, float scale); + void eraseVoxel(float x, float y, float z, float scale); private: void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails);