mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 04:57:23 +02:00
more Particles to Entities migration
This commit is contained in:
parent
597bfa33b9
commit
aaa76f6071
2 changed files with 8 additions and 108 deletions
|
@ -1,101 +0,0 @@
|
||||||
//
|
|
||||||
// paintGun.js
|
|
||||||
// examples
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 12/31/13.
|
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
// initialize our triggers
|
|
||||||
var triggerPulled = new Array();
|
|
||||||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
|
||||||
for (t = 0; t < numberOfTriggers; t++) {
|
|
||||||
triggerPulled[t] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkController(deltaTime) {
|
|
||||||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
|
||||||
var numberOfSpatialControls = Controller.getNumberOfSpatialControls();
|
|
||||||
var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers;
|
|
||||||
|
|
||||||
// this is expected for hydras
|
|
||||||
if (numberOfTriggers == 2 && controllersPerTrigger == 2) {
|
|
||||||
for (var t = 0; t < numberOfTriggers; t++) {
|
|
||||||
var shootABullet = false;
|
|
||||||
var triggerValue = Controller.getTriggerValue(t);
|
|
||||||
|
|
||||||
if (triggerPulled[t]) {
|
|
||||||
// must release to at least 0.1
|
|
||||||
if (triggerValue < 0.1) {
|
|
||||||
triggerPulled[t] = false; // unpulled
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// must pull to at least 0.9
|
|
||||||
if (triggerValue > 0.9) {
|
|
||||||
triggerPulled[t] = true; // pulled
|
|
||||||
shootABullet = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shootABullet) {
|
|
||||||
var palmController = t * controllersPerTrigger;
|
|
||||||
var palmPosition = Controller.getSpatialControlPosition(palmController);
|
|
||||||
|
|
||||||
var fingerTipController = palmController + 1;
|
|
||||||
var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController);
|
|
||||||
|
|
||||||
var palmToFingerTipVector =
|
|
||||||
{ x: (fingerTipPosition.x - palmPosition.x),
|
|
||||||
y: (fingerTipPosition.y - palmPosition.y),
|
|
||||||
z: (fingerTipPosition.z - palmPosition.z) };
|
|
||||||
|
|
||||||
// just off the front of the finger tip
|
|
||||||
var position = { x: fingerTipPosition.x + palmToFingerTipVector.x/2,
|
|
||||||
y: fingerTipPosition.y + palmToFingerTipVector.y/2,
|
|
||||||
z: fingerTipPosition.z + palmToFingerTipVector.z/2};
|
|
||||||
|
|
||||||
var linearVelocity = 25;
|
|
||||||
|
|
||||||
var velocity = { x: palmToFingerTipVector.x * linearVelocity,
|
|
||||||
y: palmToFingerTipVector.y * linearVelocity,
|
|
||||||
z: palmToFingerTipVector.z * linearVelocity };
|
|
||||||
|
|
||||||
// This is the script for the particles that this gun shoots.
|
|
||||||
var script =
|
|
||||||
" function collisionWithVoxel(voxel, collision) { " +
|
|
||||||
" print('collisionWithVoxel(voxel)... '); " +
|
|
||||||
" Vec3.print('penetration=', collision.penetration); " +
|
|
||||||
" Vec3.print('contactPoint=', collision.contactPoint); " +
|
|
||||||
" print('myID=' + Particle.getID() + '\\n'); " +
|
|
||||||
" var voxelColor = { red: voxel.red, green: voxel.green, blue: voxel.blue };" +
|
|
||||||
" var voxelAt = { x: voxel.x, y: voxel.y, z: voxel.z };" +
|
|
||||||
" var voxelScale = voxel.s;" +
|
|
||||||
" print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue + '\\n'); " +
|
|
||||||
" var myColor = Particle.getColor();" +
|
|
||||||
" print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue + '\\n'); " +
|
|
||||||
" Particle.setColor(voxelColor); " +
|
|
||||||
" Voxels.setVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale, 255, 255, 0); " +
|
|
||||||
" print('Voxels.setVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')... \\n'); " +
|
|
||||||
" } " +
|
|
||||||
" Particle.collisionWithVoxel.connect(collisionWithVoxel); ";
|
|
||||||
|
|
||||||
Particles.addParticle(
|
|
||||||
{ position: position,
|
|
||||||
radius: 0.01,
|
|
||||||
color: { red: 128, green: 128, blue: 128 },
|
|
||||||
velocity: velocity,
|
|
||||||
gravity: { x: 0, y: -0.1, z: 0 },
|
|
||||||
damping: 0,
|
|
||||||
script: script }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// register the call back so it fires before each data send
|
|
||||||
Script.update.connect(checkController);
|
|
|
@ -5,7 +5,7 @@
|
||||||
// Created by Benjamin Arnold on May 29, 2014
|
// Created by Benjamin Arnold on May 29, 2014
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// This sample script creates a swarm of tweeting bird particles that fly around the avatar.
|
// This sample script creates a swarm of tweeting bird entities that fly around the avatar.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
@ -91,15 +91,16 @@ function addBird()
|
||||||
size = 0.15;
|
size = 0.15;
|
||||||
}
|
}
|
||||||
var properties = {
|
var properties = {
|
||||||
|
type: "Sphere",
|
||||||
lifetime: birdLifetime,
|
lifetime: birdLifetime,
|
||||||
position: Vec3.sum(randVector(-range, range), myPosition),
|
position: Vec3.sum(randVector(-range, range), myPosition),
|
||||||
velocity: { x: 0, y: 0, z: 0 },
|
velocity: { x: 0, y: 0, z: 0 },
|
||||||
gravity: { x: 0, y: BIRD_GRAVITY, z: 0 },
|
gravity: { x: 0, y: BIRD_GRAVITY, z: 0 },
|
||||||
radius : size,
|
dimensions: { x: size * 2, y: size * 2, z: size * 2 },
|
||||||
color: color
|
color: color
|
||||||
};
|
};
|
||||||
|
|
||||||
birds.push(new Bird(Particles.addParticle(properties), tweet, properties.position));
|
birds.push(new Bird(Entities.addEntity(properties), tweet, properties.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
var numBirds = 30;
|
var numBirds = 30;
|
||||||
|
@ -129,7 +130,7 @@ function updateBirds(deltaTime) {
|
||||||
// Update all the birds
|
// Update all the birds
|
||||||
for (var i = 0; i < numBirds; i++) {
|
for (var i = 0; i < numBirds; i++) {
|
||||||
particleID = birds[i].particleID;
|
particleID = birds[i].particleID;
|
||||||
var properties = Particles.getParticleProperties(particleID);
|
var properties = Entities.getEntityProperties(particleID);
|
||||||
|
|
||||||
// Tweeting behavior
|
// Tweeting behavior
|
||||||
if (birds[i].tweeting == 0) {
|
if (birds[i].tweeting == 0) {
|
||||||
|
@ -180,19 +181,19 @@ function updateBirds(deltaTime) {
|
||||||
|
|
||||||
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2);
|
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2);
|
||||||
// If we are near the target, we should get a new target
|
// If we are near the target, we should get a new target
|
||||||
if (Vec3.length(Vec3.subtract(properties.position, birds[i].targetPosition)) < (properties.radius / 5.0)) {
|
if (Vec3.length(Vec3.subtract(properties.position, birds[i].targetPosition)) < (properties.dimensions.x / 5.0)) {
|
||||||
birds[i].moving = false;
|
birds[i].moving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a cosine wave offset to make it look like its flapping.
|
// Use a cosine wave offset to make it look like its flapping.
|
||||||
var offset = Math.cos(nowTimeInSeconds * BIRD_FLAP_SPEED) * properties.radius;
|
var offset = Math.cos(nowTimeInSeconds * BIRD_FLAP_SPEED) * properties.dimensions.x;
|
||||||
properties.position.y = properties.position.y + (offset - birds[i].previousFlapOffset);
|
properties.position.y = properties.position.y + (offset - birds[i].previousFlapOffset);
|
||||||
// Change position relative to previous offset.
|
// Change position relative to previous offset.
|
||||||
birds[i].previousFlapOffset = offset;
|
birds[i].previousFlapOffset = offset;
|
||||||
|
|
||||||
// Update the particle
|
// Update the particle
|
||||||
Particles.editParticle(particleID, properties);
|
Entities.editEntity(particleID, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue