flowers staying in place

This commit is contained in:
ericrius1 2016-03-04 16:48:55 -08:00
parent 17dec9446a
commit ef437b7f99

View file

@ -19,7 +19,7 @@
_this = this;
_this.flowers = [];
// _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1}
_this.STARTING_FLOWER_DIMENSIONS = {x: 0.01, y: 0.01, z: 0.02}
_this.STARTING_FLOWER_DIMENSIONS = {x: 0.2, y: 0.01, z: 0.2}
};
@ -30,7 +30,7 @@
// we're being watered- every now and then spawn a new flower to add to our growing list
// If we don't have any flowers yet, immediately grow one
var data = JSON.parse(data[0]);
if (_this.flowers.length < 10) {
if (_this.flowers.length < 1000) {
_this.createFlower(data.position, data.surfaceNormal);
}
@ -43,7 +43,7 @@
},
createFlower: function(position, surfaceNormal) {
var flowerRotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, surfaceNormal);
var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal);
print("flower rotation " + flowerRotation.x)
var flowerEntityID = Entities.addEntity({
type: "Sphere",
@ -51,14 +51,16 @@
position: position,
rotation: flowerRotation,
dimensions: _this.STARTING_FLOWER_DIMENSIONS,
// userData: JSON.stringify(_this.flowerUserData)
userData: JSON.stringify(_this.flowerUserData)
});
var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS};
var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS, startingPosition: position, rotation: flowerRotation};
flower.grow = function() {
// grow flower a bit
flower.dimensions.z += 0.0001;
Entities.editEntity(flower.id, {dimensions: flower.dimensions});
flower.dimensions.y += 0.001;
flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y/2));
//As we grow we must also move ourselves in direction we grow!
Entities.editEntity(flower.id, {dimensions: flower.dimensions, position: flower.position});
}
_this.flowers.push(flower);
},