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
<p><aclass="code"href="{{root}}/reference/#/p5/translate">translate()</a> moves our origin point in a
130
-
given direction. Anything drawn after we call translate will be
129
+
<p><aclass="code"href="{{root}}/reference/#/p5/translate">translate()</a> moves the origin in a
130
+
given direction. Anything drawn after we call <aclass="code">translate()</a> will be
131
131
positioned relative to that point. <aclass="code">translate()</a> accepts arguments for x, y, and z
132
-
values.</p>
132
+
values. Use the sliders in the sketch above to change the translation of the box, and see how it moves along
133
+
each axis.</p>
133
134
134
135
<pre><codeclass="language-javascript">
135
136
...
@@ -151,8 +152,9 @@ slug: learn/
151
152
<p>There are a few methods that can be used to rotate an object in 3D. Most of the time it's easiest to call
152
153
methods like like <aclass="code"href="{{root}}/reference/#/p5/rotateX">rotateX()</a>, <aclass="code"
153
154
href="{{root}}/reference/#/p5/rotateY">rotateY()</a>, and <aclass="code"
154
-
href="{{root}}/reference/#/p5/rotateZ">rotateZ()</a>, which allows for rotation around a specific axis.
155
-
Each of these methods accept a single argument specifying the angle of rotation.
155
+
href="{{root}}/reference/#/p5/rotateZ">rotateZ()</a>, which each allow for rotation around a specific axis.
156
+
Each of these methods accept a single argument specifying the angle of rotation. Try moving the sliders in the
157
+
example above to see how rotation is performed on each axis.
156
158
</p>
157
159
158
160
<pre><codeclass="language-javascript">
@@ -165,7 +167,7 @@ slug: learn/
165
167
..
166
168
</code></pre>
167
169
168
-
<p>By default p5.js will expect angles to be in radians. Radians use numbers from 0 - TWO_PI to specify an
170
+
<p>By default p5.js will expect angles to be in radians. Radians use numbers from 0 - <aclass="code">TWO_PI</a> to specify an
169
171
angle. To use degrees, either convert degrees to radians using <aclass="code">radians()</a>, or use
170
172
<aclass="code">angleMode(DEGREES)</a>.
171
173
</p>
@@ -182,17 +184,19 @@ slug: learn/
182
184
..
183
185
</code></pre>
184
186
185
-
<p>You can also use <aclass="code"href="{{root}}/reference/#/p5/rotate">rotate()</a>, which allows
186
-
you to specify which axis you'd like to rotate around using a vector as the second argument.</p>
187
-
188
-
<pre><codeclass="language-javascript">
189
-
...
190
-
// rotate 90 degrees around the y-axis
191
-
let axis = createVector(0,1,0);
192
-
rotate(HALF_PI, axis);
193
-
box();
194
-
..
195
-
</code></pre>
187
+
<divclass="additionalInformation">
188
+
<p>You can also use <aclass="code"href="{{root}}/reference/#/p5/rotate">rotate()</a>, which allows
189
+
you to specify which axis you'd like to rotate around using a vector as the second argument.</p>
190
+
191
+
{{!-- <pre><code class="language-javascript">
192
+
...
193
+
// rotate 90 degrees around the y-axis
194
+
let axis = createVector(0,1,0);
195
+
rotate(HALF_PI, axis);
196
+
box();
197
+
...
198
+
</code></pre> --}}
199
+
</div>
196
200
197
201
<h3>scale(): Size in Space</h3>
198
202
@@ -203,14 +207,15 @@ slug: learn/
203
207
<p><aclass="code"href="{{root}}/reference/#/p5/scale">scale()</a> changes the size of whatever is
204
208
drawn after it. Like the other methods described so far, it accepts arguments for x, y, and z values.</p>
205
209
206
-
<h2id="order">Order</h2>
210
+
<h2id="order">The Order of Transformations Matters!</h2>
207
211
208
-
<p>Something that can feel unpredictable at first is the order of transformations. Each transformation can affect
212
+
<p>Something that can feel unpredictable at first is the order of transformations. Each transformation always affects
209
213
the next one. For example, if <aclass="code">rotate()</a> is called, followed by <aclass="code">translate()</a>, the direction of that translation will
210
214
be affected by the rotation. The entire coordinate system is rotating and moving, not just the shape itself.
211
215
</p>
212
216
213
-
<p>Transformations can be performed in any order, but using <strong>translate</strong>, <strong>rotate</strong>, and then <strong>scale</strong> will be the most intuitive.</p>
217
+
<p>Transformations can be performed in any order, but using <strong>translate</strong>, <strong>rotate</strong>, and then <strong>scale</strong> will be the most intuitive.
218
+
Translation, followed by rotation, produces the effect of moving the shape <em>and then</em> rotating around that new location.</p>
214
219
215
220
<p>In the below example, try changing the order of <aclass="code">translate()</a> and <a
216
221
class="code">rotateY()</a> and see how it affects where the object is
@@ -245,7 +250,9 @@ function draw(){
245
250
class="code">push()</a> and
246
251
<aclass="code">pop()</a>, you have to keep track of whatever transformations have already taken place, which
247
252
can get complicated
248
-
and difficult to follow.
253
+
and difficult to follow. Consider this following example, which places two boxes in our sketch. To position the second box
254
+
without <aclass="code">push()</a> and <aclass="code">pop()</a>, you have to account for the first transformation. This
255
+
can be a lot to keep track of in a more complex 3D scene.
249
256
</p>
250
257
251
258
<pre><codeclass="language-javascript">
@@ -284,7 +291,7 @@ function draw(){
284
291
transformation matrix is combined with the view matrix and the projection matrix, both of which help simulate
285
292
the view of a camera, and this combination results in our 3D scene! </p>
0 commit comments