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
```{lit} Vertex shader (replace, also for tangle root "Vanilla")
305
+
fn vs_main(in: VertexInput) -> VertexOutput {
306
+
var out: VertexOutput;
307
+
let ratio = 640.0 / 480.0;
308
+
{{Set vertex out position}}
309
+
out.color = in.color;
310
+
return out;
311
+
}
312
+
```
313
+
````
314
+
329
315
```{figure} /images/pyramid-side.png
330
316
:align: center
331
317
:class: with-shadow
@@ -334,7 +320,7 @@ The pyramid seen from the side (still no perspective).
334
320
335
321
What about in-between rotations? The idea is to **mix axes**, adding a little bit of z in the y coordinates and a little bit of y in the z coordinates.
336
322
337
-
```rust
323
+
```{lit}rust, Set vertex out position (replace, also for tangle root "Vanilla")
338
324
var position = vec3f(
339
325
in.position.x,
340
326
in.position.y + 0.5 * in.position.z, // add a bit of Z in Y...
Of course at some point we have to remove some of `in.position.y` from Y so that after a quarter of turn we reach `Y = 0.0 * in.position.y + 1.0 * in.position.z`, as in the example above. So more generally our transform writes like this, where `alpha` and `beta` depend on the rotation angle:
338
+
Of course at some point we have to remove some of `in.position.y` from Y so that after a quarter of turn we reach `Y = 0.0 * in.position.y + 1.0 * in.position.z`, as in the example above. So **more generally** our transform writes like this, where `alpha` and `beta` depend on the **rotation angle**:
353
339
354
340
```rust
355
341
letangle= uMyUniforms.time; // you can multiply it go rotate faster
If you payed close attention to the snippet above, you should have noticed **a minus sign** `-` before the second `beta`. It is not visible on our pyramid because it is symmetrical but swapping axes also flips the object. To **counter-balance** this, we can change the sign of one of the dimensions. Hence the Z coordinate after a quarter of turn must be `-in.position.y` instead of `in.position.y`.
353
+
If you pay close attention to the snippet above, you can notice **a minus sign** `-` before the second `beta`. It is not visible on our pyramid because it is symmetrical but swapping axes also flips the object. To **counter-balance** this, we can change the sign of one of the dimensions. Hence the Z coordinate after a quarter of turn must be `-in.position.y` instead of `in.position.y`.
368
354
```
369
355
370
-
It turns out that these weights `alpha` and `beta` are not easy to express in terms of basic operations with respect to the angle. So mathematicians came up with a dedicated name for them: **cosine** and **sine**! And the good news is that these are **built-in operations** in WGSL:
356
+
It turns out that these **weights**`alpha` and `beta` are not easy to express in terms of basic operations **with respect to the angle**. So mathematicians came up with a dedicated name for them: **cosine** and **sine**! And the good news is that these are **built-in operations** in WGSL:
371
357
372
-
```rust
358
+
```{lit}rust, Set vertex out position (replace, also for tangle root "Vanilla")
373
359
let angle = uMyUniforms.time; // you can multiply it go rotate faster
<p><span class="caption-text">Rotation in the YZ plane</span></p>
390
376
</figcaption>
391
377
</figure>
392
378
393
-
```{image} /images/trigo-light.svg
379
+
```{themed-figure} /images/trigo-{theme}.svg
394
380
:align: center
395
-
:class: only-light
396
-
```
397
381
398
-
```{image} /images/trigo-dark.svg
399
-
:align: center
400
-
:class: only-dark
382
+
A side-view of the pyramid. The (signed) length of the green vertical and horizontal lines give the value of `alpha` and `beta` respectively.
401
383
```
402
384
403
385
Congratulations, you have learned most of what there is to know about **trigonometry** for computer graphics!
404
386
405
387
```{hint}
406
-
**If you cannot remember** which one is the $cos$ and which one is the $sin$ among `alpha` and `beta` (don't worry! It happens to everyone), **just take an example** of very simple rotation: `angle = 0`. In such a case, we need `alpha = 1` and `beta = 0`. If you look at a plot of the $sin$ and $cos$ functions you'll quickly see that $cos(0) = 1$ and $sin(0) = 0$
388
+
**If you cannot remember** which one is the $cos$ and which one is the $sin$ among `alpha` and `beta` (don't worry! It happens to everyone), **just take an example** with very simple rotation: `angle = 0`. In such a case, we need `alpha = 1` and `beta = 0`. If you look at a plot of the $sin$ and $cos$ functions you'll quickly see that $cos(0) = 1$ and $sin(0) = 0$
0 commit comments