Still, we don't add any codes for mouse dragging, so the cube's just showing the front face. </br>
Still, we don't add any codes for mouse dragging, so the cube's just showing the front face. </br>
</p>
</p>
...
@@ -118,7 +103,7 @@ SOFTWARE.
...
@@ -118,7 +103,7 @@ SOFTWARE.
<p>
<p>
It's almost done!</br>
It's almost done!</br>
In this step, we will use <code>EventListener</code> of JS and HTML DOM event.</br></br>
In this step, we will use <code>EventListener</code> of JS and HTML DOM event.</br></br>
We need 3 functions, <code>Downward</code>, <code>upward</code>, <code>Moving</code>, and 1 variable <code>drag</code>.</br></br>
We need 3 functions, <code>Downward</code>, <code>upward</code>, <code>Moving</code>, and 1 variable,<code>drag</code>.</br></br>
When you clicked the canvas, the <code>Downward</code> function will be run. </br>
When you clicked the canvas, the <code>Downward</code> function will be run. </br>
<code>Downward</code> stores the dragging point's coordinate values. </br>
<code>Downward</code> stores the dragging point's coordinate values. </br>
...
@@ -127,16 +112,49 @@ SOFTWARE.
...
@@ -127,16 +112,49 @@ SOFTWARE.
Each coordinate values will be stored to <code>original_x</code> and <code>original_y</code>.</br>
Each coordinate values will be stored to <code>original_x</code> and <code>original_y</code>.</br>
And make the <code>drag</code> value to <code>true</code>.</br></br>
And make the <code>drag</code> value to <code>true</code>.</br></br>
When you don't click the canvas, the <code>Upward</code> function will be run. </br>
When you don't click the canvas or when your mouse cursor is getting out of the canvas, the <code>Upward</code> function will be run. </br>
<code>Upward</code> do nothing except changing the <code>drag</code> value to false. </br></br>
<code>Upward</code> do nothing except changing the <code>drag</code> value to <code>false</code>. </br></br>
When you move your mouse, the <code>Moving</code> function will be run. </br>
When you move your mouse, the <code>Moving</code> function will be run. </br>
<code>Moving</code> gets the mouse's new coordinates. </br>
<code>Moving</code> gets the mouse's new coordinates. </br>
Then, using the <code>original_x</code>, <code>original_y</code>, <code>pageX</code> and <code>pageY</code>, we will get <code>gap_x</code> and <code>gap_y</code>. </br>
Then, using the <code>original_x</code>, <code>original_y</code>, <code>pageX</code> and <code>pageY</code>, we will get <code>gap_x</code> and <code>gap_y</code>. </br>
These two values, <code>gap_x</code> and <code>gap_y</code>, is the difference between original coordinates and new coordinates(present coordinates). </br>
These two values, <code>gap_x</code> and <code>gap_y</code>, is the difference between original coordinates and new coordinates(present coordinates). </br>
Using <code>gap_x</code> and <code>gap_y</code>, we will change the <code>x_rad</code> and <code>y_rad</code>. </br>
Using <code>gap_x</code> and <code>gap_y</code>, we will change the <code>x_rad</code> and <code>y_rad</code>. </br>
And finally, the <code>original_x</code> and <code>original_y</code> should be changed to present coordinate values for next movement. </br></br>
But, when you aren't dragging and just moving your mouse cursor, the <code>Moving</code> function should not be run. </br>
So, in the <code>Moving</code> function, we have to add some <code>if</code> statement that only when the <code>drag</code> is <code>true</code>, <code>Moving</code> function can be run.</br></br>