You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/VirtualAnatomy/ExplorerLevel/MeshSelection/RayCasting.md
+89-13Lines changed: 89 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,9 @@
6
6
As mentioned, we have chosen ray casting as the primary method for selecting which objects the user clicks on.
7
7
8
8
The way it works is that when the user clicks on the screen, we receive coordinates about where the mouse was clicked (in screen space). We then transform this mouse location to world space and calculate the direction from our character to the point where the mouse clicked. This direction is normalized, meaning it has a length of 1.
9
+
After that, we specify a ray length parameter to determine where the ray should end and then cast the ray from the character’s position towards the calculated endpoint.
9
10
10
-
Next, we specify a ray length parameter to determine where the ray should end.
11
-
12
-
After that, we shoot the ray from the position of our character towards the calculated end of the ray.
11
+
Previously, the system used basic ray-object collision detection techniques, but we have now implemented the Möller-Trumbore algorithm for more precise intersection testing with triangles in the scene. This algorithm allows efficient ray-triangle intersection detection, making it particularly useful for accurate selection of 3D models and surfaces.
13
12
14
13
All of these calculations are performed once the user presses the left mouse button.
15
14
@@ -25,13 +24,11 @@ The main responsibility of the `RayCaster` class is to trace the actual rays thr
25
24
26
25
----
27
26
28
-
### `RayCaster(UWorld* world = nullptr)`
29
-
30
-
**Parameters:**
27
+
### `RayCaster()`
31
28
32
-
-`UWorld* world ` - world to use for ray casting
29
+
Constructor initializing the m_world and m_currentHitComponent to nullptr.
33
30
34
-
The constructor takes a world as a parameter, which can be `nullptr` by default since the "world" does not exist during construction time.
31
+
`m_world` is set initially to `nullptr` since the "world" does not exist during construction time.
35
32
36
33
However, you can construct this class in other places besides constructors.
37
34
@@ -76,17 +73,23 @@ Therefore, before each intersection test, you must ensure that the world is set
Performs a precise ray trace, detecting triangle-level intersections on static meshes.
80
79
81
80
**Parameters:**
82
81
83
-
-`FVector start` - The starting point of the ray in world space.
84
-
-`FVector rayDirection` - The direction in which the ray will travel.
85
-
-`float rayLength` - The length of the ray, default value is 1000.
82
+
-`start`- the starting point of the ray
83
+
-`rayDirection`- the direction of the ray
84
+
-`rayLength`- the length of the ray
85
+
-`outHitPoint`- stores the location where the ray hits
86
+
-`outHitNormal`- stores the normal of the hit surface
87
+
-`outTriangleIndex`- stores the index of the hit triangle (-1 if no triangle was hit)
88
+
-`outU, outV`- Barycentric coordinates of the hit point
86
89
87
90
**Returns:**
88
91
89
-
-`True` if a hit was detected.
92
+
-`True` if an intersection is found.
90
93
-`False` otherwise.
91
94
92
95
This function uses the `LineTraceSingleByChannel` method from the `UWorld` class to trace the provided ray through the world. By default, it uses the **Visible** channel for intersection testing, meaning only objects that are visible within the scene will be tested for intersection.
@@ -95,6 +98,63 @@ If a hit is detected, the actor that caused the intersection will be stored in t
95
98
96
99
Lastly, all actors that were added via `AddIngoredActor` method will be ignored
If you visit the `BP_User` and open the viewport, you can see both the spring arm and camera there.
@@ -81,7 +80,7 @@ If you visit the `BP_User` and open the viewport, you can see both the spring ar
81
80

82
81
83
82
84
-
##Public fiels
83
+
##Public fiels
85
84
86
85
----
87
86
@@ -120,7 +119,6 @@ For example, if you want the user to start spinning once the game starts, you wo
120
119
121
120
Here we set up our default `TargetActor` and `RayCaster`, since both of them require access to the `World`, and the `World` is not accessible during construction time (e.g., in the constructor).
122
121
123
-
124
122
-----
125
123
126
124
### `void Tick(float DeltaTime);`
@@ -287,7 +285,7 @@ Rotates the character around the `TargetActor` this method is being called insid
0 commit comments