-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockSensorToWorldMap.js
More file actions
66 lines (54 loc) · 1.72 KB
/
Copy pathLockSensorToWorldMap.js
File metadata and controls
66 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(function(){
print("Top of new spawn cube");
var hand;
var _this = this;
var target;
_this.clickDownOnEntity = function(entityID, event){
print("I was clicked!");
changeColor(entityID);
}
var changeColor = function(entityID){
var newRed = Math.random()*255;
var newGreen = Math.random()*255;
var newBlue = Math.random()*255;
var newProperty = { color: {red: newRed, green: newGreen, blue: newBlue}};
Entities.editEntity(entityID, newProperty);
}
var lockWorldTransform = function(entityID){
target = MyAvatar.getSensorToWorldMatrix();
}
var fixWorldTransform = function(entityID){
if (target == undefined) {
print("target is undefined, locking instead.");
lockWorldTransform(entityID);
} else {
print("target is defined.");
var current_inverse = Mat4.inverse(MyAvatar.getSensorToWorldMatrix());
var currentPos = MyAvatar.getHeadPosition();
var translation = Mat4.extractTranslation(Mat4.multiply(target, current_inverse));
MyAvatar.goToLocation(Vec3.sum(currentPos, translation), false);
}
}
function Locker(){};
Locker.prototype = {
preload: function(entityID){
},
clickDownOnEntity: function(entityID, event){
print("I was clicked by the mouse!");
changeColor(entityID);
},
startFarTrigger: function(entityID){
print("I was clicked in VR!");
fixWorldTransform();
changeColor(entityID);
},
startNearTrigger: function(entityID){
print("I was clicked in VR!");
fixWorldTransform();
changeColor(entityID);
}
};
var someFunction = function(){
}
return new Locker();
});