change Voxels JS interface to be more clear

This commit is contained in:
Brad Hefta-Gaub 2014-01-05 11:09:16 -08:00
parent 7ce774da70
commit abf8e83c33
5 changed files with 37 additions and 39 deletions

View file

@ -24,7 +24,7 @@ function checkController() {
var numberOfTriggers = Controller.getNumberOfTriggers(); var numberOfTriggers = Controller.getNumberOfTriggers();
var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
// this is expected for hydras // this is expected for hydras
if (numberOfTriggers == 2 && controllersPerTrigger == 2) { if (numberOfTriggers == 2 && controllersPerTrigger == 2) {
for (var t = 0; t < numberOfTriggers; t++) { for (var t = 0; t < numberOfTriggers; t++) {
@ -43,38 +43,38 @@ function checkController() {
shootABullet = true; shootABullet = true;
} }
} }
if (shootABullet) { if (shootABullet) {
var palmController = t * controllersPerTrigger; var palmController = t * controllersPerTrigger;
var palmPosition = Controller.getSpatialControlPosition(palmController); var palmPosition = Controller.getSpatialControlPosition(palmController);
var fingerTipController = palmController + 1; var fingerTipController = palmController + 1;
var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController);
var bulletSize = 0.25/TREE_SCALE; var bulletSize = 0.25/TREE_SCALE;
var palmInParticleSpace = var palmInParticleSpace =
{ x: palmPosition.x/TREE_SCALE, { x: palmPosition.x/TREE_SCALE,
y: palmPosition.y/TREE_SCALE, y: palmPosition.y/TREE_SCALE,
z: palmPosition.z/TREE_SCALE }; z: palmPosition.z/TREE_SCALE };
var tipInParticleSpace = var tipInParticleSpace =
{ x: fingerTipPosition.x/TREE_SCALE, { x: fingerTipPosition.x/TREE_SCALE,
y: fingerTipPosition.y/TREE_SCALE, y: fingerTipPosition.y/TREE_SCALE,
z: fingerTipPosition.z/TREE_SCALE }; z: fingerTipPosition.z/TREE_SCALE };
var palmToFingerTipVector = var palmToFingerTipVector =
{ x: (tipInParticleSpace.x - palmInParticleSpace.x), { x: (tipInParticleSpace.x - palmInParticleSpace.x),
y: (tipInParticleSpace.y - palmInParticleSpace.y), y: (tipInParticleSpace.y - palmInParticleSpace.y),
z: (tipInParticleSpace.z - palmInParticleSpace.z) }; z: (tipInParticleSpace.z - palmInParticleSpace.z) };
// just off the front of the finger tip // just off the front of the finger tip
var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2, var position = { x: tipInParticleSpace.x + palmToFingerTipVector.x/2,
y: tipInParticleSpace.y + palmToFingerTipVector.y/2, y: tipInParticleSpace.y + palmToFingerTipVector.y/2,
z: tipInParticleSpace.z + palmToFingerTipVector.z/2}; z: tipInParticleSpace.z + palmToFingerTipVector.z/2};
var linearVelocity = 50; // 50 meters per second var linearVelocity = 50; // 50 meters per second
var velocity = { x: palmToFingerTipVector.x * linearVelocity, var velocity = { x: palmToFingerTipVector.x * linearVelocity,
y: palmToFingerTipVector.y * linearVelocity, y: palmToFingerTipVector.y * linearVelocity,
z: palmToFingerTipVector.z * linearVelocity }; z: palmToFingerTipVector.z * linearVelocity };
@ -85,7 +85,7 @@ function checkController() {
var inHand = false; var inHand = false;
// This is the script for the particles that this gun shoots. // This is the script for the particles that this gun shoots.
var script = var script =
" function collisionWithVoxel(voxel) { " + " function collisionWithVoxel(voxel) { " +
" print('collisionWithVoxel(voxel)... '); " + " print('collisionWithVoxel(voxel)... '); " +
" print('myID=' + Particle.getID() + '\\n'); " + " print('myID=' + Particle.getID() + '\\n'); " +
@ -96,17 +96,17 @@ function checkController() {
" Particle.setColor(voxelColor); " + " Particle.setColor(voxelColor); " +
" var voxelAt = voxel.getPosition();" + " var voxelAt = voxel.getPosition();" +
" var voxelScale = voxel.getScale();" + " var voxelScale = voxel.getScale();" +
" Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " + " Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " +
" print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " + " print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " +
" } " + " } " +
" Particle.collisionWithVoxel.connect(collisionWithVoxel); "; " Particle.collisionWithVoxel.connect(collisionWithVoxel); ";
Particles.queueParticleAdd(position, bulletSize, color, velocity, gravity, damping, inHand, script); Particles.queueParticleAdd(position, bulletSize, color, velocity, gravity, damping, inHand, script);
} }
} }
} }
} }
// register the call back so it fires before each data send // register the call back so it fires before each data send
Agent.willSendVisualDataCallback.connect(checkController); Agent.willSendVisualDataCallback.connect(checkController);

View file

@ -1561,8 +1561,8 @@ void Application::shootParticle() {
" Particle.setColor(voxelColor); " " Particle.setColor(voxelColor); "
" var voxelAt = voxel.getPosition();" " var voxelAt = voxel.getPosition();"
" var voxelScale = voxel.getScale();" " var voxelScale = voxel.getScale();"
" Voxels.queueVoxelDelete(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); " " Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); "
" print('Voxels.queueVoxelDelete(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " " print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); "
" } " " } "
" Particle.collisionWithVoxel.connect(collisionWithVoxel); " ); " Particle.collisionWithVoxel.connect(collisionWithVoxel); " );

View file

@ -145,7 +145,6 @@ void ScriptEngine::evaluate() {
} }
QScriptValue result = _engine.evaluate(_scriptContents); QScriptValue result = _engine.evaluate(_scriptContents);
qDebug() << "Evaluated script.\n";
if (_engine.hasUncaughtException()) { if (_engine.hasUncaughtException()) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
@ -160,7 +159,6 @@ void ScriptEngine::run() {
_isRunning = true; _isRunning = true;
QScriptValue result = _engine.evaluate(_scriptContents); QScriptValue result = _engine.evaluate(_scriptContents);
qDebug() << "Evaluated script.\n";
if (_engine.hasUncaughtException()) { if (_engine.hasUncaughtException()) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();

View file

@ -12,28 +12,28 @@ void VoxelsScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDet
getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails); 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 // setup a VoxelDetail struct with the data
VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue};
// queue the packet // queue the packet
queueVoxelAdd(PACKET_TYPE_VOXEL_SET, addVoxelDetail); 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) { uchar red, uchar green, uchar blue) {
// setup a VoxelDetail struct with the data // setup a VoxelDetail struct with the data
VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue};
// queue the destructive add // queue the destructive add
queueVoxelAdd(PACKET_TYPE_VOXEL_SET_DESTRUCTIVE, addVoxelDetail); 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 // setup a VoxelDetail struct with data
VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0}; VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0};
getVoxelPacketSender()->queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail); getVoxelPacketSender()->queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail);
} }

View file

@ -33,8 +33,8 @@ public slots:
/// \param red the R value for RGB color of voxel /// \param red the R value for RGB color of voxel
/// \param green the G 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 /// \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 /// 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 x the x-coordinate of the voxel (in VS space)
/// \param y the y-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 red the R value for RGB color of voxel
/// \param green the G 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 /// \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 /// 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 x the x-coordinate of the voxel (in VS space)
/// \param y the y-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 z the z-coordinate of the voxel (in VS space)
/// \param scale the scale 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: private:
void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails); void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails);