WEBVTT 1 00:00:05.646 --> 00:00:09.933 Game Basics Mathematics for 3D Games 1 (3D Space Design, Euler Angles) 2 00:00:09.933 --> 00:00:12.088 GCC Academy 3 00:00:26.102 --> 00:00:27.552 Hello everyone 4 00:00:27.552 --> 00:00:29.449 This is Lee Deuk-woo on Game Mathematics 5 00:00:29.449 --> 00:00:33.340 Today, we will be talking about the third dimension 6 00:00:33.340 --> 00:00:36.220 Before learning about math for 3D, 7 00:00:36.220 --> 00:00:39.020 let's first learn about 8 00:00:39.020 --> 00:00:42.700 how to design the transforms in 3D space 9 00:00:42.700 --> 00:00:46.500 We will start by designing a 3D space 10 00:00:46.500 --> 00:00:50.980 What is different about setting transform in 3D than in 2D, 11 00:00:50.980 --> 00:00:52.730 and in a 3D space, 12 00:00:52.730 --> 00:00:55.380 how do we design the camera system? 13 00:00:55.380 --> 00:00:57.139 We will find out together 14 00:00:57.139 --> 00:00:59.889 And finally, we will take a look 15 00:00:59.889 --> 00:01:02.619 at a work produced with this theory 16 00:01:02.619 --> 00:01:06.620 Next, we'll learn about Euler angles, 17 00:01:06.620 --> 00:01:09.419 an expression for rotation in a 3D space 18 00:01:09.419 --> 00:01:12.419 We will first learn about the expression in an Euler angle, 19 00:01:12.419 --> 00:01:14.619 and then the strengths 20 00:01:14.619 --> 00:01:16.475 and limitations of Euler angle 21 00:01:16.957 --> 00:01:20.710 Designing a 3D Space 22 00:01:21.860 --> 00:01:25.379 When dealing with 3D space, 23 00:01:25.379 --> 00:01:28.900 Let's start with 2D space 24 00:01:28.900 --> 00:01:33.099 In 2D, the x-axis typically points to the right, and the y-axis points upwards, 25 00:01:33.099 --> 00:01:36.019 which makes implementation relatively straightforward 26 00:01:36.019 --> 00:01:40.260 However, in 3D, the space is composed of three axes, 27 00:01:40.260 --> 00:01:42.580 and the way you design this space 28 00:01:42.580 --> 00:01:45.820 can influence the application methods 29 00:01:45.820 --> 00:01:49.459 and the mathematics we will explore 30 00:01:49.459 --> 00:01:53.580 Therefore, it is crucial to clearly define this first 31 00:01:53.580 --> 00:01:55.980 Instead of simply adopting 32 00:01:55.980 --> 00:01:58.419 a coordinate system jus because 33 00:01:58.419 --> 00:02:01.099 this application uses it, 34 00:02:01.099 --> 00:02:04.500 it is better to think about the principles 35 00:02:04.500 --> 00:02:06.700 and establish a system 36 00:02:06.700 --> 00:02:09.979 that suits your needs 37 00:02:09.979 --> 00:02:13.020 I think that is a better way to work with it 38 00:02:13.020 --> 00:02:14.631 So now, for us 39 00:02:14.631 --> 00:02:17.820 to design a 3D space, 40 00:02:17.820 --> 00:02:19.699 you must choose between two options 41 00:02:19.699 --> 00:02:22.300 Using a left-handed 42 00:02:22.300 --> 00:02:25.899 or a right-handed coordinate system 43 00:02:25.899 --> 00:02:28.820 Let me explain briefly about how to distinguish 44 00:02:28.820 --> 00:02:30.460 between the left- and right-handed system 45 00:02:30.460 --> 00:02:34.139 When you create a 3D space, 46 00:02:34.139 --> 00:02:36.089 it essentially adds 47 00:02:36.089 --> 00:02:39.220 one dimension to a 2D space 48 00:02:39.220 --> 00:02:41.470 Then, in designing a 2D space, 49 00:02:41.470 --> 00:02:43.139 to start, fix the 2D space 50 00:02:43.139 --> 00:02:46.380 As this is generally accepted, as we look at the monitor 51 00:02:46.380 --> 00:02:48.380 the x-axis points to the right 52 00:02:48.380 --> 00:02:50.779 and the y-axis points upwards 53 00:02:50.779 --> 00:02:53.729 Now, after we have fixed 54 00:02:53.729 --> 00:02:56.380 this 2D space as we see it here, 55 00:02:56.380 --> 00:02:59.580 based on the direction of the remaining dimension, 56 00:02:59.580 --> 00:03:01.132 you can distinguish 57 00:03:01.132 --> 00:03:03.380 whether the system is left- or right-handed 58 00:03:03.380 --> 00:03:05.430 When you look at the screen, 59 00:03:05.430 --> 00:03:11.339 you can see that after fixing the red 60 00:03:11.339 --> 00:03:13.239 and green axes as the x and y axes, 61 00:03:13.239 --> 00:03:16.779 the direction of the remaining z-axis 62 00:03:16.779 --> 00:03:18.172 determines whether 63 00:03:18.172 --> 00:03:21.500 the system is left-handed or right-handed 64 00:03:21.500 --> 00:03:24.259 If the z-axis points away from you, 65 00:03:24.259 --> 00:03:27.809 beyond the monitor, 66 00:03:27.809 --> 00:03:29.940 it is a left-handed coordinate system 67 00:03:29.940 --> 00:03:33.940 On the other hand, if the z-axis points toward you, 68 00:03:33.940 --> 00:03:35.490 it is a right-handed coordinate system 69 00:03:35.490 --> 00:03:38.539 That's how you can understand it 70 00:03:38.539 --> 00:03:43.860 The left-handed coordinate system is characterized as follows 71 00:03:43.860 --> 00:03:47.940 When we fix the x and the y axes, 72 00:03:47.940 --> 00:03:51.619 by the z-axis pointing forward, beyond the screen, 73 00:03:51.619 --> 00:03:54.259 stretching like this 74 00:03:54.259 --> 00:03:57.699 This makes it suitable for viewing landscapes 75 00:03:57.699 --> 00:04:01.419 or scenes stretching into the distance 76 00:04:01.419 --> 00:04:03.169 In contrast, the right-handed coordinate system, 77 00:04:03.169 --> 00:04:05.820 where the z-axis points toward you, 78 00:04:05.820 --> 00:04:08.720 can be more useful 79 00:04:08.720 --> 00:04:10.460 when observing objects up close 80 00:04:10.460 --> 00:04:14.110 Ultimately, deciding between 81 00:04:14.110 --> 00:04:16.980 the left-handed and right-handed coordinate systems 82 00:04:16.980 --> 00:04:21.530 depends on your preference, 83 00:04:21.530 --> 00:04:22.220 and it's not necessarily set by rule 84 00:04:22.220 --> 00:04:26.540 Go for what feels more comfortable 85 00:04:26.540 --> 00:04:29.140 or convenient for the system 86 00:04:29.140 --> 00:04:31.940 that you are designing 87 00:04:31.940 --> 00:04:35.859 Once you’ve chosen a coordinate system, 88 00:04:35.859 --> 00:04:39.019 the next important decision is 89 00:04:39.019 --> 00:04:42.779 determining which axis will be designated as the upward axis, 90 00:04:42.779 --> 00:04:46.300 of x, y, and z axes 91 00:04:46.300 --> 00:04:48.435 which will be designated as the upward axis? 92 00:04:48.435 --> 00:04:49.980 We have to designate one 93 00:04:49.980 --> 00:04:52.899 The Up direction, as it is commonly referred to, 94 00:04:52.899 --> 00:04:56.149 becomes particularly important later when we deal with operations 95 00:04:56.149 --> 00:04:59.100 like cross products or when calculating rotation matrices 96 00:04:59.100 --> 00:05:00.923 based on view vectors 97 00:05:00.923 --> 00:05:04.579 Knowing and setting the Up direction clearly is crucial 98 00:05:04.579 --> 00:05:07.129 Broadly, the classification involves choosing between left-handed or right-handed systems 99 00:05:07.129 --> 00:05:09.619 and deciding the Up direction 100 00:05:09.619 --> 00:05:12.966 For example, as shown in a diagram 101 00:05:12.966 --> 00:05:14.739 shared on Twitter (X), 102 00:05:14.739 --> 00:05:20.100 systems are generally divided into left-handed and right-handed coordinate systems, 103 00:05:20.100 --> 00:05:23.276 with an additional distinction based on 104 00:05:23.276 --> 00:05:25.276 whether the Up direction is along the y-axis or the z-axis 105 00:05:25.276 --> 00:05:26.859 That's another classification 106 00:05:26.859 --> 00:05:30.299 By classifying the coordinate system into these categories, 107 00:05:30.299 --> 00:05:32.949 just understand that these systems 108 00:05:32.949 --> 00:05:35.019 or programs use these distinctions 109 00:05:35.019 --> 00:05:38.605 In this course, when we deal with 3D graphics, 110 00:05:38.605 --> 00:05:40.579 in the program I developed, 111 00:05:40.579 --> 00:05:43.979 all examples are implemented using the specific type 112 00:05:43.979 --> 00:05:45.820 of coordinate system I have designated 113 00:05:45.820 --> 00:05:50.700 The examples will use a right-handed coordinate system 114 00:05:50.700 --> 00:05:52.614 with the Up direction along the y-axis, 115 00:05:52.614 --> 00:05:56.420 referred to as Y-up Right-Handed 116 00:05:56.420 --> 00:05:58.498 This means we will use the Right-Handed Coordinating System 117 00:05:58.498 --> 00:06:03.660 with the y-axis pointing upwards, to be very brief 118 00:06:03.660 --> 00:06:05.660 The forward and backward directions, 119 00:06:05.660 --> 00:06:07.899 the remaining directions, 120 00:06:07.899 --> 00:06:11.100 will be determined by the z-axis, 121 00:06:11.100 --> 00:06:13.350 while the left and right directions 122 00:06:13.350 --> 00:06:15.420 will be handled by the x-axis 123 00:06:15.420 --> 00:06:17.920 This is the coordinate I will be using 124 00:06:17.920 --> 00:06:21.260 Please take a look at it 125 00:06:21.260 --> 00:06:23.700 After setting up the coordinate system, 126 00:06:23.700 --> 00:06:26.237 the next step involves 127 00:06:26.237 --> 00:06:29.380 configuring 3D transforms 128 00:06:29.380 --> 00:06:32.630 When transitioning from 2D to 3D, 129 00:06:32.630 --> 00:06:36.820 additional considerations arise 130 00:06:36.820 --> 00:06:41.260 For instance, in the case of translation transforms, 131 00:06:41.260 --> 00:06:45.550 movement along the z-axis is added 132 00:06:45.550 --> 00:06:48.700 to the x and y movements already present in 2D 133 00:06:48.700 --> 00:06:50.900 However, 134 00:06:50.900 --> 00:06:53.550 since the x, y, and z axes are orthogonal, 135 00:06:53.550 --> 00:06:55.388 movements along one axis do not affect the others 136 00:06:55.388 --> 00:06:59.688 Therefore, adding an additional dimension 137 00:06:59.688 --> 00:07:01.859 to the matrix we have 138 00:07:01.859 --> 00:07:05.019 allows for straightforward solutions without much complexity 139 00:07:05.019 --> 00:07:07.140 So it's not a big problem 140 00:07:07.140 --> 00:07:11.840 For scaling transformations, enlarging along the x and y axes 141 00:07:11.840 --> 00:07:14.459 does not affect the z-axis, 142 00:07:14.459 --> 00:07:19.209 so it simply involves extending the matrix 143 00:07:19.209 --> 00:07:22.019 to accommodate the added dimension 144 00:07:22.019 --> 00:07:24.469 However, rotation transformations 145 00:07:24.469 --> 00:07:28.380 are more complex because all three axes 146 00:07:28.380 --> 00:07:31.738 influence one another 147 00:07:31.738 --> 00:07:32.779 while maintaining orthogonality 148 00:07:32.779 --> 00:07:36.739 So this is much more complex 149 00:07:36.739 --> 00:07:40.570 Translation and scaling can be easily implemented 150 00:07:40.570 --> 00:07:42.299 by simply extending a single axis 151 00:07:42.299 --> 00:07:44.891 However, in the case of rotation, the addition of one axis 152 00:07:44.891 --> 00:07:48.579 causes all three axes to influence one another, 153 00:07:48.579 --> 00:07:51.940 making it a much more complex transformation 154 00:07:51.940 --> 00:07:55.019 To understand rotation, 155 00:07:55.019 --> 00:07:59.069 consider the x, y, and z axes, 156 00:07:59.069 --> 00:08:05.660 our initial orthogonal x, y, and z axes, 157 00:08:05.660 --> 00:08:08.171 which are rotated 158 00:08:08.171 --> 00:08:10.299 to form a new set of local basis vectors 159 00:08:10.299 --> 00:08:13.649 By substituting the transformed basis vectors into the matrix, 160 00:08:13.649 --> 00:08:15.339 like this, 161 00:08:15.339 --> 00:08:19.589 you can construct a 3x3 rotation matrix, 162 00:08:19.589 --> 00:08:22.179 which consists of nine elements representing these transformations 163 00:08:22.179 --> 00:08:24.980 So that's a rotation transformation 164 00:08:24.980 --> 00:08:31.180 Using the transformed standard basis vectors, such as e_1, e_2, and e_3, 165 00:08:31.180 --> 00:08:33.260 the rotation matrix can be established 166 00:08:33.260 --> 00:08:35.710 as mapped to x_local, y_local, and z_local 167 00:08:35.710 --> 00:08:40.071 By marking the values, 168 00:08:40.071 --> 00:08:42.059 we can then derive the corresponding matrix 169 00:08:42.059 --> 00:08:46.659 For the scaling matrix, the original 3x3 matrix 170 00:08:46.659 --> 00:08:50.619 is extended by adding one more dimension, resulting in a 4x4 matrix 171 00:08:50.619 --> 00:08:54.022 By simply adding the z-axis component to the last row, 172 00:08:54.022 --> 00:08:55.780 the matrix can be easily constructed 173 00:08:55.780 --> 00:08:59.123 However, with rotation, local axis information must 174 00:08:59.123 --> 00:09:01.500 be fully determined 175 00:09:01.500 --> 00:09:04.567 and inserted vertically 176 00:09:04.567 --> 00:09:06.700 to build the rotation matrix 177 00:09:06.700 --> 00:09:08.900 Translation matrices 178 00:09:08.900 --> 00:09:11.539 similarly involve extending the z-axis 179 00:09:11.539 --> 00:09:13.340 and follow a similar design like this 180 00:09:13.340 --> 00:09:17.419 Using these principles, we can construct the modeling matrix 181 00:09:17.419 --> 00:09:20.539 and calculate the TRS like this 182 00:09:20.539 --> 00:09:23.689 The process is not fundamentally different 183 00:09:23.689 --> 00:09:26.299 from what we explored in 2D matrices, 184 00:09:26.299 --> 00:09:28.918 but adapted for 3D space 185 00:09:28.918 --> 00:09:33.318 In this way, we have explored 186 00:09:33.318 --> 00:09:37.179 how to design transformation matrices in 3D space 187 00:09:37.179 --> 00:09:39.900 Now, let’s move on to discussing the camera and its setup 188 00:09:39.900 --> 00:09:43.470 It's not too different with the camera 189 00:09:43.470 --> 00:09:46.767 Finally, when designing the camera for 3D space, 190 00:09:46.767 --> 00:09:50.099 additional considerations arise 191 00:09:50.099 --> 00:09:52.353 or example, using the y-axis 192 00:09:52.353 --> 00:09:54.112 as the Up direction in 3D space, 193 00:09:54.112 --> 00:09:58.059 the z-axis for an object 194 00:09:58.059 --> 00:10:02.492 at the origin typically points toward the monitor, 195 00:10:02.492 --> 00:10:05.820 or towards us 196 00:10:05.820 --> 00:10:09.780 To observe an object properly, 197 00:10:09.780 --> 00:10:13.430 the camera should be positioned in the positive z-axis direction, 198 00:10:13.430 --> 00:10:15.860 facing the object 199 00:10:15.860 --> 00:10:19.710 For example, placing the camera at my position 200 00:10:19.710 --> 00:10:22.395 and pointing it toward the monitor 201 00:10:22.395 --> 00:10:24.340 means that the camera is not facing towards me 202 00:10:24.340 --> 00:10:27.780 If it is rotated 180 degrees, I towards the monitor, 203 00:10:27.780 --> 00:10:29.480 the object towards the monitor, 204 00:10:29.480 --> 00:10:30.820 it means it's facing towards me 205 00:10:30.820 --> 00:10:35.099 That's how we can face the front of the object 206 00:10:35.099 --> 00:10:38.349 If the camera is rotated 180 degrees, 207 00:10:38.349 --> 00:10:40.780 an issue arises 208 00:10:40.780 --> 00:10:44.530 where the x-axis of the camera’s coordinate system 209 00:10:44.530 --> 00:10:47.299 points to the left instead of the right 210 00:10:47.299 --> 00:10:50.599 This contradicts the standard convention 211 00:10:50.599 --> 00:10:53.380 where the x-axis should point 212 00:10:53.380 --> 00:10:55.739 to the right in the final rendered view 213 00:10:55.739 --> 00:10:57.189 Now that it's the left, 214 00:10:57.189 --> 00:10:59.989 it creates an uncomfortable experience for the viewer, 215 00:10:59.989 --> 00:11:02.419 as the output appears flipped 216 00:11:02.419 --> 00:11:06.179 To solve this, 217 00:11:06.179 --> 00:11:10.700 the camera’s coordinate system should be adjusted 218 00:11:10.700 --> 00:11:15.020 so that the x-axis points to the right, 219 00:11:15.020 --> 00:11:16.859 while the y axis stays there 220 00:11:16.859 --> 00:11:19.059 Therefore, in this camera setup, 221 00:11:19.059 --> 00:11:22.219 the final coordinate system 222 00:11:22.219 --> 00:11:27.119 must maintain the orthogonality 223 00:11:27.119 --> 00:11:28.859 of the three axes as originally defined 224 00:11:28.859 --> 00:11:31.359 So now, 225 00:11:31.359 --> 00:11:35.524 the camera is facing forward, 226 00:11:35.524 --> 00:11:40.780 but by rotating the y-axis 180 degrees, 227 00:11:40.780 --> 00:11:42.980 causing the x-axis to align to the right 228 00:11:42.980 --> 00:11:45.500 and the z-axis to point backward from the camera, 229 00:11:45.500 --> 00:11:50.829 This creates a right-handed coordinate system 230 00:11:50.829 --> 00:11:53.340 where the viewing direction 231 00:11:53.340 --> 00:11:56.690 now points in the opposite direction, 232 00:11:56.690 --> 00:11:57.659 behind the camera 233 00:11:57.659 --> 00:11:59.809 The x-axis and y-axis, 234 00:11:59.809 --> 00:12:04.219 which represent the important dimensions of the camera’s view, 235 00:12:04.219 --> 00:12:07.820 align with the standard directions we naturally perceive 236 00:12:07.820 --> 00:12:10.470 However, the z-axis points behind the camera, 237 00:12:10.470 --> 00:12:12.099 meaning the viewing direction corresponds 238 00:12:12.099 --> 00:12:16.099 to this reversed z-axis orientation 239 00:12:16.099 --> 00:12:21.299 To place our camera 240 00:12:21.299 --> 00:12:24.260 and construct a proper view coordinate system, 241 00:12:24.260 --> 00:12:28.860 the x and z axes must be flipped to match this convention 242 00:12:28.860 --> 00:12:32.099 That completes our view coordinate system 243 00:12:32.099 --> 00:12:37.438 Let's now create a view matrix 244 00:12:37.438 --> 00:12:39.780 which is responsible creating this view coordinate system 245 00:12:39.780 --> 00:12:42.180 In 2D, the view matrix was derived 246 00:12:42.180 --> 00:12:44.900 from the inverse of the camera’s transform matrix 247 00:12:44.900 --> 00:12:48.900 by first applying the translation 248 00:12:48.900 --> 00:12:53.140 and then reversing the rotation 249 00:12:53.140 --> 00:12:56.900 The same approach applies to 3D 250 00:12:56.900 --> 00:12:59.200 Translation is applied first, 251 00:12:59.200 --> 00:13:01.739 followed by the inverse rotation 252 00:13:01.739 --> 00:13:03.566 For rotation, the yaw rotation matrix is used, 253 00:13:03.566 --> 00:13:05.766 and its local axes are organized into columns, 254 00:13:05.766 --> 00:13:07.179 then transposed into rows to form the rotation’s inverse matrix 255 00:13:07.179 --> 00:13:13.099 The translation’s inverse matrix involves negating the x, y, and z components of the translation vector. 256 00:13:13.099 --> 00:13:14.699 So, the x, y, and z axes are 257 00:13:14.699 --> 00:13:15.999 initially arranged as columns 258 00:13:15.999 --> 00:13:18.820 So, the x, y, and z axes are arranged as columns 259 00:13:18.820 --> 00:13:23.120 This transposed matrix represents the inverse rotation matrix 260 00:13:23.120 --> 00:13:25.179 used for the camera transform 261 00:13:25.179 --> 00:13:27.020 For the translation inverse matrix, it’s straightforward 262 00:13:27.020 --> 00:13:29.570 As previously mentioned, you simply negate the x, y, 263 00:13:29.570 --> 00:13:31.820 and z components of the translation vector 264 00:13:31.820 --> 00:13:33.751 That gives you the translation inverse matrix 265 00:13:33.751 --> 00:13:38.451 You first apply the translation inverse, 266 00:13:38.451 --> 00:13:40.500 followed by the rotation inverse 267 00:13:40.500 --> 00:13:42.900 By multiplying these two matrices, 268 00:13:42.900 --> 00:13:47.550 the translation component becomes 269 00:13:47.550 --> 00:13:50.179 part of the result as a dot product 270 00:13:50.179 --> 00:13:54.700 At this stage, we need to add something 271 00:13:54.700 --> 00:13:58.020 If we stop here, this is what we get 272 00:13:58.020 --> 00:14:00.940 This is what we get if we stop here 273 00:14:00.940 --> 00:14:03.890 To fully convert the matrix into the view space, 274 00:14:03.890 --> 00:14:07.419 the x-axis and z-axis values must be inverted 275 00:14:07.419 --> 00:14:09.969 By reversing the x and z components 276 00:14:09.969 --> 00:14:11.979 in the original transform information, 277 00:14:11.979 --> 00:14:16.299 both the basic x and z values, 278 00:14:16.299 --> 00:14:19.099 as well as the corresponding elements 279 00:14:19.099 --> 00:14:21.299 in the dot product, are negated 280 00:14:21.299 --> 00:14:24.499 This adjustment produces 281 00:14:24.499 --> 00:14:26.700 this view coordinate system 282 00:14:26.700 --> 00:14:32.179 That was on the foundational setup for 3D space 283 00:14:32.179 --> 00:14:35.429 Next, I will demonstrate 284 00:14:35.429 --> 00:14:36.661 how to apply the view matrix to render a 3D cube 285 00:14:36.661 --> 00:14:38.419 using the program I created 286 00:14:38.419 --> 00:14:41.979 First, the object will be positioned at the origin point (0, 0, 0) 287 00:14:41.979 --> 00:14:43.629 You can imagine 288 00:14:43.629 --> 00:14:46.079 placing a rectangular cube on the monitor 289 00:14:46.079 --> 00:14:50.059 that you are currently looking at as the object being discussed 290 00:14:50.059 --> 00:14:54.059 Next, the object will be rotated 45 degrees around the y-axis 291 00:14:54.059 --> 00:14:56.539 and 60 degrees around the x-axis 292 00:14:56.539 --> 00:14:59.900 This means the object will first spin around the y-axis, 293 00:14:59.900 --> 00:15:03.639 like the rotation of a helicopter propeller, 294 00:15:03.639 --> 00:15:06.739 and then tilt by -60 degrees around the x-axis, 295 00:15:06.739 --> 00:15:09.074 something like this, 296 00:15:09.074 --> 00:15:10.780 as if for nodding 297 00:15:10.780 --> 00:15:14.448 These two rotations combined will result in a state 298 00:15:14.448 --> 00:15:17.299 where the object has been rotated in both directions 299 00:15:17.299 --> 00:15:19.299 After applying these rotations, the camera will 300 00:15:19.299 --> 00:15:21.419 be positioned at (0, 0, 500) 301 00:15:21.419 --> 00:15:25.607 This placement assumes the positive z-axis points outward 302 00:15:25.607 --> 00:15:27.340 from the monitor toward you, 303 00:15:27.340 --> 00:15:31.260 meaning the camera is essentially placed at your position 304 00:15:31.260 --> 00:15:34.910 Since the camera is facing the monitor, 305 00:15:34.910 --> 00:15:37.020 the view needs to be adjusted by a 180-degree rotation, 306 00:15:37.020 --> 00:15:39.320 in the y-axis, 307 00:15:39.320 --> 00:15:42.619 so that the camera can face the object 308 00:15:42.619 --> 00:15:45.369 This is the result 309 00:15:45.369 --> 00:15:48.059 of that scene we just created 310 00:15:48.059 --> 00:15:50.966 This concludes the demonstration 311 00:15:50.966 --> 00:15:54.059 of how to set up and configure a 3D scene 312 00:15:54.059 --> 00:15:57.459 The result displayed here shows 313 00:15:57.459 --> 00:16:00.709 the rectangular shape that appears slightly unnatural 314 00:16:00.709 --> 00:16:02.380 due to the lack of perspective applied 315 00:16:02.380 --> 00:16:04.580 In the upcoming section, we will explore 316 00:16:04.580 --> 00:16:08.180 methods to incorporate perspective into the scene 317 00:16:08.180 --> 00:16:11.059 and compare the resulting outputs 318 00:16:11.059 --> 00:16:15.020 This concludes the basic setups for the 3D space 319 00:16:15.215 --> 00:16:19.017 Euler Angles 320 00:16:20.158 --> 00:16:22.958 To understand Euler angles, 321 00:16:22.958 --> 00:16:26.658 we must first revisit how to handle rotations 322 00:16:26.658 --> 00:16:30.257 in 3D space, as discussed previously 323 00:16:30.257 --> 00:16:34.299 When constructing a rotation matrix, 324 00:16:34.299 --> 00:16:40.026 the standard basis vectors e_1 , e_2 , and e_3 325 00:16:40.026 --> 00:16:41.497 are transformed 326 00:16:41.497 --> 00:16:44.776 while preserving their original orthogonality, 327 00:16:44.776 --> 00:16:52.020 rotating the axes to result in this rotation matrix 328 00:16:52.020 --> 00:16:57.070 The transformed vectors, which are now defined 329 00:16:57.070 --> 00:17:00.570 as local X, local Y, and local Z, 330 00:17:00.570 --> 00:17:02.739 these three local vectors 331 00:17:02.739 --> 00:17:08.939 of x, y, and z 332 00:17:08.939 --> 00:17:10.904 are arranged as columns 333 00:17:10.904 --> 00:17:14.060 to create a matrix 334 00:17:14.060 --> 00:17:17.171 While constructing the rotation matrix is straightforward 335 00:17:17.171 --> 00:17:20.459 if the values of these transformed local axes are known, 336 00:17:20.459 --> 00:17:25.009 the challenge lies in determining 337 00:17:25.009 --> 00:17:27.900 the new local axis values after rotation 338 00:17:27.900 --> 00:17:31.800 If we want to rotate it by some angle, 339 00:17:31.800 --> 00:17:35.600 what is the value of each local axis 340 00:17:35.600 --> 00:17:39.410 that has been rotated? That is still a question 341 00:17:39.410 --> 00:17:41.560 For instance, if a game developer 342 00:17:41.560 --> 00:17:45.540 who is not familiar with math 343 00:17:45.540 --> 00:17:50.540 wants to rotate an object 30 degrees around the y-axis, 344 00:17:50.540 --> 00:17:54.540 with that command that resulted in the 30 degrees rotation, 345 00:17:54.540 --> 00:17:59.090 calculating the exact values of 346 00:17:59.090 --> 00:18:01.240 the local x, y, and z vectors after the rotation 347 00:18:01.240 --> 00:18:02.900 becomes a complex problem 348 00:18:02.900 --> 00:18:06.540 It could be a very complex problem, indeed 349 00:18:06.540 --> 00:18:09.340 The second issue arises 350 00:18:09.340 --> 00:18:12.859 when managing rotations using matrices 351 00:18:12.859 --> 00:18:14.659 As shown, a rotation matrix 352 00:18:14.659 --> 00:18:18.182 requires three 3D vectors, 353 00:18:18.182 --> 00:18:20.219 resulting in a total of nine data elements 354 00:18:20.219 --> 00:18:23.619 When issuing a simple command like 355 00:18:23.619 --> 00:18:25.869 rotate 30 degrees around the y-axis, 356 00:18:25.869 --> 00:18:30.140 determining how to correctly arrange and calculate 357 00:18:30.140 --> 00:18:33.890 these nine values can be cumbersome, 358 00:18:33.890 --> 00:18:36.819 especially in the developer's point of view 359 00:18:36.819 --> 00:18:40.119 From a developer’s perspective, 360 00:18:40.119 --> 00:18:41.893 a simpler method 361 00:18:41.893 --> 00:18:44.393 for representing rotations in 3D space 362 00:18:44.393 --> 00:18:46.380 is highly desirable 363 00:18:46.380 --> 00:18:49.699 his is where the Euler angle representation comes into play 364 00:18:49.699 --> 00:18:52.199 As shown on the screen, 365 00:18:52.199 --> 00:18:55.449 the Euler angle representation expresses rotations in 3D space 366 00:18:55.449 --> 00:18:58.739 by specifying the amount of rotation 367 00:18:58.739 --> 00:19:03.900 around the local x, y, and z axes 368 00:19:03.900 --> 00:19:07.597 The newly defined basis axes 369 00:19:07.597 --> 00:19:10.297 e1, e2, and e3 correspond to 370 00:19:10.297 --> 00:19:13.780 the standard basis vectors (1, 0, 0), (0, 1, 0), and (0, 0, 1) 371 00:19:13.780 --> 00:19:16.380 So they do not need to be explicitly included 372 00:19:16.380 --> 00:19:22.680 Instead, only the rotation values for these axes 373 00:19:22.680 --> 00:19:24.080 can represent the 3D rotations 374 00:19:24.080 --> 00:19:26.060 as the following, 375 00:19:26.060 --> 00:19:29.900 as theta_x, theta_y, and theta_z 376 00:19:29.900 --> 00:19:33.914 This approach significantly reduces complexity, 377 00:19:33.914 --> 00:19:35.514 as it replaces the need for nine matrix elements 378 00:19:35.514 --> 00:19:38.714 with just three values 379 00:19:38.714 --> 00:19:41.020 for representing rotations in 3D space 380 00:19:41.020 --> 00:19:45.520 In Unity, rotation values for each axis are managed 381 00:19:45.520 --> 00:19:48.020 using the Vector3 structure, 382 00:19:48.020 --> 00:19:50.020 while in Unreal Engine, 383 00:19:50.020 --> 00:19:53.780 rotations are handled through a Rotator structure 384 00:19:53.780 --> 00:19:56.291 A key distinction is that Unity 385 00:19:56.291 --> 00:19:58.307 uses x, y, and z values directly, 386 00:19:58.307 --> 00:20:02.120 whereas Unreal Engine employs Yaw, Pitch, and Roll 387 00:20:02.120 --> 00:20:06.440 to define rotations, 388 00:20:06.440 --> 00:20:08.699 which are modeled after airplane movements 389 00:20:08.699 --> 00:20:11.349 Let's talk more about 390 00:20:11.349 --> 00:20:13.080 the Yaw, Roll, and Pitch rotations 391 00:20:13.080 --> 00:20:15.720 Yaw, Pitch, and Roll are specific types of rotations 392 00:20:15.720 --> 00:20:19.973 based on how an object moves relative to its axes, 393 00:20:19.973 --> 00:20:21.923 often visualized 394 00:20:21.923 --> 00:20:23.920 using an airplane as you can see 395 00:20:23.920 --> 00:20:27.480 This is the rotation in an airplane 396 00:20:27.480 --> 00:20:30.530 We do not determine this 397 00:20:30.530 --> 00:20:32.320 as x, y, and z axis 398 00:20:32.320 --> 00:20:36.360 We instead determine the rotation based on the shape 399 00:20:36.360 --> 00:20:37.880 Let me explicate 400 00:20:37.880 --> 00:20:40.360 The Yaw rotation 401 00:20:40.360 --> 00:20:42.359 is rotating around the Up vector, 402 00:20:42.359 --> 00:20:44.263 akin to 403 00:20:44.263 --> 00:20:46.599 a helicopter propeller's rotation 404 00:20:46.599 --> 00:20:48.400 that we all know of 405 00:20:48.400 --> 00:20:51.819 That shape of rotation 406 00:20:51.819 --> 00:20:53.456 occurring in a 3D space 407 00:20:53.456 --> 00:20:55.599 is what we call a Yaw rotation 408 00:20:55.599 --> 00:20:58.472 As for the Pitch rotation, 409 00:20:58.472 --> 00:21:00.807 it rotates around the left-to-right axis, 410 00:21:00.807 --> 00:21:02.161 resembling 411 00:21:02.161 --> 00:21:04.879 a nodding motion like so 412 00:21:04.879 --> 00:21:08.457 The Roll rotation happens around the forward axis, 413 00:21:08.457 --> 00:21:10.107 where the object spins 414 00:21:10.107 --> 00:21:11.768 like a barrel roll 415 00:21:11.768 --> 00:21:15.239 These three types of rotation define how objects move in 3D space 416 00:21:15.239 --> 00:21:18.160 If the rotation occurs around the Up vector, it is referred to as Yaw 417 00:21:18.160 --> 00:21:21.460 If the rotation occurs around the left-right axis 418 00:21:21.460 --> 00:21:23.680 with a nodding motion, it is Pitch 419 00:21:23.680 --> 00:21:25.718 Finally, if the rotation happens around the forward axis, 420 00:21:25.718 --> 00:21:27.919 it is Roll 421 00:21:27.919 --> 00:21:32.040 Regardless of which axes (x, y, z) are used, 422 00:21:32.040 --> 00:21:35.360 the shapes of the rotations remain consistent 423 00:21:35.360 --> 00:21:42.320 This consistency allows for easier exchange of rotation data 424 00:21:42.320 --> 00:21:44.360 between different programs that use varying 3D coordinate systems 425 00:21:44.360 --> 00:21:46.134 By standardizing rotations 426 00:21:46.134 --> 00:21:48.080 with Yaw, Pitch, and Roll based on these rotational shapes, 427 00:21:48.080 --> 00:21:51.880 it becomes much clearer 428 00:21:51.880 --> 00:21:54.599 and more precise to share rotational information 429 00:21:54.599 --> 00:21:56.699 across different 430 00:21:56.699 --> 00:21:59.879 systems or applications 431 00:21:59.879 --> 00:22:05.056 For us, Yaw, Roll and Pitch are the following 432 00:22:05.056 --> 00:22:08.156 Our coordinate system is the right-hand one 433 00:22:08.156 --> 00:22:10.112 The left-hand one does not matter here 434 00:22:10.112 --> 00:22:12.395 So for each of x, y, and x axis, 435 00:22:12.395 --> 00:22:14.800 we can assign Yaw, Roll, and Pitch 436 00:22:14.800 --> 00:22:16.550 In the context of a Y-up coordinate system, 437 00:22:16.550 --> 00:22:18.679 Yaw corresponds to rotation around the y-axis 438 00:22:18.679 --> 00:22:20.639 or the vertical axis 439 00:22:20.639 --> 00:22:24.449 Now the x axis is the left-right, while the z is the forward-backward 440 00:22:24.449 --> 00:22:27.599 Pitch corresponds to rotation around the x-axis 441 00:22:27.599 --> 00:22:30.600 Roll corresponds to rotation around the z-axis 442 00:22:30.600 --> 00:22:35.350 That's how each of them is assigned 443 00:22:35.350 --> 00:22:37.240 in our program 444 00:22:37.240 --> 00:22:39.052 The Yaw, Pitch, and Roll convention 445 00:22:39.052 --> 00:22:42.093 originally came from aeronautics, 446 00:22:42.093 --> 00:22:45.079 adopted in mechanical engineering 447 00:22:45.079 --> 00:22:48.119 over time with the original methods 448 00:22:48.119 --> 00:22:50.819 and later became a standard in computer graphics, 449 00:22:50.819 --> 00:22:53.904 where it is still widely used today 450 00:22:53.904 --> 00:22:55.534 As previously mentioned, 451 00:22:55.534 --> 00:22:58.279 different programs may use axes differently, 452 00:22:58.279 --> 00:23:00.629 but representing rotations based on their shapes 453 00:23:00.629 --> 00:23:02.839 ensures that the rotation information 454 00:23:02.839 --> 00:23:05.919 can be clearly exchanged between systems 455 00:23:05.919 --> 00:23:09.080 That's the major advantage 456 00:23:09.080 --> 00:23:13.759 Ultimately, Euler angles 457 00:23:13.759 --> 00:23:17.309 need to be converted 458 00:23:17.309 --> 00:23:19.191 into rotation matrices, why? 459 00:23:19.191 --> 00:23:22.279 To create a TRS (Translation, Rotation, Scaling) matrix, 460 00:23:22.279 --> 00:23:25.960 a rotation matrix is necessary 461 00:23:25.960 --> 00:23:28.759 Even though Euler angles are user-friendly, 462 00:23:28.759 --> 00:23:31.309 for operations involving a large number of points 463 00:23:31.309 --> 00:23:33.360 like tens of thousands or millions, 464 00:23:33.360 --> 00:23:34.800 matrices are essential for efficient transformations 465 00:23:34.800 --> 00:23:37.960 Therefore, based on the information of the Euler angle, 466 00:23:37.960 --> 00:23:40.000 creating rotation matrix is necessary 467 00:23:40.000 --> 00:23:42.320 Let's dive deeper into it 468 00:23:42.320 --> 00:23:44.479 First, Euler angles 469 00:23:44.479 --> 00:23:46.979 do not represent 470 00:23:46.979 --> 00:23:48.639 a single instantaneous rotation 471 00:23:48.639 --> 00:23:52.720 It's not an instantaneous thing 472 00:23:52.720 --> 00:23:54.870 Instead, they describe a sequence 473 00:23:54.870 --> 00:23:57.600 of three rotations, each around a local axis 474 00:23:57.600 --> 00:23:59.759 First, the object is rotated around the x-axis 475 00:23:59.759 --> 00:24:04.199 After this rotation, the local y- and z-axes shift to new positions 476 00:24:04.199 --> 00:24:07.149 Now based on its new local axes, 477 00:24:07.149 --> 00:24:08.600 the object is rotated around the y-axis 478 00:24:08.600 --> 00:24:13.399 Finally, the object is rotated around the z-axis, again using its updated local axes 479 00:24:13.399 --> 00:24:17.000 This sequence of rotations, broken into three steps, 480 00:24:17.000 --> 00:24:20.279 intuitively represents 3D rotations 481 00:24:20.279 --> 00:24:24.640 I say intuitive for users, 482 00:24:24.640 --> 00:24:27.040 but in terms of theory, it involves 483 00:24:27.040 --> 00:24:30.407 a layered transformation process 484 00:24:30.407 --> 00:24:31.839 That's how it works, essentially 485 00:24:31.839 --> 00:24:37.600 So the order of these opretaions is critical 486 00:24:37.600 --> 00:24:42.160 x, y, and z, or Yaw, Roll, and Pitch 487 00:24:42.160 --> 00:24:44.799 These three rotations, Yaw, Pitch, and Roll, 488 00:24:44.799 --> 00:24:48.399 are applied one by one 489 00:24:48.399 --> 00:24:51.239 Depending on the chosen order, 490 00:24:51.239 --> 00:24:54.239 six possible cases of applying the rotations can occur, 491 00:24:54.239 --> 00:24:57.079 of which we need to choose one 492 00:24:57.079 --> 00:25:00.689 To determine the order of applying 493 00:25:00.689 --> 00:25:02.359 rotations to the local axes, 494 00:25:02.359 --> 00:25:04.920 a common sequence 495 00:25:04.920 --> 00:25:08.200 is Roll, Pitch, 496 00:25:08.200 --> 00:25:12.239 and then Yaw, in that order 497 00:25:12.239 --> 00:25:15.239 This method is widely adopted in game engines 498 00:25:15.239 --> 00:25:18.399 such as Unreal Engine and Unity, 499 00:25:18.399 --> 00:25:20.359 making it the standard approach 500 00:25:20.359 --> 00:25:22.279 for handling Euler angles 501 00:25:22.279 --> 00:25:25.000 If you are wondering 502 00:25:25.000 --> 00:25:27.119 how to remember this order, 503 00:25:27.119 --> 00:25:30.320 think of the process 504 00:25:30.320 --> 00:25:32.000 as similar to controlling an airplane 505 00:25:32.000 --> 00:25:33.160 First, the airplane stabilizes 506 00:25:33.160 --> 00:25:35.440 its horizontal orientation to be able to fly 507 00:25:35.440 --> 00:25:39.760 by rolling around its forward axis 508 00:25:39.760 --> 00:25:43.279 Next, to fly upward, 509 00:25:43.279 --> 00:25:44.959 the airplane nods 510 00:25:44.959 --> 00:25:46.519 upward or downward 511 00:25:46.519 --> 00:25:49.640 by pitching around its left-right axis 512 00:25:49.640 --> 00:25:51.399 Finally, to steer toward the destination, 513 00:25:51.399 --> 00:25:53.600 the airplane turns left or right 514 00:25:53.600 --> 00:25:55.600 by yawing around its vertical axis 515 00:25:55.600 --> 00:25:58.959 This sequence,stabilize the roll, adjust the pitch, 516 00:25:58.959 --> 00:26:00.640 and steer with yaw, 517 00:26:00.640 --> 00:26:02.799 matches the order 518 00:26:02.799 --> 00:26:07.320 Roll, Pitch, and Yaw, 519 00:26:07.320 --> 00:26:11.760 making it intuitive for applications 520 00:26:11.760 --> 00:26:15.359 Once the order is set, 521 00:26:15.359 --> 00:26:17.259 the next step involves 522 00:26:17.259 --> 00:26:19.679 calculating the rotation matrix 523 00:26:19.679 --> 00:26:23.279 based on this sequence 524 00:26:23.279 --> 00:26:25.200 Each axis's rotation matrix 525 00:26:25.200 --> 00:26:27.799 will be derived like so 526 00:26:27.799 --> 00:26:30.040 The rotation matrix for the x-axis 527 00:26:30.040 --> 00:26:33.559 means x is the basis 528 00:26:33.559 --> 00:26:35.859 that represents a rotation 529 00:26:35.859 --> 00:26:37.519 around the x-axis, 530 00:26:37.519 --> 00:26:41.040 where the x-axis itself remains unchanged 531 00:26:41.040 --> 00:26:44.920 In this case, only the y- and z-axes undergo rotation, 532 00:26:44.920 --> 00:26:48.279 without the x axis rotating, 533 00:26:48.279 --> 00:26:50.640 effectively describing a planar rotation within the yz-plane 534 00:26:50.640 --> 00:26:52.760 For the x, y, and z axis, 535 00:26:52.760 --> 00:26:56.239 Since I'm a right-handed person, like this, 536 00:26:56.239 --> 00:27:01.040 let's think about a yz plane based on this x axis 537 00:27:01.040 --> 00:27:07.079 In a right-handed coordinate system, 538 00:27:07.079 --> 00:27:13.079 y axis is Up, x axis is Left-Right, and z axis, Forward-Backward 539 00:27:13.079 --> 00:27:16.239 This right-handed positioning 540 00:27:16.239 --> 00:27:18.489 is the 3D coordinate 541 00:27:18.489 --> 00:27:20.320 that my program uses 542 00:27:20.320 --> 00:27:23.160 For a rotation about the x-axis, 543 00:27:23.160 --> 00:27:26.480 for this rotation, 544 00:27:26.480 --> 00:27:29.839 the yz-plane rotates, 545 00:27:29.839 --> 00:27:32.839 with the direction of rotation 546 00:27:32.839 --> 00:27:36.539 being from the y-axis 547 00:27:36.539 --> 00:27:38.239 toward the z-axis 548 00:27:38.239 --> 00:27:43.079 When looking at the rotation matrix for the y- and z-axes, 549 00:27:43.079 --> 00:27:48.244 it includes cosine and negative sine components, 550 00:27:48.244 --> 00:27:50.178 which form the basis of the rotation matrix 551 00:27:50.178 --> 00:27:53.600 Thus, for the x-axis rotation matrix, it can be represented in this way 552 00:27:53.600 --> 00:27:56.119 Moving on to the rotation matrix for the y-axis, 553 00:27:56.119 --> 00:27:59.399 the y-axis remains unchanged 554 00:27:59.399 --> 00:28:00.999 What’s critical here 555 00:28:00.999 --> 00:28:04.920 is whether this y axis rotation 556 00:28:04.920 --> 00:28:08.600 goes from the x-axis to the z-axis or vice versa 557 00:28:08.600 --> 00:28:13.239 It's determining the sequence of rotation within the plane 558 00:28:13.239 --> 00:28:17.239 When the rotation is based on the y-axis, it starts from the z-axis 559 00:28:17.239 --> 00:28:20.559 and moves to the x-axis, forming the zx-plane rotation 560 00:28:20.559 --> 00:28:24.362 If you list the sequence x, y, z repeatedly, 561 00:28:24.362 --> 00:28:26.440 like so, 562 00:28:26.440 --> 00:28:29.720 and you rotate about the x-axis, the remaining plane is yz 563 00:28:29.720 --> 00:28:32.679 Then, for the y-axis, 564 00:28:32.679 --> 00:28:35.200 the sequence becomes zx, 565 00:28:35.200 --> 00:28:37.679 and for the z-axis, it becomes xy 566 00:28:37.679 --> 00:28:42.280 This is how the order of rotations is determined when designing the matrices 567 00:28:42.280 --> 00:28:44.799 Because it moves from zx, 568 00:28:44.799 --> 00:28:48.919 it effectively flips the xz-plane, 569 00:28:48.919 --> 00:28:51.238 creating a transposed matrix 570 00:28:51.238 --> 00:28:52.280 It's a flip 571 00:28:52.280 --> 00:28:56.380 This inversion results in the rotation matrix for the y-axis 572 00:28:56.380 --> 00:28:58.416 having a negative sign 573 00:28:58.416 --> 00:29:00.280 in the lower-left corner 574 00:29:00.280 --> 00:29:03.200 It’s easy to get confused, 575 00:29:03.200 --> 00:29:05.479 so it’s important to understand this clearly 576 00:29:05.479 --> 00:29:08.359 For the z-axis rotation, it starts with the xy-plane, 577 00:29:08.359 --> 00:29:11.659 and its rotation 578 00:29:11.659 --> 00:29:15.067 behaves consistently as expected 579 00:29:15.067 --> 00:29:17.840 In this context, the y-axis corresponds to Yaw, 580 00:29:17.840 --> 00:29:21.389 the x-axis corresponds to Pitch, and the z-axis corresponds to Roll 581 00:29:21.389 --> 00:29:25.317 Since we apply the rotations in the order Roll, Pitch, and Yaw, 582 00:29:25.317 --> 00:29:28.617 Yaw is applied last, 583 00:29:28.617 --> 00:29:30.039 which places its rotation matrix at the far left 584 00:29:30.039 --> 00:29:31.880 R_y by 585 00:29:31.880 --> 00:29:34.039 Roll, being the first applied, goes on the far right, 586 00:29:34.039 --> 00:29:38.439 making the order of matrix multiplication 587 00:29:38.439 --> 00:29:41.735 R_y×R_x×R_z 588 00:29:41.735 --> 00:29:44.835 If Yaw, Pitch, and Roll are represented 589 00:29:44.835 --> 00:29:46.960 as α, β, and γ, respectively, 590 00:29:46.960 --> 00:29:50.119 each rotation matrix can be computed 591 00:29:50.119 --> 00:29:54.080 and multiplied to yield the final result 592 00:29:54.080 --> 00:29:57.000 Although this composite rotation matrix is lengthy, 593 00:29:57.000 --> 00:30:00.520 it represents the 3D rotation derived from Euler angles effectively 594 00:30:00.520 --> 00:30:02.919 So, this is what it is, 595 00:30:02.919 --> 00:30:05.469 the 3D rotation matrix 596 00:30:05.469 --> 00:30:10.080 derived from Euler angles 597 00:30:10.080 --> 00:30:12.530 The calculated rotation matrix 598 00:30:12.530 --> 00:30:15.479 is identical to the rotation matrix for 3D space 599 00:30:15.479 --> 00:30:18.440 The column vectors here 600 00:30:18.440 --> 00:30:23.080 are the rotated results 601 00:30:23.080 --> 00:30:27.880 of the local x, y, and z axes 602 00:30:27.880 --> 00:30:29.000 That's what it is 603 00:30:29.000 --> 00:30:32.550 If you take this part 604 00:30:32.550 --> 00:30:35.099 and extract it as a vector, it becomes the local x-axis 605 00:30:35.099 --> 00:30:37.000 If you take this part, it becomes the local y-axis 606 00:30:37.000 --> 00:30:40.559 Lastly, taking this part gives you the local z-axis 607 00:30:40.559 --> 00:30:44.599 In game design, 608 00:30:44.599 --> 00:30:47.799 this allows us to specify 609 00:30:47.799 --> 00:30:50.719 a desired 3D space like this 610 00:30:50.719 --> 00:30:53.520 Now, while this resolves two problems, 611 00:30:53.520 --> 00:30:56.000 Euler angles still have their own limitations 612 00:30:56.000 --> 00:30:58.239 Let’s take a look at this 613 00:30:58.239 --> 00:31:01.400 It might seem like a perfect solution, 614 00:31:01.400 --> 00:31:05.159 but there is a fundamental limitation to Euler angles 615 00:31:05.159 --> 00:31:06.799 As I explained earlier, 616 00:31:06.799 --> 00:31:10.719 if they look straight ahead and apply a Roll rotation, 617 00:31:10.719 --> 00:31:14.239 the face rotates, right? 618 00:31:14.239 --> 00:31:16.467 The face, or your nose as the center, 619 00:31:16.467 --> 00:31:18.760 turns sideways like this 620 00:31:18.760 --> 00:31:21.060 Then, if I apply a Pitch rotation 621 00:31:21.060 --> 00:31:22.239 about theneck, 622 00:31:22.239 --> 00:31:24.599 then it goes this way 623 00:31:24.599 --> 00:31:27.719 After this Pitch rotation, 624 00:31:27.719 --> 00:31:32.019 when I proceed to the Roll, Pitch, and Yaw rotations, 625 00:31:32.019 --> 00:31:33.640 and continue, 626 00:31:33.640 --> 00:31:35.840 what happens with the Yaw rotation? 627 00:31:35.840 --> 00:31:38.559 The face rotates around its center again, 628 00:31:38.559 --> 00:31:40.009 around the face 629 00:31:40.009 --> 00:31:41.880 It's rotating around the center of the face 630 00:31:41.880 --> 00:31:45.479 This is the replica, 631 00:31:45.479 --> 00:31:48.239 the exact same result 632 00:31:48.239 --> 00:31:51.139 as the initial Roll rotation 633 00:31:51.139 --> 00:31:52.440 as we've seen here 634 00:31:52.440 --> 00:31:56.200 Essentially, the rotations from two axes 635 00:31:56.200 --> 00:31:59.200 end up being used for rotating the face, 636 00:31:59.200 --> 00:32:02.559 This means that a rotation that should involve three axes 637 00:32:02.559 --> 00:32:06.000 becomes 638 00:32:06.000 --> 00:32:10.520 unnaturally constrained to two axes, 639 00:32:10.520 --> 00:32:13.239 resulting in an inability to properly represent the rotation 640 00:32:13.239 --> 00:32:16.960 This phenomenon is called gimbal lock 641 00:32:16.960 --> 00:32:19.660 To demonstrate this, 642 00:32:19.660 --> 00:32:21.440 let’s look at a simple example 643 00:32:21.440 --> 00:32:23.559 In this demonstration, as the object rotates freely, 644 00:32:23.559 --> 00:32:26.840 there’s a specific condition 645 00:32:26.840 --> 00:32:31.280 Here, despite using different keys for control, 646 00:32:31.280 --> 00:32:32.960 the same rotation is applied 647 00:32:32.960 --> 00:32:35.400 You can see that both the Yaw and Roll rotations are continuously changing, 648 00:32:35.400 --> 00:32:38.640 but in the end, they only affect the face's rotation 649 00:32:38.640 --> 00:32:40.080 Even when pressing 650 00:32:40.080 --> 00:32:42.919 separate keys for Yaw or Roll, 651 00:32:42.919 --> 00:32:44.960 both seem to control the same motion 652 00:32:44.960 --> 00:32:48.200 As a result, 653 00:32:48.200 --> 00:32:49.650 the freedom to express rotation 654 00:32:49.650 --> 00:32:51.679 becomes severely limited in this situation 655 00:32:51.679 --> 00:32:54.760 This phenomenon can occur occasionally, 656 00:32:54.760 --> 00:32:57.679 but detecting the exact moment it happens 657 00:32:57.679 --> 00:32:59.000 is very challenging 658 00:32:59.000 --> 00:33:04.559 To prevent this issue, 659 00:33:04.559 --> 00:33:07.400 developers need to write defensive code, 660 00:33:07.400 --> 00:33:11.080 making it difficult 661 00:33:11.080 --> 00:33:13.039 to safely implement rotation 662 00:33:13.039 --> 00:33:16.339 Euler angles 663 00:33:16.339 --> 00:33:17.559 work fine when the object is static, 664 00:33:17.559 --> 00:33:19.559 or when the rotation doesn’t change 665 00:33:19.559 --> 00:33:22.919 It’s effective for representing fixed rotations 666 00:33:22.919 --> 00:33:27.080 However, when the rotation dynamically changes and shifts freely, 667 00:33:27.080 --> 00:33:30.559 unexpected situations like gimbal lock can occur, 668 00:33:30.559 --> 00:33:32.640 making it very tricky to handle 669 00:33:32.640 --> 00:33:37.159 Thus, while setting fixed angles 670 00:33:37.159 --> 00:33:38.274 for static objects 671 00:33:38.274 --> 00:33:41.080 in engines is fine, like this 672 00:33:41.080 --> 00:33:44.400 since we’re assigning values without movement 673 00:33:44.400 --> 00:33:46.333 Euler angles pose critical problems 674 00:33:46.333 --> 00:33:49.320 when it comes to objects 675 00:33:49.320 --> 00:33:51.559 that need to rotate freely 676 00:33:51.559 --> 00:33:53.320 That's one 677 00:33:53.320 --> 00:33:57.559 The second issue is interpolation of rotations 678 00:33:57.559 --> 00:34:01.400 When we rotate an object using Euler angles along one axis, 679 00:34:01.400 --> 00:34:04.960 such as a Yaw rotation by 15 degrees 680 00:34:04.960 --> 00:34:08.159 followed by another Yaw rotation by 30 degrees, 681 00:34:08.159 --> 00:34:13.679 the result is intuitively a Yaw rotation of 45 degrees 682 00:34:13.679 --> 00:34:16.719 In terms of rotation, this means 683 00:34:16.719 --> 00:34:20.280 a 15-degree rotation plus a 30-degree rotation equals a 45-degree rotation 684 00:34:20.280 --> 00:34:24.119 If we represent this as R_2 and R_1, 685 00:34:24.119 --> 00:34:26.569 combining a 15-degree and 30-degree rotation 686 00:34:26.569 --> 00:34:29.239 should logically result 687 00:34:29.239 --> 00:34:30.919 in a 45-degree rotation 688 00:34:30.919 --> 00:34:33.419 Mathematically, 689 00:34:33.419 --> 00:34:34.599 this holds true because, 690 00:34:34.599 --> 00:34:40.159 for Euler angles, only one axis rotates 691 00:34:40.159 --> 00:34:42.119 while the others remain stationary 692 00:34:42.119 --> 00:34:44.719 Since the other axes contribute nothing to the rotation, or 0 degrees, 693 00:34:44.719 --> 00:34:47.479 so that's a Roll rotation 694 00:34:47.479 --> 00:34:50.479 For Pitch rotation, 695 00:34:50.479 --> 00:34:53.520 It's treated as an identity matrix, or I 696 00:34:53.520 --> 00:34:58.159 So the related things here use I 697 00:34:58.159 --> 00:35:00.315 Ultimately, these two matrices 698 00:35:00.315 --> 00:35:02.359 result in the same conclusion 699 00:35:02.359 --> 00:35:04.759 By adding two angles, 700 00:35:04.759 --> 00:35:06.798 we can create a new angle 701 00:35:06.798 --> 00:35:09.880 This demonstrates that interpolation is valid 702 00:35:09.880 --> 00:35:13.679 If the sum of these two angles results in the same outcome, 703 00:35:13.679 --> 00:35:15.840 for example, 704 00:35:15.840 --> 00:35:19.760 if we interpolate halfway, 705 00:35:19.760 --> 00:35:22.039 we only need to include half of each angle 706 00:35:22.039 --> 00:35:27.599 This allows us to determine the angle at any proportion 707 00:35:27.599 --> 00:35:30.840 between the start and end, 708 00:35:30.840 --> 00:35:34.159 making partial rotation possible 709 00:35:34.159 --> 00:35:39.200 However, if more than two rotations 710 00:35:39.200 --> 00:35:42.919 are involved and angles are applied simultaneously, 711 00:35:42.919 --> 00:35:44.919 issues arise at this point 712 00:35:44.919 --> 00:35:48.869 In such cases, 713 00:35:48.869 --> 00:35:50.599 the previously valid equations no longer hold 714 00:35:50.599 --> 00:35:54.599 For example, if you apply both a roll rotation and a yaw rotation, 715 00:35:54.599 --> 00:36:01.520 the 45-degree rotation represented as R_yaw3×R_roll3 716 00:36:01.520 --> 00:36:06.280 differs from the outcome of applying each rotation 717 00:36:06.280 --> 00:36:07.520 separately, by 30, right? 718 00:36:07.520 --> 00:36:11.579 By 15 degrees or 30 degrees 719 00:36:11.579 --> 00:36:15.119 This is Ru3×Rl3 720 00:36:15.119 --> 00:36:23.559 While this is R_yaw2, R_roll2, R_yaw1, R_roll1 721 00:36:23.559 --> 00:36:25.463 For the angles to align, 722 00:36:25.463 --> 00:36:28.320 rotations must follow the same axis and sequence 723 00:36:28.320 --> 00:36:31.479 However, since roll and yaw 724 00:36:31.479 --> 00:36:33.039 alternate across different axes, 725 00:36:33.039 --> 00:36:37.290 their summed rotations 726 00:36:37.290 --> 00:36:40.390 do not guarantee consistent results 727 00:36:40.390 --> 00:36:41.479 for their rotations 728 00:36:41.479 --> 00:36:45.239 Consequently, the results differ 729 00:36:45.239 --> 00:36:49.679 This inconsistency makes interpolating Euler angles with more than two rotations 730 00:36:49.679 --> 00:36:52.200 challenging and impractical 731 00:36:52.200 --> 00:36:57.250 Since these rotations cannot be expressed as a simple sum of angles, 732 00:36:57.250 --> 00:36:58.239 the process becomes more complex 733 00:36:58.239 --> 00:37:00.939 For instance, 734 00:37:00.939 --> 00:37:02.520 in animations, 735 00:37:02.520 --> 00:37:05.560 let's say that we're going for some 736 00:37:05.560 --> 00:37:07.640 animation work in a timeframe 737 00:37:07.640 --> 00:37:11.240 if you simply define a starting and ending angle 738 00:37:11.240 --> 00:37:13.560 to create a smooth transition 739 00:37:13.560 --> 00:37:15.680 with keyframes in between 740 00:37:15.680 --> 00:37:18.359 this approach fails with Euler angles 741 00:37:18.359 --> 00:37:22.560 Instead, you need to use methods like axis-angle rotation, where a specific axis is defined, 742 00:37:22.560 --> 00:37:27.599 and rotation occurs around it 743 00:37:27.599 --> 00:37:30.920 to interpolate between the start and end rotations 744 00:37:30.920 --> 00:37:35.538 Common techniques for this include Rodrigues’ rotation formula or quaternions 745 00:37:35.538 --> 00:37:38.388 However, in this session, 746 00:37:38.388 --> 00:37:42.359 we will focus solely on Euler angles 747 00:37:42.359 --> 00:37:45.719 We explored how Euler angles are used 748 00:37:45.719 --> 00:37:48.920 to define rotations in 3D space and their limitations 749 00:37:48.920 --> 00:37:51.079 This concludes today’s lecture 750 00:37:51.079 --> 00:37:53.000 Thank you for your hard work 751 00:37:53.000 --> 00:37:53.973 Thank you 752 00:37:54.489 --> 00:37:55.679 Design of 3D Space 3D space is divided into left and right-handed coordinate systems, defined by three axes Here, we use the right-handed Y-up 753 00:37:55.679 --> 00:37:56.813 3D Transform Setup The rotation mechanism: M=T·R·S= [x_x·s_x y_x·s_y z_x·s_z t_x] 754 00:37:56.813 --> 00:37:57.870 [x_y·s_x y_y·s_y z_y·s_z t_y] [x_z·s_x y_z·s_y z_z·s_z t_z] [ 0 0 0 1 ] 755 00:37:57.870 --> 00:37:58.977 3D Camera System To view the world from the camera's perspective, the x-axis points to the right 756 00:37:58.977 --> 00:37:59.996 Rotating the y-axis 180 degrees aligns the screen's axes with a Cartesian system Flipp x and y axes to create the view coordinate 757 00:37:59.996 --> 00:38:01.043 View Matrix Construction V= [-x_x -x_y -x_x x·y] [y_x y_y y_z -y·t] [-z_x -z_y -z_z z·t] [ 0 0 0 1 ] 758 00:38:01.043 --> 00:38:02.743 Euler angle representation Rotation matrix: local vectors in columns Rotations are expressed with three angles 759 00:38:02.743 --> 00:38:04.443 Unity Engine uses x, y, z in a Vector3 structure, while Unreal Engine uses Yaw, Roll, Pitch in a Rotator structure 760 00:38:04.443 --> 00:38:06.143 Yaw, Roll, Pitch Rotation Yaw: Rotation around the up vector, resembling a propeller 761 00:38:06.143 --> 00:38:07.834 Roll: Rotation about the forward axis Pitch: Rotation about the side axis, like nodding 762 00:38:07.834 --> 00:38:08.786 Euler Angle Application Order Roll→Pitch→Yaw Rotation Matrix for Euler Angles R= [cos_α·cos_γ+sin_α·sin_β·sin_γ·cos_β·sin_γ 763 00:38:08.786 --> 00:38:09.758 -cos_a·sin_γ+sin_α·sin_β·cos_γ·cos_β·cos_γ sin_α·cos_β-sin_β] 764 00:38:09.758 --> 00:38:10.691 [-sin_α·cos_γ+cos_α·sin_β·sin_γ sin_α·sin_γ+cos_α·sin_β·cos_γ cos_α·cos_β] Local Vectors with Euler Angles 765 00:38:10.691 --> 00:38:11.669 x_local=(cos_α·cos_γ+sin_α·sin_β·sin_γ, cos_β·sin_γ, -sin_α·cos_γ+cos_α·sin_β·sin_γ) 766 00:38:11.669 --> 00:38:12.597 y_local=(-cos_a·sin_γ+sin_α·sin_β·cos_γ, cos_β·cos_γ, -sin_α·sin_γ+cos_α·sin_β·cos_γ) 767 00:38:12.597 --> 00:38:13.465 z_local=(sin_α·cos_β, -sin_β, cos_α·cos_β) Issues with Euler Angles 768 00:38:13.465 --> 00:38:14.325 Gimbal Lock: Two axes align under certain conditions Interpolation of Rotation: Euler angles make interpolation difficult with many axes