mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-17 22:52:15 +02:00
Merge pull request #6580 from imgntn/parented_flashlight
Update Flashlight to use Parenting
This commit is contained in:
commit
27d28900a4
1 changed files with 17 additions and 28 deletions
|
@ -25,7 +25,7 @@
|
|||
//we are creating lights that we don't want to get stranded so lets make sure that we can get rid of them
|
||||
var startTime = Date.now();
|
||||
//if you're going to be using this in a dungeon or something and holding it for a long time, increase this lifetime value.
|
||||
var LIFETIME = 25;
|
||||
var LIFETIME = 100;
|
||||
var MSEC_PER_SEC = 1000.0;
|
||||
|
||||
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
|
||||
|
@ -85,9 +85,14 @@
|
|||
this.hand = 'LEFT';
|
||||
},
|
||||
|
||||
startNearGrab: function() {
|
||||
startNearGrab: function(entityID) {
|
||||
if (!this.hasSpotlight) {
|
||||
|
||||
var modelProperties = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
||||
var lightTransform = evalLightWorldTransform(modelProperties.position, modelProperties.rotation);
|
||||
var glowLightTransform = glowLightWorldTransform(modelProperties.position, modelProperties.rotation);
|
||||
|
||||
|
||||
//this light casts the beam
|
||||
this.spotlight = Entities.addEntity({
|
||||
type: "Light",
|
||||
|
@ -97,6 +102,7 @@
|
|||
y: 2,
|
||||
z: 20
|
||||
},
|
||||
parentID: this.entityID,
|
||||
color: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
|
@ -105,7 +111,9 @@
|
|||
intensity: 2,
|
||||
exponent: 0.3,
|
||||
cutoff: 20,
|
||||
lifetime: LIFETIME
|
||||
lifetime: LIFETIME,
|
||||
position: lightTransform.p,
|
||||
rotation: lightTransform.q,
|
||||
});
|
||||
|
||||
//this light creates the effect of a bulb at the end of the flashlight
|
||||
|
@ -116,6 +124,7 @@
|
|||
y: 0.25,
|
||||
z: 0.25
|
||||
},
|
||||
parentID: this.entityID,
|
||||
isSpotlight: false,
|
||||
color: {
|
||||
red: 255,
|
||||
|
@ -123,8 +132,11 @@
|
|||
blue: 255
|
||||
},
|
||||
exponent: 0,
|
||||
lifetime: LIFETIME,
|
||||
cutoff: 90, // in degrees
|
||||
lifetime: LIFETIME
|
||||
position: glowLightTransform.p,
|
||||
rotation: glowLightTransform.q,
|
||||
|
||||
});
|
||||
|
||||
this.hasSpotlight = true;
|
||||
|
@ -142,7 +154,6 @@
|
|||
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
|
||||
this.setWhichHand();
|
||||
} else {
|
||||
this.updateLightPositions();
|
||||
this.changeLightWithTriggerPressure(this.whichHand);
|
||||
}
|
||||
},
|
||||
|
@ -159,29 +170,7 @@
|
|||
this.lightOn = false;
|
||||
}
|
||||
},
|
||||
|
||||
updateLightPositions: function() {
|
||||
var modelProperties = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
||||
|
||||
//move the two lights along the vectors we set above
|
||||
var lightTransform = evalLightWorldTransform(modelProperties.position, modelProperties.rotation);
|
||||
var glowLightTransform = glowLightWorldTransform(modelProperties.position, modelProperties.rotation);
|
||||
|
||||
//move them with the entity model
|
||||
Entities.editEntity(this.spotlight, {
|
||||
position: lightTransform.p,
|
||||
rotation: lightTransform.q,
|
||||
lifetime: (Date.now() - startTime) / MSEC_PER_SEC + LIFETIME
|
||||
});
|
||||
|
||||
Entities.editEntity(this.glowLight, {
|
||||
position: glowLightTransform.p,
|
||||
rotation: glowLightTransform.q,
|
||||
lifetime: (Date.now() - startTime) / MSEC_PER_SEC + LIFETIME
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
|
||||
changeLightWithTriggerPressure: function(flashLightHand) {
|
||||
|
||||
if (flashLightHand === 'LEFT') {
|
||||
|
|
Loading…
Reference in a new issue