Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 04bbf9d

Browse filesBrowse files
committed
add plane reflection example
1 parent 1cf0c96 commit 04bbf9d
Copy full SHA for 04bbf9d
Expand file treeCollapse file tree

20 files changed

+455
-126
lines changed

‎Assets/Scenes/GlobalScripts/HolisticMath.cs

Copy file name to clipboardExpand all lines: Assets/Scenes/GlobalScripts/HolisticMath.cs
-77Lines changed: 0 additions & 77 deletions
This file was deleted.

‎Assets/Scenes/GlobalScripts.meta renamed to ‎Assets/Scripts.meta

Copy file name to clipboardExpand all lines: Assets/Scripts.meta
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scenes/GlobalScripts/Coords.cs renamed to ‎Assets/Scripts/Coords.cs

Copy file name to clipboardExpand all lines: Assets/Scripts/Coords.cs
+27-8Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public Coords(Vector3 vecpos)
3030
z = vecpos.z;
3131
}
3232

33+
public Coords GetNormal()
34+
{
35+
float magnitude = HolisticMath.Distance(new Coords(0, 0, 0), new Coords(x, y, z));
36+
return new Coords(x / magnitude, y / magnitude, z / magnitude);
37+
}
38+
3339
public override string ToString()
3440
{
3541
return "(" + x + "," + y + "," + z + ")";
@@ -42,12 +48,31 @@ public Vector3 ToVector()
4248

4349
static public Coords operator +(Coords a, Coords b)
4450
{
45-
return new Coords(a.x + b.x, a.y + b.y, a.z + b.z);
51+
Coords c = new Coords(a.x + b.x, a.y + b.y, a.z + b.z);
52+
return c;
4653
}
4754

4855
static public Coords operator -(Coords a, Coords b)
4956
{
50-
return new Coords(a.x - b.x, a.y - b.y, a.z - b.z);
57+
Coords c = new Coords(a.x - b.x, a.y - b.y, a.z - b.z);
58+
return c;
59+
}
60+
61+
static public Coords operator /(Coords a, float b)
62+
{
63+
Coords c = new Coords(a.x / b, a.y / b, a.z / b);
64+
return c;
65+
}
66+
67+
static public Coords operator *(Coords a, float b)
68+
{
69+
Coords c = new Coords(a.x * b, a.y * b, a.z * b);
70+
return c;
71+
}
72+
73+
static public Coords Perp(Coords v)
74+
{
75+
return new Coords(-v.y, v.x, -1.0f);
5176
}
5277

5378
static public void DrawLine(Coords startPoint, Coords endPoint, float width, Color colour)
@@ -63,12 +88,6 @@ static public void DrawLine(Coords startPoint, Coords endPoint, float width, Col
6388
lineRenderer.endWidth = width;
6489
}
6590

66-
67-
static public Coords Perp(Coords v)
68-
{
69-
return new Coords(-v.y, v.x);
70-
}
71-
7291
static public void DrawPoint(Coords position, float width, Color colour)
7392
{
7493
GameObject line = new GameObject("Point_" + position.ToString());

‎Assets/Scenes/GlobalScripts/Coords.cs.meta renamed to ‎Assets/Scripts/Coords.cs.meta

Copy file name to clipboardExpand all lines: Assets/Scripts/Coords.cs.meta
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scenes/GlobalScripts/CreateLines.cs renamed to ‎Assets/Scripts/CreateLines.cs

Copy file name to clipboardExpand all lines: Assets/Scripts/CreateLines.cs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class CreateLines : MonoBehaviour
1010
// Start is called before the first frame update
1111
void Start()
1212
{
13-
L1 = new Line(new Coords(0.0f, 0.0f, 0.0f), new Coords(-6.0f, 7.0f, 3.0f));
13+
L1 = new Line(new Coords(-100, 0, 0), new Coords(20, 50, 0));
1414
L1.Draw(1, Color.green);
15-
L2 = new Line(new Coords(0.0f, 0.0f, 0.0f), new Coords(-7.0f, -6.0f, 6.0f));
15+
L2 = new Line(new Coords(-100, 10, 0), new Coords(0, 50, 0));
1616
L2.Draw(1, Color.red);
1717

1818
float intersectT = L1.IntersectsAt(L2);
@@ -23,6 +23,8 @@ void Start()
2323
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
2424
sphere.transform.position = L1.Lerp(intersectT).ToVector();
2525
}
26+
27+
Debug.Log("T:" + intersectT + " S:" + intersectS);
2628
}
2729

2830
// Update is called once per frame

‎Assets/Scenes/GlobalScripts/CreateLines.cs.meta renamed to ‎Assets/Scripts/CreateLines.cs.meta

Copy file name to clipboardExpand all lines: Assets/Scripts/CreateLines.cs.meta
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scripts/CreatePlane.cs

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class CreatePlane : MonoBehaviour
6+
{
7+
public Transform A;
8+
public Transform B;
9+
public Transform C;
10+
Plane plane;
11+
12+
// Start is called before the first frame update
13+
void Start()
14+
{
15+
plane = new Plane(new Coords(A.position),
16+
new Coords(B.position),
17+
new Coords(C.position));
18+
19+
for(float s = -5; s < 5; s += 0.1f)
20+
{
21+
for(float t = -5; t < 5; t += 0.1f)
22+
{
23+
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
24+
sphere.transform.position = plane.Lerp(s, t).ToVector();
25+
}
26+
}
27+
}
28+
29+
// Update is called once per frame
30+
void Update()
31+
{
32+
33+
}
34+
}

‎Assets/Scripts/CreatePlane.cs.meta

Copy file name to clipboardExpand all lines: Assets/Scripts/CreatePlane.cs.meta
+11Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+16-10Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
44

@@ -13,31 +13,37 @@ public class CreatePlaneHit : MonoBehaviour
1313
Plane plane;
1414
Line L1;
1515

16+
// Start is called before the first frame update
1617
void Start()
1718
{
18-
plane = new Plane(new Coords(A.position), new Coords(B.position), new Coords(C.position));
19+
plane = new Plane(new Coords(A.position),
20+
new Coords(B.position),
21+
new Coords(C.position));
1922

2023
L1 = new Line(new Coords(D.position), new Coords(E.position), Line.LINETYPE.RAY);
2124
L1.Draw(1, Color.green);
2225

23-
for (float s = 0; s <= 1; s += 0.1f)
26+
for(float s = 0; s <= 1; s += 0.1f)
2427
{
25-
for (float t = 0; t <= 1; t += 0.1f)
28+
for(float t = 0; t <= 1; t += 0.1f)
2629
{
2730
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
2831
sphere.transform.position = plane.Lerp(s, t).ToVector();
2932
}
3033
}
3134

32-
float z = L1.IntersectsAt(plane);
33-
Debug.Log(z);
34-
35-
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
36-
cube.transform.position = L1.Lerp(z).ToVector();
35+
float interceptT = L1.IntersectsAt(plane);
36+
if(interceptT == interceptT)
37+
{
38+
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
39+
cube.transform.position = L1.Lerp(interceptT).ToVector();
40+
}
3741
}
3842

43+
44+
// Update is called once per frame
3945
void Update()
4046
{
41-
47+
4248
}
4349
}

