WEBVTT 1 00:00:06.144 --> 00:00:09.837 Game Basics Mathematics for 3D Games Part 2: Cross Product of Vectors 2 00:00:27.950 --> 00:00:29.531 Hello, everyone 3 00:00:29.531 --> 00:00:31.521 This is Lee Deuk-woo from Game Mathematics 4 00:00:31.521 --> 00:00:34.370 In this session, we will take a look at an important operation on vectors 5 00:00:34.370 --> 00:00:36.641 which is the cross product 6 00:00:36.641 --> 00:00:38.670 We will explore the cross product operation 7 00:00:38.670 --> 00:00:42.490 and its properties 8 00:00:42.490 --> 00:00:46.539 Next, we will compare the differences 9 00:00:46.539 --> 00:00:49.710 between the cross product and the cross product operation 10 00:00:49.710 --> 00:00:52.540 Finally, we’ll look at various ways 11 00:00:52.540 --> 00:00:54.804 to apply the cross product 12 00:00:55.680 --> 00:00:59.205 The Cross Product Operation 13 00:00:59.788 --> 00:01:03.995 Let’s start by understanding the cross product operation 14 00:01:03.995 --> 00:01:05.669 The cross product operation 15 00:01:05.669 --> 00:01:08.360 can only be performed in three-dimensional space, 16 00:01:08.360 --> 00:01:11.080 meaning it applies exclusively 17 00:01:11.080 --> 00:01:13.510 to 3D vectors 18 00:01:13.510 --> 00:01:16.639 The result of the cross product 19 00:01:16.639 --> 00:01:19.084 unlike the dot product 20 00:01:19.084 --> 00:01:20.767 is a vector value 21 00:01:20.767 --> 00:01:23.539 The dot product yields a scalar value, 22 00:01:23.539 --> 00:01:27.060 but the cross product produces a vector 23 00:01:27.060 --> 00:01:29.599 The operation is performed in 3D space 24 00:01:29.599 --> 00:01:32.839 on 3D vectors 25 00:01:32.839 --> 00:01:35.839 and the result is also a 3D vector 26 00:01:35.839 --> 00:01:37.529 So, let’s explore how the cross product operation 27 00:01:37.529 --> 00:01:40.320 is performed 28 00:01:40.320 --> 00:01:43.199 Here, when performing the cross product of an arbitrary vector, u 29 00:01:43.199 --> 00:01:46.400 and another arbitrary vector v 30 00:01:46.400 --> 00:01:49.559 For the first component, x, 31 00:01:49.559 --> 00:01:53.780 you exclude x and use the y and z components 32 00:01:53.780 --> 00:01:57.000 instead and proceed 33 00:01:57.000 --> 00:02:01.040 The first step in calculating the cross product of u and v 34 00:02:01.040 --> 00:02:06.120 is to take uy, vz in order. 35 00:02:06.120 --> 00:02:09.039 Then, you put a minus 36 00:02:09.039 --> 00:02:11.160 and reverse the product 37 00:02:11.160 --> 00:02:14.830 Thus, vy and uz is subtracted 38 00:02:14.830 --> 00:02:17.520 which is a key characteristic of the cross product operation 39 00:02:17.520 --> 00:02:19.800 Next, let’s look at the second component 40 00:02:19.800 --> 00:02:21.560 The second component is y 41 00:02:21.560 --> 00:02:24.130 so you exclude y and use the other two components 42 00:02:24.130 --> 00:02:28.320 We follow the cyclic order x,y,z,x,y,z, as previously mentioned 43 00:02:28.320 --> 00:02:30.440 Excluding y 44 00:02:30.440 --> 00:02:33.559 the sequence proceeds as z, x 45 00:02:33.559 --> 00:02:37.039 First, calculate uz and vx 46 00:02:37.039 --> 00:02:40.000 Then, subtract the reverse product 47 00:02:40.000 --> 00:02:46.520 for vz ux 48 00:02:46.520 --> 00:02:50.928 Finally, for the z-component 49 00:02:50.928 --> 00:02:54.898 the sequence proceeds as x,y 50 00:02:54.898 --> 00:02:58.729 First, calculate ux*vy 51 00:02:58.729 --> 00:03:01.759 Then, subtract the reverse product 52 00:03:01.759 --> 00:03:04.390 vx*uy 53 00:03:04.390 --> 00:03:09.400 This completes the vector derived from the cross product operation 54 00:03:09.400 --> 00:03:13.243 We should always examine 55 00:03:13.243 --> 00:03:15.679 the cross product and dot product of vectors 56 00:03:15.679 --> 00:03:17.559 by comparing them 57 00:03:17.559 --> 00:03:21.559 Although these two operations are contrasting 58 00:03:21.559 --> 00:03:24.920 you can think of the cross product as 59 00:03:24.920 --> 00:03:27.859 complementing the aspects that the dot product lacks 60 00:03:27.859 --> 00:03:29.889 Looking at this diagram 61 00:03:29.889 --> 00:03:33.160 when two arbitrary vectors are used 62 00:03:33.160 --> 00:03:34.880 the dot product involves 63 00:03:34.880 --> 00:03:38.560 multiplying corresponding components and then adding them together 64 00:03:38.560 --> 00:03:40.570 However, in the cross product 65 00:03:40.570 --> 00:03:42.451 for any x-component, 66 00:03:42.451 --> 00:03:44.659 it uses the components other than x 67 00:03:44.659 --> 00:03:46.869 For y, it uses components other than y 68 00:03:46.869 --> 00:03:50.679 so the operation relies only 69 00:03:50.679 --> 00:03:52.559 on non-corresponding components 70 00:03:52.559 --> 00:03:55.949 This way, you can understand that the cross product complements 71 00:03:55.949 --> 00:04:00.878 the properties of the dot product 72 00:04:00.878 --> 00:04:04.039 Now, let’s examine the properties 73 00:04:04.039 --> 00:04:06.949 of the dot product and the cross product operations 74 00:04:06.949 --> 00:04:10.240 Previously, we studied the various properties 75 00:04:10.240 --> 00:04:12.010 of the dot product operation 76 00:04:12.010 --> 00:04:14.112 Let’s review the two operations 77 00:04:14.112 --> 00:04:16.730 by comparing them side by side 78 00:04:16.730 --> 00:04:21.680 The dot product operation satisfies the commutative property 79 00:04:21.680 --> 00:04:24.760 but the cross product does not 80 00:04:24.760 --> 00:04:28.910 As you can see, the cross product involves subtraction 81 00:04:28.910 --> 00:04:34.160 so if you swap v and u in the operation 82 00:04:34.160 --> 00:04:39.839 the resulting value will differ from the previous calculation 83 00:04:39.839 --> 00:04:42.640 Thus, the commutative property does not hold for the cross product 84 00:04:42.640 --> 00:04:46.799 The important point here is that although the commutative property does not apply 85 00:04:46.799 --> 00:04:52.240 adding a negative sign to the vector, 86 00:04:52.240 --> 00:04:54.516 when reversing the order 87 00:04:54.516 --> 00:04:58.080 results in the same cross product value as the original 88 00:04:58.080 --> 00:05:00.320 This means a vector in the opposite direction is created 89 00:05:00.320 --> 00:05:04.160 So, while the commutative property does not apply 90 00:05:04.160 --> 00:05:06.468 you can think of it as 91 00:05:06.468 --> 00:05:08.359 following a specific rule 92 00:05:08.359 --> 00:05:11.023 Neither the dot product nor the cross product 93 00:05:11.023 --> 00:05:12.600 satisfies the associative property 94 00:05:12.600 --> 00:05:14.602 It’s good to note that 95 00:05:14.602 --> 00:05:17.079 neither operation adheres 96 00:05:17.079 --> 00:05:19.119 to the associative property 97 00:05:19.119 --> 00:05:22.279 Next, one important property is that 98 00:05:22.279 --> 00:05:24.568 over addition, the dot product satisfies 99 00:05:24.568 --> 00:05:26.720 the distributive property 100 00:05:26.720 --> 00:05:27.880 The same applies to the cross product 101 00:05:27.880 --> 00:05:31.959 The distributive property holds for addition in the cross product, as shown here 102 00:05:31.959 --> 00:05:37.359 Make sure to remember this property 103 00:05:37.359 --> 00:05:38.876 Let’s examine the key properties 104 00:05:38.876 --> 00:05:41.880 of the cross product 105 00:05:41.880 --> 00:05:45.799 If we consider vectors in the same or opposite directions 106 00:05:45.799 --> 00:05:47.535 this means 107 00:05:47.535 --> 00:05:50.399 vectors that are either aligned in the same or opposite directions 108 00:05:50.399 --> 00:05:53.480 This implies that the vectors are parallel 109 00:05:53.480 --> 00:05:56.815 This implies that the vectors are parallel vectors 110 00:05:56.815 --> 00:05:59.160 always results in a zero vector 111 00:05:59.160 --> 00:06:01.279 Let’s explore why this happens 112 00:06:01.279 --> 00:06:05.079 When you take the cross product 113 00:06:05.079 --> 00:06:08.119 of the same vector with itself, 114 00:06:08.119 --> 00:06:10.193 the result is a zero vector 115 00:06:10.193 --> 00:06:12.941 due to the negative sign introduced by the operation 116 00:06:12.941 --> 00:06:15.409 Similarly, the cross product of vectors in opposite directions 117 00:06:15.409 --> 00:06:18.320 also results in a zero vector 118 00:06:18.320 --> 00:06:22.239 The only difference is the sign—positive or negative 119 00:06:22.239 --> 00:06:26.614 Even if you multiply a vector by a scalar 120 00:06:26.614 --> 00:06:28.040 and take the cross product with another vector 121 00:06:28.040 --> 00:06:30.760 in the same direction, 122 00:06:30.760 --> 00:06:34.980 the result remains equivalent to scaling the zero vector 123 00:06:34.980 --> 00:06:38.429 Since scaling a zero vector still results in a zero vector 124 00:06:38.429 --> 00:06:42.289 parallel vectors always produce a zero vector, 125 00:06:42.289 --> 00:06:45.160 which is a fundamental property of the cross product 126 00:06:45.160 --> 00:06:47.112 Let’s explore 127 00:06:47.112 --> 00:06:49.630 how to apply this property 128 00:06:49.630 --> 00:06:53.200 When we have two vectors, u and v 129 00:06:53.200 --> 00:06:54.760 with these two, 130 00:06:54.760 --> 00:06:57.327 we can decompose u with respect to v 131 00:06:57.327 --> 00:06:59.320 into two components 132 00:06:59.320 --> 00:07:02.760 One component is parallel, and the other is perpendicular 133 00:07:02.760 --> 00:07:06.720 The parallel component will naturally produce a zero vector in the cross product 134 00:07:06.720 --> 00:07:09.760 The perpendicular component will result in a non-zero value 135 00:07:09.760 --> 00:07:12.959 Previously, we divided the vector into two components like this 136 00:07:12.959 --> 00:07:16.279 Since the distributive property holds for addition 137 00:07:16.279 --> 00:07:19.637 the cross product of u and v 138 00:07:19.637 --> 00:07:20.804 simplifies as follows 139 00:07:20.804 --> 00:07:23.320 The parallel component becomes a zero vector and cancels out 140 00:07:23.320 --> 00:07:27.359 Only the perpendicular component remains 141 00:07:27.359 --> 00:07:31.745 Thus, when dealing with 142 00:07:31.745 --> 00:07:35.279 such arbitrary vectors, 143 00:07:35.279 --> 00:07:41.399 if we consistently decompose the vector and exclude the parallel component, 144 00:07:41.399 --> 00:07:45.119 regardless of the vector’s magnitude 145 00:07:45.119 --> 00:07:47.382 the result is influenced by 146 00:07:47.382 --> 00:07:50.359 the angle between the vector and v 147 00:07:50.359 --> 00:07:52.359 This is because only the perpendicular component contributes to the result 148 00:07:52.359 --> 00:07:55.920 Ultimately, the smaller the angle, 149 00:07:55.920 --> 00:07:59.559 the smaller the perpendicular component becomes 150 00:07:59.559 --> 00:08:03.399 As a result, the cross product value decreases 151 00:08:03.399 --> 00:08:07.240 On the other hand, the larger the angle, 152 00:08:07.240 --> 00:08:10.150 the larger the perpendicular component becomes 153 00:08:10.150 --> 00:08:13.119 Thus, the cross product value increases 154 00:08:13.119 --> 00:08:15.572 This proportional relationship 155 00:08:15.572 --> 00:08:18.770 is related to the sine function of trigonometry 156 00:08:18.770 --> 00:08:21.699 In this context, the sine function corresponds to this part 157 00:08:21.699 --> 00:08:24.320 which represents the perpendicular component 158 00:08:24.320 --> 00:08:27.005 Thus, the magnitude of the cross product vector 159 00:08:27.005 --> 00:08:30.720 is proportional to the sine of the angle between the two vectors 160 00:08:30.720 --> 00:08:33.379 This is the conclusion we can draw 161 00:08:33.379 --> 00:08:36.205 In the case of the dot product we learned earlier 162 00:08:36.205 --> 00:08:38.159 it was proportional to the cosine function 163 00:08:38.159 --> 00:08:40.654 The cosine and sine functions, 164 00:08:40.654 --> 00:08:44.189 as well as the dot product and cross product, complement each other 165 00:08:44.189 --> 00:08:45.978 Remember this 166 00:08:45.978 --> 00:08:48.078 Now, let’s examine the cross product 167 00:08:48.078 --> 00:08:50.209 of two arbitrary vectors 168 00:08:50.209 --> 00:08:53.680 After calculating the cross product 169 00:08:53.680 --> 00:08:58.179 we’ll take the result and compute the dot product with either u or v 170 00:08:58.179 --> 00:09:03.289 According to the equation, the result of the dot product 171 00:09:03.289 --> 00:09:07.479 will repeat identical values, ultimately resulting in 0 172 00:09:07.479 --> 00:09:10.733 This is when we take the dot product with u 173 00:09:10.733 --> 00:09:12.880 and this is when we do it with v 174 00:09:12.880 --> 00:09:15.840 Since the dot product satisfies the commutative property 175 00:09:15.840 --> 00:09:18.599 it doesn’t matter which vector is placed first 176 00:09:18.599 --> 00:09:22.039 In any case, taking the dot product resulted in 0 177 00:09:22.039 --> 00:09:24.039 What does this mean? 178 00:09:24.039 --> 00:09:26.771 The property of the dot product being proportional to the cosine function 179 00:09:26.771 --> 00:09:27.960 is called orthogonality 180 00:09:27.960 --> 00:09:30.036 Thus, a dot product value of 0 181 00:09:30.036 --> 00:09:33.249 means that the two vectors are orthogonal 182 00:09:33.249 --> 00:09:37.000 Previously, we discussed that two arbitrary vectors 183 00:09:37.000 --> 00:09:38.947 with different slopes 184 00:09:38.947 --> 00:09:42.159 can form a plane 185 00:09:42.159 --> 00:09:45.080 When you take the cross product of these two vectors 186 00:09:45.080 --> 00:09:47.411 a vector orthogonal to both 187 00:09:47.411 --> 00:09:49.988 is produced 188 00:09:49.988 --> 00:09:53.520 This means that it generates a vector orthogonal to the plane 189 00:09:53.520 --> 00:09:56.729 This is how the cross product operation works 190 00:09:56.729 --> 00:09:59.608 The direction of orthogonality to the plane 191 00:09:59.608 --> 00:10:04.280 essentially indicates the shortest distance from the plane 192 00:10:04.280 --> 00:10:07.400 we can understand this in this way 193 00:10:07.400 --> 00:10:10.480 It can also be understood as the direction the plane is facing 194 00:10:10.480 --> 00:10:13.904 The vector produced by the cross product of two vectors 195 00:10:13.904 --> 00:10:16.200 is commonly called a normal vector 196 00:10:16.200 --> 00:10:19.919 The cross product operation is used to create this normal vector 197 00:10:19.919 --> 00:10:22.200 This has practical applications in computer graphics 198 00:10:22.200 --> 00:10:26.690 particularly for light calculations 199 00:10:26.690 --> 00:10:29.440 So it’s important to understand this 200 00:10:29.440 --> 00:10:31.873 When creating an orthogonal vector 201 00:10:31.873 --> 00:10:34.840 note that a plane has a front side and a back side 202 00:10:34.840 --> 00:10:36.215 There is a front side and a back side 203 00:10:36.215 --> 00:10:39.108 and whether it faces forward or backward 204 00:10:39.108 --> 00:10:40.670 is determined by orthogonality 205 00:10:40.670 --> 00:10:45.119 which means the dot product equation results in 0 206 00:10:45.119 --> 00:10:49.440 This is related to the order of the cross product we examined earlier 207 00:10:49.440 --> 00:10:53.075 If we take the cross product of u and v 208 00:10:53.075 --> 00:10:55.719 and get a direction, 209 00:10:55.719 --> 00:10:58.972 taking the cross product of v and u in reverse 210 00:10:58.972 --> 00:11:00.870 produces a vector in the opposite direction 211 00:11:00.870 --> 00:11:04.021 Thus, we need to decide 212 00:11:04.021 --> 00:11:07.400 which side is the true front 213 00:11:07.400 --> 00:11:09.239 This is determined by the right-hand rule 214 00:11:09.239 --> 00:11:11.760 The result of the cross product always follows the right-hand rule 215 00:11:11.760 --> 00:11:15.946 The direction of the plane depends 216 00:11:15.946 --> 00:11:17.359 on the priority given to the vectors 217 00:11:17.359 --> 00:11:20.163 In the case of the diagram shown here 218 00:11:20.163 --> 00:11:24.493 if you curl your right hand from u to v 219 00:11:24.493 --> 00:11:28.993 the direction your thumb points indicates 220 00:11:28.993 --> 00:11:33.550 the direction of the plane 221 00:11:33.550 --> 00:11:38.440 We’ve covered how to generate a normal vector 222 00:11:38.440 --> 00:11:40.893 Now let’s compare the dot product and cross product comprehensively 223 00:11:40.893 --> 00:11:44.396 using a diagram 224 00:11:44.396 --> 00:11:47.800 Let’s assume we have two vectors 225 00:11:47.800 --> 00:11:50.705 The dot product is proportional to the cosine function 226 00:11:50.705 --> 00:11:52.749 while the cross product is proportional to the sine function 227 00:11:52.749 --> 00:11:57.840 For the cross product, which is proportional to the sine function 228 00:11:57.840 --> 00:12:00.952 a positive value indicates 229 00:12:00.952 --> 00:12:04.520 the right side, as shown here 230 00:12:04.520 --> 00:12:07.196 A negative value indicates the left side 231 00:12:08.840 --> 00:12:12.050 On the other hand, the dot product 232 00:12:12.050 --> 00:12:13.482 is proportional to the cosine function 233 00:12:13.482 --> 00:12:17.239 so a positive value represents the front side 234 00:12:17.239 --> 00:12:19.673 Thus, the dot product is used to determine orthogonality 235 00:12:19.673 --> 00:12:21.976 The dot product helps identify orthogonality 236 00:12:21.976 --> 00:12:24.988 while the cross product determines parallelism 237 00:12:24.988 --> 00:12:29.390 The dot product is proportional to cosθ, and the cross product is proportional to sinθ 238 00:12:29.390 --> 00:12:31.493 The dot product is used to distinguish front and back 239 00:12:31.493 --> 00:12:34.199 while the cross product is used to distinguish left and right 240 00:12:34.199 --> 00:12:37.458 You can see that 241 00:12:37.458 --> 00:12:40.520 they complement each other quite well 242 00:12:40.520 --> 00:12:42.275 The dot product produces a scalar value 243 00:12:42.275 --> 00:12:45.020 while the cross product produces a vector value 244 00:12:45.020 --> 00:12:47.061 One key application of the dot product 245 00:12:47.061 --> 00:12:49.181 is creating projection vectors 246 00:12:49.181 --> 00:12:52.611 The cross product is used to create normal vectors 247 00:12:53.125 --> 00:12:56.858 Applications of the Cross Product 248 00:12:57.500 --> 00:13:01.738 Let’s explore how the cross product 249 00:13:01.738 --> 00:13:05.470 is practically applied in game development 250 00:13:05.470 --> 00:13:09.467 The first application we’ll look at is determining left and right 251 00:13:09.467 --> 00:13:12.940 The cross product can be used to determine whether 252 00:13:12.940 --> 00:13:15.020 something is on the left or the right 253 00:13:15.020 --> 00:13:18.514 When we set a viewing vector f 254 00:13:18.514 --> 00:13:22.860 and define the vector from the character to the object as v 255 00:13:22.860 --> 00:13:29.338 if we calculate the cross product 256 00:13:29.338 --> 00:13:31.320 from f to v 257 00:13:31.320 --> 00:13:34.736 the result of the cross product will point downward 258 00:13:34.736 --> 00:13:37.371 when using the right-hand rule, right? 259 00:13:37.371 --> 00:13:41.524 On the other hand, if the object 260 00:13:41.524 --> 00:13:44.239 is on the left side of the viewing vector, let’s call it v' 261 00:13:44.239 --> 00:13:48.218 the cross product will point upward, as you can see 262 00:13:48.218 --> 00:13:52.050 This means that relative to the character’s view 263 00:13:52.050 --> 00:13:54.167 an object on the left will result in an upward direction 264 00:13:54.167 --> 00:13:56.342 while an object on the right will point downward 265 00:13:56.342 --> 00:13:57.787 This is what you will be able to see 266 00:13:59.599 --> 00:14:02.549 By using this property, where upward means left 267 00:14:02.549 --> 00:14:05.520 and downward means right 268 00:14:05.520 --> 00:14:08.446 we can determine whether the object 269 00:14:08.446 --> 00:14:10.559 is on the left or right 270 00:14:10.559 --> 00:14:14.221 However, since the cross product always produces a vector 271 00:14:14.221 --> 00:14:16.400 it’s not possible to clearly distinguish 272 00:14:16.400 --> 00:14:18.067 between left and right 273 00:14:18.067 --> 00:14:21.119 based solely on the vector value 274 00:14:21.119 --> 00:14:23.329 At this point, we introduce an "Up vector," 275 00:14:23.329 --> 00:14:27.479 a vector pointing upward 276 00:14:27.479 --> 00:14:29.847 Typically, this is the world’s y-axis 277 00:14:29.847 --> 00:14:31.880 represented as (0, 1, 0) 278 00:14:31.880 --> 00:14:36.360 We use the (0, 1, 0) vector 279 00:14:36.360 --> 00:14:38.799 to perform an additional dot product calculation 280 00:14:38.799 --> 00:14:40.969 When taking the dot product 281 00:14:40.969 --> 00:14:42.604 with the Up vector 282 00:14:42.604 --> 00:14:45.289 if they are in the same direction, it indicates upward 283 00:14:45.289 --> 00:14:48.540 Thus, a positive result indicates left, and negative indicates right 284 00:14:48.540 --> 00:14:50.100 you can understand it like this 285 00:14:50.100 --> 00:14:52.771 You can use the scalar triple product 286 00:14:52.771 --> 00:14:55.679 to determine left and right like this 287 00:14:55.679 --> 00:14:58.185 The second application of the cross product 288 00:14:58.185 --> 00:15:02.029 is generating a rotation matrix from vectors 289 00:15:02.029 --> 00:15:04.204 This is commonly used 290 00:15:04.204 --> 00:15:06.389 for determining the orientation of an object’s viewing direction 291 00:15:06.389 --> 00:15:09.559 or a camera’s viewing direction 292 00:15:09.559 --> 00:15:11.961 to derive a rotation matrix 293 00:15:11.961 --> 00:15:14.719 from the viewing direction 294 00:15:14.719 --> 00:15:16.679 Let’s go through an example 295 00:15:16.679 --> 00:15:18.699 Suppose there is a camera and an object 296 00:15:18.699 --> 00:15:21.952 The direction from the camera to the object 297 00:15:21.952 --> 00:15:25.840 can be found by subtracting the camera’s position from the object’s position 298 00:15:25.840 --> 00:15:28.570 This vector essentially represents 299 00:15:28.570 --> 00:15:31.280 the local z-axis 300 00:15:31.280 --> 00:15:34.573 Once we have the local z-axis 301 00:15:34.573 --> 00:15:38.520 we need to calculate the remaining local x-axis and y-axis 302 00:15:38.520 --> 00:15:42.980 The local x-axis can be derived using the world’s Up vector 303 00:15:42.980 --> 00:15:45.520 and the plane formed by 304 00:15:45.520 --> 00:15:48.362 the z-local and the Up vector 305 00:15:48.362 --> 00:15:55.520 The vector orthogonal to this plane becomes the x-local axis 306 00:15:55.520 --> 00:15:58.420 Thus, we calculate the x-local axis 307 00:15:58.420 --> 00:16:01.320 which points beyond the camera monitor 308 00:16:01.320 --> 00:16:04.640 Using the cross product, this becomes the normal vector 309 00:16:04.640 --> 00:16:07.280 After calculating the x-local axis this way 310 00:16:07.280 --> 00:16:10.374 the y-local axis can be found 311 00:16:10.374 --> 00:16:14.280 by taking the cross product of z-local and x-local 312 00:16:14.280 --> 00:16:17.719 This completes the three axes 313 00:16:17.719 --> 00:16:23.536 However, it’s important to note that these vectors 314 00:16:23.536 --> 00:16:26.799 may not all have a magnitude of 1 315 00:16:26.799 --> 00:16:30.559 For the z-local axis, 316 00:16:30.559 --> 00:16:32.359 we can normalize it 317 00:16:32.359 --> 00:16:36.359 Dividing the vector by its magnitude normalizes it 318 00:16:36.359 --> 00:16:40.389 Similarly, the x-vector generated from the cross product 319 00:16:40.389 --> 00:16:42.519 may not have a magnitude of 1 320 00:16:42.519 --> 00:16:44.939 This is because it’s not guaranteed that 321 00:16:44.939 --> 00:16:47.490 the y-axis and x-axis are orthogonal 322 00:16:47.490 --> 00:16:51.220 Thus, the angle between them may vary, 323 00:16:51.220 --> 00:16:53.216 so we must normalize it 324 00:16:53.216 --> 00:16:56.440 after calculation 325 00:16:56.440 --> 00:16:59.179 Since the z and x axes 326 00:16:59.179 --> 00:17:01.640 are designed to be orthogonal 327 00:17:01.640 --> 00:17:04.618 the y-axis can be directly calculated 328 00:17:04.618 --> 00:17:07.239 using the cross product without additional normalization 329 00:17:07.239 --> 00:17:08.807 In summary, you can calculate 330 00:17:08.807 --> 00:17:12.000 the three local axes as follows 331 00:17:12.000 --> 00:17:14.666 These axes can then be used 332 00:17:14.666 --> 00:17:18.479 to construct a rotation matrix in 3D space 333 00:17:18.479 --> 00:17:22.800 There are some considerations to keep in mind when creating such a rotation matrix 334 00:17:22.800 --> 00:17:24.680 For instance, there are cases where the camera might flip upside down 335 00:17:24.680 --> 00:17:27.599 Sometimes an object moves in an inverted manner 336 00:17:27.599 --> 00:17:29.839 Although these cases are rare 337 00:17:29.839 --> 00:17:32.599 it’s good to account for them just in case 338 00:17:32.599 --> 00:17:35.526 You can typically provide an option 339 00:17:35.526 --> 00:17:37.920 to specify the direction of the Up vector 340 00:17:37.920 --> 00:17:40.040 in such scenarios 341 00:17:40.040 --> 00:17:42.729 Keep in mind that such functionality 342 00:17:42.729 --> 00:17:45.239 might be necessary 343 00:17:45.239 --> 00:17:50.199 The second issue occurs when the camera’s viewing direction 344 00:17:50.199 --> 00:17:53.239 is parallel to the specified Up vector 345 00:17:53.239 --> 00:17:55.536 In this case, taking their cross product 346 00:17:55.536 --> 00:17:57.199 results in a zero vector 347 00:17:57.199 --> 00:18:00.239 which means you cannot proceed further 348 00:18:00.239 --> 00:18:03.239 This becomes a significant obstacle 349 00:18:03.239 --> 00:18:06.119 In such cases, 350 00:18:06.119 --> 00:18:12.237 having the Up vector 351 00:18:12.237 --> 00:18:15.439 and the local z-axis parallel is meaningless, right? 352 00:18:15.439 --> 00:18:20.610 So, you need to arbitrarily designate a vector 353 00:18:20.610 --> 00:18:23.960 orthogonal to the viewing direction 354 00:18:23.960 --> 00:18:27.669 You can specify an x-axis separately or arbitrarily assign it 355 00:18:27.669 --> 00:18:31.040 In this case, the x-axis refers to the world’s x-axis 356 00:18:31.040 --> 00:18:35.576 You can assign either the world x-axis or the world z-axis, 357 00:18:35.576 --> 00:18:39.385 and use them to calculate 358 00:18:39.385 --> 00:18:40.970 the remaining axes 359 00:18:40.970 --> 00:18:42.932 Such exceptions 360 00:18:42.932 --> 00:18:45.537 must be considered during implementation 361 00:18:47.211 --> 00:18:49.399 The final application of the cross product is 362 00:18:49.399 --> 00:18:52.515 back-face culling, which is a technique 363 00:18:52.515 --> 00:18:54.711 commonly used in rendering 364 00:18:54.711 --> 00:18:58.640 When dealing with a triangle 365 00:18:58.640 --> 00:19:02.075 there’s always a front face and a back face 366 00:19:02.075 --> 00:19:06.309 If it faces the back, there’s no need to render it 367 00:19:06.309 --> 00:19:08.720 Because it’s not visible to the eye, typically 368 00:19:08.720 --> 00:19:10.514 in the case of opaque objects 369 00:19:10.514 --> 00:19:13.000 the back face is not rendered as it’s not visible 370 00:19:13.000 --> 00:19:16.611 Using back-face culling 371 00:19:16.611 --> 00:19:18.380 to omit the back face 372 00:19:18.380 --> 00:19:21.726 can significantly reduce the number of triangles rendered 373 00:19:21.726 --> 00:19:24.209 by nearly half 374 00:19:24.209 --> 00:19:28.239 This leads to substantial performance improvements in game development 375 00:19:28.239 --> 00:19:31.610 Let’s look at how this is implemented 376 00:19:31.610 --> 00:19:35.439 Typically, when we define a triangle by specifying three vertices 377 00:19:35.439 --> 00:19:36.830 we need to determine 378 00:19:36.830 --> 00:19:40.360 which way the face of the triangle is oriented 379 00:19:40.360 --> 00:19:43.420 Since a triangle always has a front face and a back face 380 00:19:43.420 --> 00:19:48.299 it’s necessary to specify which side is the front face 381 00:19:48.299 --> 00:19:52.160 However, if we explicitly define the front face for every triangle 382 00:19:52.160 --> 00:19:54.582 we’d have to store 383 00:19:54.582 --> 00:19:57.359 additional directional data 384 00:19:57.359 --> 00:19:59.780 which would be a significant waste of storage 385 00:19:59.780 --> 00:20:01.750 This is where the cross product comes in 386 00:20:01.750 --> 00:20:08.359 We implicitly use the order of the vertices 387 00:20:08.359 --> 00:20:13.719 to define the direction of the triangle’s face using the normal vector 388 00:20:13.719 --> 00:20:16.199 generated by the cross product 389 00:20:16.199 --> 00:20:17.479 Let’s take an example 390 00:20:17.479 --> 00:20:20.642 Here for 0, 1, 2, the triangle is defined 391 00:20:20.642 --> 00:20:23.399 in a counter-clockwise order 392 00:20:23.399 --> 00:20:28.000 In this case, using the right-hand rule 393 00:20:28.000 --> 00:20:30.720 the result of the cross product points beyond the monitor 394 00:20:30.720 --> 00:20:33.199 This indicates the direction of the face 395 00:20:33.199 --> 00:20:35.048 Now, for a triangle defined 396 00:20:35.048 --> 00:20:36.569 in a clockwise order 397 00:20:36.569 --> 00:20:39.840 the result points toward the front, or toward me 398 00:20:39.840 --> 00:20:43.630 Thus, this side is implicitly defined 399 00:20:43.630 --> 00:20:45.390 as the direction of the face 400 00:20:45.390 --> 00:20:48.839 Using this method, there’s no need 401 00:20:48.839 --> 00:20:52.809 to explicitly store face direction data in the mesh 402 00:20:52.809 --> 00:20:56.199 By clearly distinguishing between the front and back faces 403 00:20:56.199 --> 00:20:59.099 we can implement the technique of back-face culling 404 00:20:59.099 --> 00:21:03.690 For example, if the camera has a viewing direction 405 00:21:03.690 --> 00:21:08.160 only the faces that face the viewing direction are rendered 406 00:21:08.160 --> 00:21:10.360 If the face direction 407 00:21:10.360 --> 00:21:13.525 is the same as the camera’s viewing direction 408 00:21:13.525 --> 00:21:15.260 it means the camera is looking at the back face 409 00:21:15.260 --> 00:21:17.730 In this case, rendering is unnecessary 410 00:21:17.730 --> 00:21:20.089 When the triangle is oriented clockwise 411 00:21:20.089 --> 00:21:21.821 and the camera looks in this direction 412 00:21:21.821 --> 00:21:24.438 since the camera and face are facing each other, 413 00:21:24.438 --> 00:21:26.410 it should be rendered 414 00:21:26.410 --> 00:21:27.909 So how do we determine this? 415 00:21:27.909 --> 00:21:30.622 By calculating the dot product of the camera’s viewing direction vector 416 00:21:30.622 --> 00:21:33.880 and the face’s direction vector, 417 00:21:33.880 --> 00:21:36.360 if their directions align, the result is positive 418 00:21:36.360 --> 00:21:39.000 If the result is negative, they face each other 419 00:21:39.000 --> 00:21:41.710 so it should be rendered 420 00:21:41.710 --> 00:21:44.079 This screen here shows 421 00:21:44.079 --> 00:21:47.159 both the front and back faces rendered on the left 422 00:21:47.159 --> 00:21:53.240 When we render rectangles or cubes in 3D, 423 00:21:53.240 --> 00:21:55.551 we typically render even the parts at the back 424 00:21:55.551 --> 00:21:57.640 This is how a wireframe is drawn 425 00:21:57.640 --> 00:21:59.559 However, using back-face culling 426 00:21:59.559 --> 00:22:03.159 all back faces that face away from the camera 427 00:22:03.159 --> 00:22:05.841 are omitted 428 00:22:05.841 --> 00:22:09.396 This gives the appearance of 429 00:22:09.396 --> 00:22:11.890 a solid, three-dimensional object 430 00:22:11.890 --> 00:22:16.919 In this way, we’ve covered the basic operations and properties of the cross product of vectors 431 00:22:16.919 --> 00:22:19.700 We also explored 432 00:22:19.700 --> 00:22:22.439 its various applications 433 00:22:22.439 --> 00:22:24.449 That concludes the summary of the cross product 434 00:22:24.449 --> 00:22:27.770 We’ll meet again next time with a different topic 435 00:22:27.770 --> 00:22:29.929 This concludes today’s lecture 436 00:22:29.929 --> 00:22:31.760 Thank you for your attention 437 00:22:31.760 --> 00:22:32.580 Thank you! 438 00:22:32.969 --> 00:22:35.463 Vector Cross Product Operations Cross Product Operation Performed only in 3D space, resulting in a vector u=ux, uy, uz, v=vx, vy, vz 439 00:22:35.463 --> 00:22:37.909 u x v= uyvz-vyuz,uzvx-vzux,uxvy-vxuy Properties of the outer product operation Commutative law does not hold Associative law does not hold Distributive law holds for addition 440 00:22:37.909 --> 00:22:39.951 Operation of vector cross product Main properties of cross product When you cross product parallel vectors, you get a zero vector The size of the cross product vector is proportional to the sine function of the angle between them Creates a vector orthogonal to the plane 441 00:22:39.951 --> 00:22:41.641 Comparison of outer and inner products The inner product is used for orthogonal discrimination, and the outer product is used for parallel discrimination The inner product is proportional to cosθ, and the outer product is proportional to sinθ The inner product is used for front and back discrimination, and the outer product is used for left and right discrimination 442 00:22:41.641 --> 00:22:42.928 Dot Product Applications: Projection vectors Cross Product Applications: Normal vectors 443 00:22:42.928 --> 00:22:45.606 Application of vector outer product Left-right determination Determination using scalar triple product f x v y > 0 f x v y <0 Generating rotation matrix from vector 444 00:22:45.606 --> 00:22:46.806 xlocal=y x zlocal/y x zlocal, ylocal=zlocal x xlocal, zlocal-v/v 445 00:22:46.806 --> 00:22:47.988 R=xx yx zx 0, xy yy zy 0, xz yz zz 0, 0, 0, 0, 1 446 00:22:47.988 --> 00:22:49.238 Application of Vector Cross Product Backface Culling Opaque objects usually have no back-facing graphics, so backface culling can drastically reduce triangle drawing 447 00:22:49.238 --> 00:22:50.517 The normal vector created externally using the vertex placement order is implicitly designated as the direction of the triangle Only the faces facing the camera's view direction are drawn 448 00:22:50.517 --> 00:22:51.717 Dot Product of Camera View Vector and Triangle Normal: Positive: Same direction, skip rendering 449 00:22:51.717 --> 00:22:52.938 Negative: Opposite direction, render