more Particles to Entities migration

This commit is contained in:
ZappoMan 2014-10-16 21:13:34 -07:00
parent 7ca4c95d4a
commit c5c44e7cec

View file

@ -129,7 +129,7 @@ function Hand(name, palm, tip, forwardButton, button3, trigger) {
this.button3 = button3; this.button3 = button3;
this.trigger = trigger; this.trigger = trigger;
this.holdingFrisbee = false; this.holdingFrisbee = false;
this.particle = false; this.entity = false;
this.palmPosition = function() { return Controller.getSpatialControlPosition(this.palm); } this.palmPosition = function() { return Controller.getSpatialControlPosition(this.palm); }
this.grabButtonPressed = function() { this.grabButtonPressed = function() {
return ( return (
@ -185,28 +185,29 @@ function playSound(sound, position) {
function cleanupFrisbees() { function cleanupFrisbees() {
simulatedFrisbees = []; simulatedFrisbees = [];
var particles = Particles.findParticles(MyAvatar.position, 1000); var entities = Entities.findEntities(MyAvatar.position, 1000);
for (particle in particles) { for (entity in entities) {
Particles.deleteParticle(particles[particle]); Entities.deleteEntity(entities[entity]);
} }
} }
function checkControllerSide(hand) { function checkControllerSide(hand) {
// If I don't currently have a frisbee in my hand, then try to catch closest one // If I don't currently have a frisbee in my hand, then try to catch closest one
if (!hand.holdingFrisbee && hand.grabButtonPressed()) { if (!hand.holdingFrisbee && hand.grabButtonPressed()) {
var closestParticle = Particles.findClosestParticle(hand.palmPosition(), CATCH_RADIUS); var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS);
var modelUrl = Particles.getParticleProperties(closestParticle).modelURL; var modelUrl = Entities.getEntityProperties(closestEntity).modelURL;
if (closestParticle.isKnownID && validFrisbeeURL(Particles.getParticleProperties(closestParticle).modelURL)) { if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) {
Particles.editParticle(closestParticle, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true}); Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true});
Particles.deleteParticle(closestParticle); Entities.deleteEntity(closestEntity);
debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!"); debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!");
var properties = { var properties = {
type: "Model",
position: hand.holdPosition(), position: hand.holdPosition(),
velocity: { x: 0, y: 0, z: 0}, velocity: { x: 0, y: 0, z: 0},
gravity: { x: 0, y: 0, z: 0}, gravity: { x: 0, y: 0, z: 0},
inHand: true, inHand: true,
radius: FRISBEE_RADIUS, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS },
damping: 0.999, damping: 0.999,
modelURL: modelUrl, modelURL: modelUrl,
modelScale: FRISBEE_MODEL_SCALE, modelScale: FRISBEE_MODEL_SCALE,
@ -214,10 +215,10 @@ function checkControllerSide(hand) {
lifetime: FRISBEE_LIFETIME lifetime: FRISBEE_LIFETIME
}; };
newParticle = Particles.addParticle(properties); newEntity = Entities.addEntity(properties);
hand.holdingFrisbee = true; hand.holdingFrisbee = true;
hand.particle = newParticle; hand.entity = newEntity;
playSound(catchSound, hand.holdPosition()); playSound(catchSound, hand.holdPosition());
@ -228,11 +229,12 @@ function checkControllerSide(hand) {
// If '3' is pressed, and not holding a frisbee, make a new one // If '3' is pressed, and not holding a frisbee, make a new one
if (hand.grabButtonPressed() && !hand.holdingFrisbee && newfrisbeeEnabled) { if (hand.grabButtonPressed() && !hand.holdingFrisbee && newfrisbeeEnabled) {
var properties = { var properties = {
type: "Model",
position: hand.holdPosition(), position: hand.holdPosition(),
velocity: { x: 0, y: 0, z: 0}, velocity: { x: 0, y: 0, z: 0},
gravity: { x: 0, y: 0, z: 0}, gravity: { x: 0, y: 0, z: 0},
inHand: true, inHand: true,
radius: FRISBEE_RADIUS, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS },
damping: 0.999, damping: 0.999,
modelURL: frisbeeURL(), modelURL: frisbeeURL(),
modelScale: FRISBEE_MODEL_SCALE, modelScale: FRISBEE_MODEL_SCALE,
@ -240,9 +242,9 @@ function checkControllerSide(hand) {
lifetime: FRISBEE_LIFETIME lifetime: FRISBEE_LIFETIME
}; };
newParticle = Particles.addParticle(properties); newEntity = Entities.addEntity(properties);
hand.holdingFrisbee = true; hand.holdingFrisbee = true;
hand.particle = newParticle; hand.entity = newEntity;
// Play a new frisbee sound // Play a new frisbee sound
playSound(newSound, hand.holdPosition()); playSound(newSound, hand.holdPosition());
@ -258,7 +260,7 @@ function checkControllerSide(hand) {
position: hand.holdPosition(), position: hand.holdPosition(),
modelRotation: hand.holdRotation() modelRotation: hand.holdRotation()
}; };
Particles.editParticle(hand.particle, properties); Entities.editEntity(hand.entity, properties);
} else { } else {
debugPrint(">>>>> " + hand.name + "-FRISBEE IN HAND, not grabbing, THROW!!!"); debugPrint(">>>>> " + hand.name + "-FRISBEE IN HAND, not grabbing, THROW!!!");
// If frisbee just released, add velocity to it! // If frisbee just released, add velocity to it!
@ -271,12 +273,12 @@ function checkControllerSide(hand) {
modelRotation: hand.holdRotation() modelRotation: hand.holdRotation()
}; };
Particles.editParticle(hand.particle, properties); Entities.editEntity(hand.entity, properties);
simulatedFrisbees.push(hand.particle); simulatedFrisbees.push(hand.entity);
hand.holdingFrisbee = false; hand.holdingFrisbee = false;
hand.particle = false; hand.entity = false;
playSound(throwSound, hand.holdPosition()); playSound(throwSound, hand.holdPosition());
} }
@ -323,7 +325,7 @@ function checkController(deltaTime) {
function controlFrisbees(deltaTime) { function controlFrisbees(deltaTime) {
var killSimulations = []; var killSimulations = [];
for (frisbee in simulatedFrisbees) { for (frisbee in simulatedFrisbees) {
var properties = Particles.getParticleProperties(simulatedFrisbees[frisbee]); var properties = Entities.getEntityProperties(simulatedFrisbees[frisbee]);
//get the horizon length from the velocity origin in order to get speed //get the horizon length from the velocity origin in order to get speed
var speed = Vec3.length({x:properties.velocity.x, y:0, z:properties.velocity.z}); var speed = Vec3.length({x:properties.velocity.x, y:0, z:properties.velocity.z});
if (speed < MIN_SIMULATION_SPEED) { if (speed < MIN_SIMULATION_SPEED) {
@ -331,7 +333,7 @@ function controlFrisbees(deltaTime) {
killSimulations.push(frisbee); killSimulations.push(frisbee);
continue; continue;
} }
Particles.editParticle(simulatedFrisbees[frisbee], {modelRotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))}); Entities.editEntity(simulatedFrisbees[frisbee], {modelRotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))});
} }
for (var i = killSimulations.length - 1; i >= 0; i--) { for (var i = killSimulations.length - 1; i >= 0; i--) {