‎Assets/Scenes/GlobalScripts/CreatePlaneHit.cs.meta renamed to ‎Assets/Scripts/CreatePlaneHit.cs.meta

Copy file name to clipboardExpand all lines: Assets/Scripts/CreatePlaneHit.cs.meta
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scripts/CreateWall.cs

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class CreateWall : MonoBehaviour
6+
{
7+
Line wall;
8+
Line ballPath;
9+
public GameObject ball;
10+
Vector3 pathNormal;
11+
12+
Line trajectory;
13+
14+
// Start is called before the first frame update
15+
void Start()
16+
{
17+
wall = new Line(new Coords(5, -2, 0), new Coords(0, 5, 0));
18+
wall.Draw(1, Color.blue);
19+
20+
ballPath = new Line(new Coords(-6, 2, 0), new Coords(100, -20, 0));
21+
ballPath.Draw(0.1f, Color.yellow);
22+
23+
ball.transform.position = ballPath.A.ToVector();
24+
25+
//ball path wall intersection
26+
float t = ballPath.IntersectsAt(wall);
27+
float s = wall.IntersectsAt(ballPath);
28+
if (t == t && s == s)
29+
trajectory = new Line(ballPath.A, ballPath.Lerp(t), Line.LINETYPE.SEGMENT);
30+
31+
}
32+
33+
// Update is called once per frame
34+
void Update()
35+
{
36+
if (Time.time <= 1)
37+
{
38+
ball.transform.position = trajectory.Lerp(Time.time).ToVector();
39+
}
40+
else
41+
{
42+
ball.transform.position += trajectory.Reflect(Coords.Perp(wall.v)).ToVector() * Time.deltaTime * 5;
43+
}
44+
45+
}
46+
}

‎Assets/Scripts/CreateWall.cs.meta

Copy file name to clipboardExpand all lines: Assets/Scripts/CreateWall.cs.meta
+11Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.