mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:57:30 +02:00
ray casting works
This commit is contained in:
parent
def0df9bff
commit
cf891ef5d9
3 changed files with 11 additions and 94 deletions
|
@ -17,113 +17,27 @@
|
|||
var _this;
|
||||
GrowingPlant = function() {
|
||||
_this = this;
|
||||
_this.flowers = [];
|
||||
_this.delay = 1000;
|
||||
_this.MAX_CACTUS_Y_DIMENSION = 0.7;
|
||||
_this.GROW_RATE = 0.001;
|
||||
|
||||
};
|
||||
|
||||
GrowingPlant.prototype = {
|
||||
|
||||
|
||||
water: function() {
|
||||
_this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: _this.GROW_RATE, z: 0});
|
||||
|
||||
if (_this.cactusDimensions.y > _this.MAX_CACTUS_Y_DIMENSION) {
|
||||
// We don't want to grow our cactus any more than this or it will look bad
|
||||
return;
|
||||
}
|
||||
// Need to raise up cactus as it stretches so it doesnt burst out the bottom of the plant
|
||||
_this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement * 0.1, z: 0});
|
||||
Entities.editEntity(_this.cactus, {dimensions: _this.cactusDimensions, position: _this.cactusPosition});
|
||||
|
||||
_this.flowers.forEach(_this.waterFlower);
|
||||
},
|
||||
|
||||
waterFlower: function(flower) {
|
||||
var props = Entities.getEntityProperties(flower, ["position, dimensions"]);
|
||||
var newDimensions = Vec3.sum(props.dimensions, {x: randFloat(0, 0.0001), y: 0.001, z: randFloat(0, 0.0001)});
|
||||
var newPosition = Vec3.sum(props.position, {x: 0, y: _this.flowerHeightMovement * 0.55, z: 0});
|
||||
Entities.editEntity(flower, {dimensions: newDimensions, position: newPosition});
|
||||
},
|
||||
|
||||
createFlowers: function() {
|
||||
var size = 0.1;
|
||||
var NUM_FLOWERS = 20
|
||||
_this.startingFlowerDimensions = {
|
||||
x: size,
|
||||
y: 0.001,
|
||||
z: size
|
||||
};
|
||||
_this.flowerHeightMovement = _this.startingFlowerDimensions.y;
|
||||
for (var i = 0; i < NUM_FLOWERS; i++) {
|
||||
var segment = i / NUM_FLOWERS * Math.PI * 2;
|
||||
var radius = randFloat(0.13, 0.25);
|
||||
var position = Vec3.sum(_this.position, {
|
||||
x: radius * Math.cos(segment),
|
||||
y: 0.16,
|
||||
z: radius * Math.sin(segment)
|
||||
});
|
||||
_this.createFlower(position);
|
||||
}
|
||||
},
|
||||
|
||||
createFlower: function(position) {
|
||||
|
||||
var flowerUserData = {
|
||||
ProceduralEntity: {
|
||||
shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs",
|
||||
uniforms: {
|
||||
iBloomPct: randFloat(0.4, 0.8),
|
||||
hueTwerking: randFloat(10, 30)
|
||||
}
|
||||
}
|
||||
};
|
||||
var flower = Entities.addEntity({
|
||||
type: "Sphere",
|
||||
name: "flower",
|
||||
position: position,
|
||||
dimensions: _this.startingFlowerDimensions,
|
||||
userData: JSON.stringify(flowerUserData)
|
||||
});
|
||||
_this.flowers.push(flower);
|
||||
|
||||
},
|
||||
|
||||
createCactus: function() {
|
||||
var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/cactus.fbx"
|
||||
_this.cactusDimensions = {
|
||||
x: 0.09,
|
||||
y: 0.01,
|
||||
z: 0.09
|
||||
};
|
||||
_this.cactusHeightMovement = _this.cactusDimensions.y/2;
|
||||
_this.cactusPosition = _this.position;
|
||||
_this.cactus = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: MODEL_URL,
|
||||
name: "cactus",
|
||||
position: _this.cactusPosition,
|
||||
dimensions: _this.cactusDimensions
|
||||
});
|
||||
grow: function() {
|
||||
print(" I AM BEING GROWN RIGHT NOW")
|
||||
},
|
||||
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]);
|
||||
this.position = this.props.position;
|
||||
this.dimensions = this.props.dimensions;
|
||||
this.createCactus();
|
||||
this.createFlowers();
|
||||
_this.entityID = entityID;
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
unload: function() {
|
||||
Entities.deleteEntity(_this.cactus);
|
||||
_this.flowers.forEach(function(flower) {
|
||||
Entities.deleteEntity(flower);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -38,6 +38,7 @@ var plant = Entities.addEntity({
|
|||
name: "hifi-growable-plant",
|
||||
dimensions: plantDimensions,
|
||||
position: plantPosition,
|
||||
script: PLANT_SCRIPT_URL,
|
||||
parentID: bowl
|
||||
});
|
||||
|
||||
|
|
|
@ -78,8 +78,10 @@
|
|||
var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities);
|
||||
|
||||
if (intersection.intersects) {
|
||||
//We've intersected with a growable object, now
|
||||
print(intersection.properties.name)
|
||||
print("intersection with growable object");
|
||||
Entities.callEntityMethod(intersection.entityID, 'grow');
|
||||
}
|
||||
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue