BlueGit

timfa frameworkv3

Fix step 1

timfa Tim · pushed by timfa

Authored 2022-10-18 · 4 years ago

Hash
a8a9a632951c2d3b44c99c04b4ce98c3cca7da64
Parent
6ae3b3c3
3 files changed +12 −11
framework/engine/objectComponents/collider.js +2 −2
@@ -59,9 +59,9 @@ class Collider
59 59 var hw = this.gameObject.transform.size.x / 2;
60 60 var hh = this.gameObject.transform.size.y / 2;
61 61
62 if(point.x > this.transform.position.x - hw && point.x < this.transform.position.x + hw)
62 if(point.x > this.gameObject.transform.position.x - hw && point.x < this.gameObject.transform.position.x + hw)
63 63 {
64 if(point.y > this.transform.position.y - hh && point.y < this.transform.position.y + hh)
64 if(point.y > this.gameObject.transform.position.y - hh && point.y < this.gameObject.transform.position.y + hh)
65 65 {
66 66 return true;
67 67 }
@@ -59,9 +59,9 @@ class Collider
59 var hw = this.gameObject.transform.size.x / 2;
59 var hw = this.gameObject.transform.size.x / 2;
60 var hh = this.gameObject.transform.size.y / 2;
60 var hh = this.gameObject.transform.size.y / 2;
61
61
62 if(point.x > this.transform.position.x - hw && point.x < this.transform.position.x + hw)
62 if(point.x > this.gameObject.transform.position.x - hw && point.x < this.gameObject.transform.position.x + hw)
63 {
63 {
64 if(point.y > this.transform.position.y - hh && point.y < this.transform.position.y + hh)
64 if(point.y > this.gameObject.transform.position.y - hh && point.y < this.gameObject.transform.position.y + hh)
65 {
65 {
66 return true;
66 return true;
67 }
67 }
framework/util/ray.js +5 −4
@@ -18,18 +18,19 @@ class Ray
18 18 new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)
19 19 ]
20 20
21 for(let p = 0; o < points.length; p++)
21 for(let p = 0; p < points.length; p++)
22 22 {
23 let point = points[p].subtract(origin);
23 let point = points[p];
24 let deltaDistance = point.subtract(origin).length;
24 25 direction = direction.normalize();
25 26
26 let stretched = direction.stretch(Math.min(point.length, maxLength >= 0? maxLength : point.length))
27 let stretched = direction.stretch(Math.min(deltaDistance, maxLength > 0? maxLength : deltaDistance))
27 28
28 29 let calcPoint = origin.add(stretched);
29 30
30 31 if(scene.activeObjects[i].collider.isInBounds(calcPoint))
31 32 {
32 hits.push({hitObj: scene.activeObjects[i], hitPoint: new vector(0, 0)})
33 hits.push({hitObj: scene.activeObjects[i], hitPoint: calcPoint})
33 34 }
34 35 }
35 36 }
@@ -18,18 +18,19 @@ class Ray
18 new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)
18 new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)
19 ]
19 ]
20
20
21 for(let p = 0; o < points.length; p++)
21 for(let p = 0; p < points.length; p++)
22 {
22 {
23 let point = points[p].subtract(origin);
23 let point = points[p];
24 let deltaDistance = point.subtract(origin).length;
24 direction = direction.normalize();
25 direction = direction.normalize();
25
26
26 let stretched = direction.stretch(Math.min(point.length, maxLength >= 0? maxLength : point.length))
27 let stretched = direction.stretch(Math.min(deltaDistance, maxLength > 0? maxLength : deltaDistance))
27
28
28 let calcPoint = origin.add(stretched);
29 let calcPoint = origin.add(stretched);
29
30
30 if(scene.activeObjects[i].collider.isInBounds(calcPoint))
31 if(scene.activeObjects[i].collider.isInBounds(calcPoint))
31 {
32 {
32 hits.push({hitObj: scene.activeObjects[i], hitPoint: new vector(0, 0)})
33 hits.push({hitObj: scene.activeObjects[i], hitPoint: calcPoint})
33 }
34 }
34 }
35 }
35 }
36 }
framework/util/vector.js +5 −5
@@ -12,10 +12,10 @@ class vector
12 12
13 13 get length()
14 14 {
15 return this.length();
15 return Math.sqrt((this.x * this.x) + (this.y * this.y));
16 16 }
17 17
18 length()
18 getLength()
19 19 {
20 20 return Math.sqrt((this.x * this.x) + (this.y * this.y));
21 21 }
@@ -31,9 +31,9 @@ class vector
31 31 {
32 32 var newVector = this.getCopy();
33 33
34 if(newVector.length() != 0)
34 if(newVector.length != 0)
35 35 {
36 var length = newVector.length();
36 var length = newVector.length;
37 37 newVector.x /= length;
38 38 newVector.y /= length;
39 39 }
@@ -55,7 +55,7 @@ class vector
55 55 var dX = this.x - otherVector.x;
56 56 var dY = this.y - otherVector.y;
57 57
58 return new vector(dX, dY).length();
58 return new vector(dX, dY).length;
59 59 }
60 60
61 61
@@ -12,10 +12,10 @@ class vector
12
12
13 get length()
13 get length()
14 {
14 {
15 return this.length();
15 return Math.sqrt((this.x * this.x) + (this.y * this.y));
16 }
16 }
17
17
18 length()
18 getLength()
19 {
19 {
20 return Math.sqrt((this.x * this.x) + (this.y * this.y));
20 return Math.sqrt((this.x * this.x) + (this.y * this.y));
21 }
21 }
@@ -31,9 +31,9 @@ class vector
31 {
31 {
32 var newVector = this.getCopy();
32 var newVector = this.getCopy();
33
33
34 if(newVector.length() != 0)
34 if(newVector.length != 0)
35 {
35 {
36 var length = newVector.length();
36 var length = newVector.length;
37 newVector.x /= length;
37 newVector.x /= length;
38 newVector.y /= length;
38 newVector.y /= length;
39 }
39 }
@@ -55,7 +55,7 @@ class vector
55 var dX = this.x - otherVector.x;
55 var dX = this.x - otherVector.x;
56 var dY = this.y - otherVector.y;
56 var dY = this.y - otherVector.y;
57
57
58 return new vector(dX, dY).length();
58 return new vector(dX, dY).length;
59 }
59 }
60
60
61
61