-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaser.js
65 lines (50 loc) · 1.56 KB
/
laser.js
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
laser = function(camera) {
var speed = 100;
var dist = 0;
var material = new THREE.MeshLambertMaterial({
//alphaTest: 0.5,
shading: THREE.FlatShading,
//overdraw: true,
//wireframe: true,
//wireframeLinewidth: 2,
//reflectivity: 0.3,
emissive: 'rgb(255,255,255)',
//shiness: 10,
color: 'rgb(255,255,255)',
//map: texture,
//transparent: true,
//wrapAround: true,
//opacity: 0.95
fog: true
});
var geometry = new THREE.PlaneGeometry(1, 30);
var mesh = new THREE.Mesh(new THREE.CubeGeometry(0.1, 0.1, 1.0), material);
mesh.scale.z = 300;
mesh.rotation.y = camera.rotation.y;
var dir = new THREE.Vector3();
dir = camera.localToWorld(new THREE.Vector3(0, 0, 1));
dir.sub(dir,camera.position);
dir.normalize();
mesh.position.x = camera.position.x;
mesh.position.y = 1;
mesh.position.z = camera.position.z;
mesh.name = 'laser';
var pl = PointLight.getLight();
pl.distance = 300;
pl.intensity = 1;
mesh.add(pl);
var lScene = this;
mesh.update = function(dt) {
dist += speed;
pl.position.y = 5;
mesh.position.x += dir.x * speed;
mesh.position.z += dir.z * speed;
//document.getElementById( "val_right" ).innerHTML = mesh.position.distanceTo(camera.position);
if (mesh.position.distanceTo(camera.position) > 1000) {
pl.distance = 0;
pl.intensity = 0;
lScene.remove(mesh);
}
};
this.add(mesh);
};