From 305e34e834ab03e750be6e7499784b520dd5fcc5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 20:18:45 -0800 Subject: [PATCH 1/8] more tweaks to particles with models rendering to make space invaders work --- interface/src/ParticleTreeRenderer.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index 7ba714ae93..7a1991ca93 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -84,12 +84,11 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg const float alpha = 1.0f; Model* model = getModel(particle.getModelURL()); - - glm::vec3 translationAdjustment = particle.getModelTranslation(); - + glm::vec3 translationAdjustment = particle.getModelTranslation() * radius; + // set the position - glm::vec3 translation(position.x, position.y, position.z); - model->setTranslation(translation + translationAdjustment); + glm::vec3 translation = position + translationAdjustment; + model->setTranslation(translation); // set the rotation glm::quat rotation = particle.getModelRotation(); @@ -100,14 +99,20 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg const float MODEL_SCALE = 0.00575f; glm::vec3 scale(1.0f,1.0f,1.0f); - // TODO: There is some kind of a bug in packing of the particle packets which is causing modelscale to - // sometimes be garbage. - float modelScale = 2.0f; /// particle.getModelScale() + float modelScale = particle.getModelScale(); model->setScale(scale * MODEL_SCALE * radius * modelScale); model->simulate(0.0f); model->render(alpha); // TODO: should we allow particles to have alpha on their models? + const bool wantDebugSphere = false; + if (wantDebugSphere) { + glPushMatrix(); + glTranslatef(position.x, position.y, position.z); + glutWireSphere(radius, 15, 15); + glPopMatrix(); + } + glPopMatrix(); } else { glPushMatrix(); From a35e5eeb92725602ad2ca1608531fb811d512780 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 20:20:06 -0800 Subject: [PATCH 2/8] move modelScale before translation and rotation since that seems to fix the corruption --- libraries/particles/src/Particle.cpp | 103 ++++++++++++++------------- libraries/particles/src/Particle.h | 14 ++-- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index 12b59d28c9..69ad2c03fc 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -190,6 +190,12 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const { success = packetData->appendRawData((const unsigned char*)qPrintable(_modelURL), modelURLLength); } } + + // modelScale + if (success) { + success = packetData->appendValue(getModelScale()); + } + // modelTranslation if (success) { success = packetData->appendValue(getModelTranslation()); @@ -198,11 +204,6 @@ bool Particle::appendParticleData(OctreePacketData* packetData) const { if (success) { success = packetData->appendValue(getModelRotation()); } - // modelScale - if (success) { - success = packetData->appendValue(getModelScale()); - } - return success; } @@ -319,6 +320,11 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef dataAt += modelURLLength; bytesRead += modelURLLength; + // modelScale + memcpy(&_modelScale, dataAt, sizeof(_modelScale)); + dataAt += sizeof(_modelScale); + bytesRead += sizeof(_modelScale); + // modelTranslation memcpy(&_modelTranslation, dataAt, sizeof(_modelTranslation)); dataAt += sizeof(_modelTranslation); @@ -329,11 +335,6 @@ int Particle::readParticleDataFromBuffer(const unsigned char* data, int bytesLef dataAt += bytes; bytesRead += bytes; - // modelScale - memcpy(&_modelScale, dataAt, sizeof(_modelScale)); - dataAt += sizeof(_modelScale); - bytesRead += sizeof(_modelScale); - //printf("Particle::readParticleDataFromBuffer()... "); debugDump(); } return bytesRead; @@ -498,6 +499,13 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr processedBytes += modelURLLength; } + // modelScale + if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) { + memcpy(&newParticle._modelScale, dataAt, sizeof(newParticle._modelScale)); + dataAt += sizeof(newParticle._modelScale); + processedBytes += sizeof(newParticle._modelScale); + } + // modelTranslation if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_TRANSLATION) == CONTAINS_MODEL_TRANSLATION)) { memcpy(&newParticle._modelTranslation, dataAt, sizeof(newParticle._modelTranslation)); @@ -512,13 +520,6 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr processedBytes += bytes; } - // modelScale - if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) { - memcpy(&newParticle._modelScale, dataAt, sizeof(newParticle._modelScale)); - dataAt += sizeof(newParticle._modelScale); - processedBytes += sizeof(newParticle._modelScale); - } - const bool wantDebugging = false; if (wantDebugging) { qDebug("Particle::fromEditPacket()..."); @@ -696,6 +697,14 @@ bool Particle::encodeParticleEditMessageDetails(PacketType command, ParticleID i sizeOut += urlLength; } + // modelScale + if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) { + float modelScale = properties.getModelScale(); + memcpy(copyAt, &modelScale, sizeof(modelScale)); + copyAt += sizeof(modelScale); + sizeOut += sizeof(modelScale); + } + // modelTranslation if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_TRANSLATION) == CONTAINS_MODEL_TRANSLATION)) { glm::vec3 modelTranslation = properties.getModelTranslation(); // should this be relative to TREE_SCALE?? @@ -711,14 +720,6 @@ bool Particle::encodeParticleEditMessageDetails(PacketType command, ParticleID i sizeOut += bytes; } - // modelScale - if (isNewParticle || ((packetContainsBits & CONTAINS_MODEL_SCALE) == CONTAINS_MODEL_SCALE)) { - float modelScale = properties.getModelScale(); - memcpy(copyAt, &modelScale, sizeof(modelScale)); - copyAt += sizeof(modelScale); - sizeOut += sizeof(modelScale); - } - bool wantDebugging = false; if (wantDebugging) { printf("encodeParticleEditMessageDetails()....\n"); @@ -931,9 +932,9 @@ ParticleProperties::ParticleProperties() : _inHand(false), _shouldDie(false), _modelURL(""), + _modelScale(DEFAULT_MODEL_SCALE), _modelTranslation(DEFAULT_MODEL_TRANSLATION), _modelRotation(DEFAULT_MODEL_ROTATION), - _modelScale(DEFAULT_MODEL_SCALE), _id(UNKNOWN_PARTICLE_ID), _idSet(false), @@ -950,9 +951,9 @@ ParticleProperties::ParticleProperties() : _inHandChanged(false), _shouldDieChanged(false), _modelURLChanged(false), + _modelScaleChanged(false), _modelTranslationChanged(false), _modelRotationChanged(false), - _modelScaleChanged(false), _defaultSettings(true) { } @@ -1004,6 +1005,10 @@ uint16_t ParticleProperties::getChangedBits() const { changedBits += CONTAINS_MODEL_URL; } + if (_modelScaleChanged) { + changedBits += CONTAINS_MODEL_SCALE; + } + if (_modelTranslationChanged) { changedBits += CONTAINS_MODEL_TRANSLATION; } @@ -1012,10 +1017,6 @@ uint16_t ParticleProperties::getChangedBits() const { changedBits += CONTAINS_MODEL_ROTATION; } - if (_modelScaleChanged) { - changedBits += CONTAINS_MODEL_SCALE; - } - return changedBits; } @@ -1045,14 +1046,14 @@ QScriptValue ParticleProperties::copyToScriptValue(QScriptEngine* engine) const properties.setProperty("modelURL", _modelURL); + properties.setProperty("modelScale", _modelScale); + QScriptValue modelTranslation = vec3toScriptValue(engine, _modelTranslation); properties.setProperty("modelTranslation", modelTranslation); QScriptValue modelRotation = quatToScriptValue(engine, _modelRotation); properties.setProperty("modelRotation", modelRotation); - properties.setProperty("modelScale", _modelScale); - if (_idSet) { properties.setProperty("id", _id); @@ -1203,7 +1204,17 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { _modelURLChanged = true; } } - + + QScriptValue modelScale = object.property("modelScale"); + if (modelScale.isValid()) { + float newModelScale; + newModelScale = modelScale.toVariant().toFloat(); + if (_defaultSettings || newModelScale != _modelScale) { + _modelScale = newModelScale; + _modelScaleChanged = true; + } + } + QScriptValue modelTranslation = object.property("modelTranslation"); if (modelTranslation.isValid()) { QScriptValue x = modelTranslation.property("x"); @@ -1241,16 +1252,6 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { } } - QScriptValue modelScale = object.property("modelScale"); - if (modelScale.isValid()) { - float newModelScale; - newModelScale = modelScale.toVariant().toFloat(); - if (_defaultSettings || newModelScale != _modelScale) { - _modelScale = newModelScale; - _modelScaleChanged = true; - } - } - _lastEdited = usecTimestampNow(); } @@ -1310,6 +1311,11 @@ void ParticleProperties::copyToParticle(Particle& particle) const { particle.setModelURL(_modelURL); somethingChanged = true; } + + if (_modelScaleChanged) { + particle.setModelScale(_modelScale); + somethingChanged = true; + } if (_modelTranslationChanged) { particle.setModelTranslation(_modelTranslation); @@ -1321,11 +1327,6 @@ void ParticleProperties::copyToParticle(Particle& particle) const { somethingChanged = true; } - if (_modelScaleChanged) { - particle.setModelScale(_modelScale); - somethingChanged = true; - } - if (somethingChanged) { bool wantDebug = false; if (wantDebug) { @@ -1350,9 +1351,9 @@ void ParticleProperties::copyFromParticle(const Particle& particle) { _inHand = particle.getInHand(); _shouldDie = particle.getShouldDie(); _modelURL = particle.getModelURL(); + _modelScale = particle.getModelScale(); _modelTranslation = particle.getModelTranslation(); _modelRotation = particle.getModelRotation(); - _modelScale = particle.getModelScale(); _id = particle.getID(); _idSet = true; @@ -1368,9 +1369,9 @@ void ParticleProperties::copyFromParticle(const Particle& particle) { _inHandChanged = false; _shouldDieChanged = false; _modelURLChanged = false; + _modelScaleChanged = false; _modelTranslationChanged = false; _modelRotationChanged = false; - _modelScaleChanged = false; _defaultSettings = false; } diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index 925227055f..6d22e75810 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -88,9 +88,9 @@ public: bool getInHand() const { return _inHand; } bool getShouldDie() const { return _shouldDie; } const QString& getModelURL() const { return _modelURL; } + float getModelScale() const { return _modelScale; } const glm::vec3& getModelTranslation() const { return _modelTranslation; } const glm::quat& getModelRotation() const { return _modelRotation; } - float getModelScale() const { return _modelScale; } quint64 getLastEdited() const { return _lastEdited; } uint16_t getChangedBits() const; @@ -113,10 +113,10 @@ public: // model related properties void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; } + void setModelScale(float scale) { _modelScale = scale; _modelScaleChanged = true; } void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation; _modelTranslationChanged = true; } void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; _modelRotationChanged = true; } - void setModelScale(float scale) { _modelScale = scale; _modelScaleChanged = true; } /// used by ParticleScriptingInterface to return ParticleProperties for unknown particles void setIsUnknownID() { _id = UNKNOWN_PARTICLE_ID; _idSet = true; } @@ -133,9 +133,9 @@ private: bool _inHand; bool _shouldDie; QString _modelURL; + float _modelScale; glm::vec3 _modelTranslation; glm::quat _modelRotation; - float _modelScale; uint32_t _id; bool _idSet; @@ -152,9 +152,9 @@ private: bool _inHandChanged; bool _shouldDieChanged; bool _modelURLChanged; + bool _modelScaleChanged; bool _modelTranslationChanged; bool _modelRotationChanged; - bool _modelScaleChanged; bool _defaultSettings; }; Q_DECLARE_METATYPE(ParticleProperties); @@ -227,9 +227,9 @@ public: // model related properties bool hasModel() const { return !_modelURL.isEmpty(); } const QString& getModelURL() const { return _modelURL; } + float getModelScale() const { return _modelScale; } const glm::vec3& getModelTranslation() const { return _modelTranslation; } const glm::quat& getModelRotation() const { return _modelRotation; } - float getModelScale() const { return _modelScale; } ParticleID getParticleID() const { return ParticleID(getID(), getCreatorTokenID(), getID() != UNKNOWN_PARTICLE_ID); } ParticleProperties getProperties() const; @@ -277,9 +277,9 @@ public: // model related properties void setModelURL(const QString& url) { _modelURL = url; } + void setModelScale(float scale) { _modelScale = scale; } void setModelTranslation(const glm::vec3& translation) { _modelTranslation = translation; } void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; } - void setModelScale(float scale) { _modelScale = scale; } void setProperties(const ParticleProperties& properties); @@ -344,9 +344,9 @@ protected: // model related items QString _modelURL; + float _modelScale; glm::vec3 _modelTranslation; glm::quat _modelRotation; - float _modelScale; uint32_t _creatorTokenID; bool _newlyCreated; From 13d9b710f1ce422064ad14dc6082121c7412ab1f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 20:23:12 -0800 Subject: [PATCH 3/8] bump packet version --- libraries/shared/src/PacketHeaders.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 3fd51949f9..67b534bc34 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -44,6 +44,8 @@ int packArithmeticallyCodedValue(int value, char* destination) { PacketVersion versionForPacketType(PacketType type) { switch (type) { + case PacketTypeParticleData: + return 1; default: return 0; } From 2f14b265a8d289a4252b9513cf503ef96881433c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 20:24:08 -0800 Subject: [PATCH 4/8] make sure SVO files with version details are supported --- interface/src/renderer/FBXReader.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index e2c3bfafdd..5a27b51b70 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -1632,7 +1632,18 @@ FBXGeometry readSVO(const QByteArray& model) { VoxelTree tree; ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS); - tree.readBitstreamToTree((unsigned char*)model.data(), model.size(), args); + + unsigned char* dataAt = (unsigned char*)model.data(); + size_t dataSize = model.size(); + + if (tree.getWantSVOfileVersions()) { + // skip the type/version + dataAt += sizeof(PacketType); + dataSize -= sizeof(PacketType); + dataAt += sizeof(PacketVersion); + dataSize -= sizeof(PacketVersion); + } + tree.readBitstreamToTree(dataAt, dataSize, args); tree.recurseTreeWithOperation(addMeshVoxelsOperation, &mesh); geometry.meshes.append(mesh); From 758c1e0817e167aa6298b53375bba552e1ef6c39 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 20:28:11 -0800 Subject: [PATCH 5/8] add examples for setting model scale and translation --- examples/particleModelExample.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/particleModelExample.js b/examples/particleModelExample.js index e95cc0c2bf..2f36445d1a 100644 --- a/examples/particleModelExample.js +++ b/examples/particleModelExample.js @@ -11,7 +11,7 @@ var count = 0; var stopAfter = 100; -var modelProperties = { +var modelPropertiesA = { position: { x: 1, y: 1, z: 1 }, velocity: { x: 0.5, y: 0, z: 0.5 }, gravity: { x: 0, y: 0, z: 0 }, @@ -21,6 +21,18 @@ var modelProperties = { lifetime: 20 }; +var modelPropertiesB = { + position: { x: 1, y: 1.5, z: 1 }, + velocity: { x: 0.5, y: 0, z: 0.5 }, + gravity: { x: 0, y: 0, z: 0 }, + damping: 0, + radius : 0.25, + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + lifetime: 20 +}; + var ballProperties = { position: { x: 1, y: 0.5, z: 1 }, velocity: { x: 0.5, y: 0, z: 0.5 }, @@ -31,7 +43,8 @@ var ballProperties = { lifetime: 20 }; -var modelParticleID = Particles.addParticle(modelProperties); +var modelAParticleID = Particles.addParticle(modelPropertiesA); +var modelBParticleID = Particles.addParticle(modelPropertiesB); var ballParticleID = Particles.addParticle(ballProperties); function endAfterAWhile() { From 15be49cb8d55d70950c8dbef8b1dd6bfe7d541c0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 21:08:12 -0800 Subject: [PATCH 6/8] latest changes to space invaders --- examples/spaceInvadersExample.js | 98 ++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 6c8473b4d7..cff8aded74 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -17,7 +17,8 @@ var invaderStepsPerCycle = 120; // the number of update steps it takes then inva var invaderStepOfCycle = 0; // current iteration in the cycle var invaderMoveDirection = 1; // 1 for moving to right, -1 for moving to left -var itemLifetimes = 60 * 2; // 2 minutes +// game length... +var itemLifetimes = 60; // 1 minute // position the game to be basically near the avatar running the game... @@ -51,7 +52,8 @@ var gameAt = { x: gameAtX, y: gameAtY, z: gameAtZ }; var middleX = gameAt.x + (gameSize.x/2); var middleY = gameAt.y + (gameSize.y/2); -var shipSize = 0.2; +var invaderSize = 0.4; +var shipSize = 0.25; var missileSize = 0.1; var myShip; var myShipProperties; @@ -88,16 +90,54 @@ var currentMoveSound = 0; var numberOfSounds = 4; var stepsPerSound = invaderStepsPerCycle / numberOfSounds; +// if you set this to false, sounds will come from the location of particles instead of the player's head +var soundInMyHead = true; + +// models... +var invaderModels = new Array(); +invaderModels[0] = { + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16-large-purple.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + }; +invaderModels[1] = { + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16-large-cyan.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + }; +invaderModels[2] = { + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16-medium-cyan.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + }; +invaderModels[3] = { + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16-medium-green.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + }; +invaderModels[4] = { + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/newInvader16x16-small-green.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, + }; + + + +//modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX", +//modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/invader.svo", +// "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/spaceInvader3.fbx" + function initializeMyShip() { myShipProperties = { - position: { x: middleX , y: gameAt.y, z: gameAt.z }, - velocity: { x: 0, y: 0, z: 0 }, - gravity: { x: 0, y: 0, z: 0 }, - damping: 0, - radius: shipSize, - color: { red: 0, green: 255, blue: 0 }, - lifetime: itemLifetimes - }; + position: { x: middleX , y: gameAt.y, z: gameAt.z }, + velocity: { x: 0, y: 0, z: 0 }, + gravity: { x: 0, y: 0, z: 0 }, + damping: 0, + radius: shipSize, + color: { red: 0, green: 255, blue: 0 }, + //modelURL: myShipModel, + lifetime: itemLifetimes + }; myShip = Particles.addParticle(myShipProperties); } @@ -131,9 +171,11 @@ function initializeInvaders() { velocity: { x: 0, y: 0, z: 0 }, gravity: { x: 0, y: 0, z: 0 }, damping: 0, - radius: shipSize, + radius: invaderSize, color: { red: 255, green: 0, blue: 0 }, - modelURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX", + modelURL: invaderModels[row].modelURL, + modelScale: invaderModels[row].modelScale, + modelTranslation: invaderModels[row].modelTranslation, lifetime: itemLifetimes }); @@ -171,8 +213,15 @@ function update() { if (invaderStepOfCycle % stepsPerSound == 0) { // play the move sound var options = new AudioInjectionOptions();
 - options.position = getInvaderPosition(invadersPerRow / 2, numberOfRows / 2); - options.volume = 10.0; + if (soundInMyHead) { + options.position = { x: MyAvatar.position.x + 0.0, + y: MyAvatar.position.y + 0.1, + z: MyAvatar.position.z + 0.0 }; + } else { + options.position = getInvaderPosition(invadersPerRow / 2, numberOfRows / 2); + } + print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); + options.volume = 1.0; Audio.playSound(moveSounds[currentMoveSound], options); // get ready for next move sound @@ -274,7 +323,14 @@ function fireMissile() { }); var options = new AudioInjectionOptions();
 - options.position = missilePosition; + if (soundInMyHead) { + options.position = { x: MyAvatar.position.x + 0.0, + y: MyAvatar.position.y + 0.1, + z: MyAvatar.position.z + 0.0 }; + } else { + options.position = missilePosition; + } + print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); options.volume = 1.0; Audio.playSound(shootSound, options); @@ -318,8 +374,14 @@ function deleteIfInvader(possibleInvaderParticle) { // play the hit sound var options = new AudioInjectionOptions();
 - var invaderPosition = getInvaderPosition(row, column); - options.position = invaderPosition; + if (soundInMyHead) { + options.position = { x: MyAvatar.position.x + 0.0, + y: MyAvatar.position.y + 0.1, + z: MyAvatar.position.z + 0.0 }; + } else { + options.position = getInvaderPosition(row, column); + } + print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); options.volume = 1.0; Audio.playSound(hitSound, options); } @@ -346,4 +408,6 @@ Particles.particleCollisionWithParticle.connect(particleCollisionWithParticle); initializeMyShip(); initializeInvaders(); +// shut down the game after 1 minute +var gameTimer = Script.setTimeout(endGame, itemLifetimes * 1000); From 7ffe73bf6eaf0c919abe08d2001319b81555003c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 21:14:49 -0800 Subject: [PATCH 7/8] added the cannon as voxels --- examples/spaceInvadersExample.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index cff8aded74..6e21b6be30 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -135,7 +135,9 @@ function initializeMyShip() { damping: 0, radius: shipSize, color: { red: 0, green: 255, blue: 0 }, - //modelURL: myShipModel, + modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/myCannon16x16.svo", + modelScale: 450, + modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, lifetime: itemLifetimes }; myShip = Particles.addParticle(myShipProperties); From 5afe184c3bbfdc746077be203ff9d956e50556ab Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Feb 2014 21:16:07 -0800 Subject: [PATCH 8/8] removed debug --- examples/spaceInvadersExample.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 6e21b6be30..79e6837f21 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -222,7 +222,6 @@ function update() { } else { options.position = getInvaderPosition(invadersPerRow / 2, numberOfRows / 2); } - print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); options.volume = 1.0; Audio.playSound(moveSounds[currentMoveSound], options); @@ -332,7 +331,6 @@ function fireMissile() { } else { options.position = missilePosition; } - print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); options.volume = 1.0; Audio.playSound(shootSound, options); @@ -383,7 +381,6 @@ function deleteIfInvader(possibleInvaderParticle) { } else { options.position = getInvaderPosition(row, column); } - print("options.position=" + options.position.x + ", " + options.position.y + ", " + options.position.z ); options.volume = 1.0; Audio.playSound(hitSound, options); }