Skip to content

Commit cac7c74

Browse files
committed
continuing to add and tweak text
1 parent d758293 commit cac7c74

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

src/templates/pages/learn/getting-started-in-3d.hbs

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ slug: learn/
7575

7676
<h2>Transformations</h2>
7777

78-
<p>p5.js has a few methods, translate(), rotate(), and scale(), that we can use to position and orient objects
78+
<p>p5.js has a few methods, <a class="code" href="{{root}}/reference/#/p5/translate">translate()</a>, <a class="code" href="{{root}}/reference/#/p5/rotate">rotate()</a>, and <a class="code" href="{{root}}/reference/#/p5/scale">scale()</a>, that we can use to position and orient objects
7979
within space. Collectively these are known as the <em>transformation</em> of an object. These methods are
8080
available for
8181
both 2D and 3D drawing.</p>
@@ -106,6 +106,8 @@ slug: learn/
106106
href="{{root}}/reference/#/p5/rotateZ">rotateZ(angle)</a> apply an angle to the
107107
specific axis, but each can be called in combination. </p>
108108

109+
{{!-- TODO explain Euler angles --}}
110+
109111
<h3>scale()</h3>
110112

111113
{{!-- sketch illustrating scaling of geometry --}}
@@ -117,20 +119,61 @@ slug: learn/
117119

118120
<h2>Order</h2>
119121

120-
<p>One thing that might feel a little different than working in 2d is that our 3d sketch has a camera. The camera
121-
is a 3d object of its own, with rotation and position that can affect the way that we see the geometry in our
122-
scene. When we move our object, keep in mind that rotate and translate operate independently from the position
123-
of your camera. These transformations happen in world space, relative to the world origin.</p>
122+
<p>Something that can feel unpredictable at first is the order of transformations. Each transformation can affect
123+
the next one. For example if you call rotate(), followed by translate(), the direction of that translation will
124+
be affected by the rotation. You can think of it as your entire coordinate system rotating and moving, not just
125+
the object itself.</p>
126+
127+
<p>The order that you use will depend on what you’re trying to do, but a good place to start is to follow the
128+
order of translate, rotate, and then scale. If you perform these out of order you might find that your
129+
transformations don’t act the way that you expect them to.</p>
130+
</p>
131+
132+
<p>Another tool we have in p5.js is <a class="code" href="{{root}}/reference/#/p5/push">push()</a> and <a class="code" href="{{root}}/reference/#/p5/pop">pop()</a>. Since transformations accumulate and affect each other, you
133+
might want to control which objects are affected by a certain transformation. push() saves and sets aside our
134+
current transformations (and certain styling, like stroke() or fill()), which allows you to perform other
135+
transformations. pop() restores those transformations.</p>
136+
</p>
137+
138+
<p>You might use push() and pop() so that you can move each object individually. If you don’t use push() and
139+
pop(), you have to keep track of whatever transformations have already taken place, which can get complicated
140+
and difficult to follow. </p>
141+
</p>
142+
143+
<pre><code class="language-javascript">
144+
// draw a box 100 units to the right
145+
translate(100,0,0);
146+
box();
147+
148+
// now, to draw another box 100 units to the left
149+
// since transformations accumulate, we have to
150+
// subtract 200 to do this
151+
translate(-200,0,0);
152+
box();
153+
</code></pre>
154+
155+
<p>Now, the same thing with push() and pop(). Now we can just translate the object where we want it, without
156+
having to remember where our coordinate system lies.</p>
124157

125-
<p>Something that can feel unpredictable at first is the order of transformations. In general, the order that you
126-
want to perform transformations is scale, rotation, then translation. If you perform these out of order it can
127-
be a little more difficult to control. Each of these transformations can have an effect on each other, and this
128-
order makes it much more intuitive. </p>
158+
<pre><code class="language-javascript">
159+
push(); // detach our coordinate system
160+
// draw a box 100 units to the right
161+
translate(100,0,0);
162+
box();
163+
pop(); // return to our original coordinate system
164+
165+
push(); // detach our coordinate system
166+
// draw a box 100 units to the left
167+
translate(-100,0,0);
168+
box();
169+
pop(); // return to our original coordinate system
170+
</code></pre>
171+
172+
<p>While this is a more advanced topic, each of these transformations affect what is called the model matrix. The
173+
transformation matrix is combined with the view matrix and the projection matrix, both of which help simulate
174+
the view of a camera, and this combination results in our 3D scene! </p>
129175

130-
<p>When you call scale, rotate, or translate, each of these calls will affect any objects that are drawn after. If
131-
you want to move things independently, without having to account for prior transformations, you can use the
132-
methods push() and pop(). The combination of these two methods allow you to "detach" the current coordinate
133-
space, which you can then transform, and with pop() you can return to the original coordinate space. </p>
176+
https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_model_view_projection
134177

135178
<p>In the below example, try removing push() and pop() to see how the transformations affect the second object
136179
that is drawn. </p>
@@ -204,15 +247,15 @@ slug: learn/
204247

205248
</ul>
206249

207-
{{!-- sketch illustrating materials --}}
208-
<iframe src="{{assets}}/learn/basic3d/materialsExample.html" width="720" height="350">
209-
</iframe>
210-
211250
<p>You can even draw to another image and apply it as a texture to the object. </p>
212251

213252
<p>and more custom materials can be achieved through texture() and shaders, which will be discussed more at length
214253
later. </p>
215254

255+
{{!-- sketch illustrating materials --}}
256+
<iframe src="{{assets}}/learn/basic3d/materialsExample.html" width="720" height="350">
257+
</iframe>
258+
216259
<h2>Glossary</h2>
217260

218261
<h3>World Space</h3>

0 commit comments

Comments
 (0)