flowers spawning and growing correctly

This commit is contained in:
ericrius1 2016-03-04 17:32:29 -08:00
parent ef437b7f99
commit 3ad2d1aa9b
3 changed files with 29 additions and 10 deletions

View file

@ -19,7 +19,11 @@
_this = this; _this = this;
_this.flowers = []; _this.flowers = [];
// _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1}
_this.STARTING_FLOWER_DIMENSIONS = {x: 0.2, y: 0.01, z: 0.2} _this.STARTING_FLOWER_DIMENSIONS = {
x: 0.1,
y: 0.01,
z: 0.1
}
}; };
@ -35,7 +39,7 @@
_this.createFlower(data.position, data.surfaceNormal); _this.createFlower(data.position, data.surfaceNormal);
} }
_this.flowers.forEach( function(flower) { _this.flowers.forEach(function(flower) {
flower.grow(); flower.grow();
}); });
@ -44,23 +48,37 @@
createFlower: function(position, surfaceNormal) { createFlower: function(position, surfaceNormal) {
var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal);
print("flower rotation " + flowerRotation.x)
var flowerEntityID = Entities.addEntity({ var flowerEntityID = Entities.addEntity({
type: "Sphere", type: "Sphere",
name: "flower", name: "flower",
position: position, position: position,
collisionless: true,
rotation: flowerRotation, rotation: flowerRotation,
dimensions: _this.STARTING_FLOWER_DIMENSIONS, dimensions: _this.STARTING_FLOWER_DIMENSIONS,
userData: JSON.stringify(_this.flowerUserData) userData: JSON.stringify(_this.flowerUserData)
}); });
var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS, startingPosition: position, rotation: flowerRotation}; var flower = {
id: flowerEntityID,
dimensions: {x: _this.STARTING_FLOWER_DIMENSIONS.x, y: _this.STARTING_FLOWER_DIMENSIONS.y, z: _this.STARTING_FLOWER_DIMENSIONS.z},
startingPosition: position,
rotation: flowerRotation,
maxYDimension: randFloat(0.2, 1.5),
growthRate: randFloat(0.0001, 0.001)
};
print(_this.STARTING_FLOWER_DIMENSIONS.y)
flower.grow = function() { flower.grow = function() {
// grow flower a bit // grow flower a bit
flower.dimensions.y += 0.001; if (flower.dimensions.y > flower.maxYDimension) {
flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y/2)); return;
}
flower.dimensions.y += flower.growthRate;
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! //As we grow we must also move ourselves in direction we grow!
Entities.editEntity(flower.id, {dimensions: flower.dimensions, position: flower.position}); Entities.editEntity(flower.id, {
dimensions: flower.dimensions,
position: flower.position
});
} }
_this.flowers.push(flower); _this.flowers.push(flower);
}, },

View file

@ -49,6 +49,7 @@ var waterCanRotation = orientation;
var waterCan = Entities.addEntity({ var waterCan = Entities.addEntity({
type: "Model", type: "Model",
shapeType: 'box', shapeType: 'box',
name: "hifi-water-can",
modelURL: WATER_CAN_MODEL_URL, modelURL: WATER_CAN_MODEL_URL,
script: WATER_CAN_SCRIPT_URL, script: WATER_CAN_SCRIPT_URL,
dimensions: {x: 0.1859, y: 0.2762, z: 0.4115}, dimensions: {x: 0.1859, y: 0.2762, z: 0.4115},

View file

@ -165,7 +165,7 @@
green: 10, green: 10,
blue: 200 blue: 200
}, },
lineWidth: 1, lineWidth: 2,
alpha: 1, alpha: 1,
visible: true, visible: true,
ignoreRayIntersection: true ignoreRayIntersection: true