Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate smooth rotation in given time interval (+- x%)
    primarykey
    data
    text
    <p>I have got a cube in my scene which I want to rotate at a <strong>specific start velocity</strong> and in a <strong>given time interval</strong>. <br /> In addition, the cube's end angle should be the <strong>same as the start angle</strong>. Therefore, I thought of allowing +- 5% deviation of the time interval.</p> <p>Here is my current status: <a href="http://jsfiddle.net/5NWab/1/" rel="nofollow noreferrer">http://jsfiddle.net/5NWab/1/</a>. <br />Don't wonder that is currently <em>working</em>. The problem occurs if I change the time interval, e.g. by '3000': <a href="http://jsfiddle.net/5NWab/2/" rel="nofollow noreferrer">http://jsfiddle.net/5NWab/2/</a>.</p> <p>The essential <em>move()</em> method of my cube:</p> <pre class="lang-js prettyprint-override"><code>Reel.prototype.move = function (delta) { if (this.velocity &lt; 0 &amp;&amp; this.mesh.rotation.x == 0) { return false; } // Create smooth end rotation if (this.velocity &lt; 0 &amp;&amp; this.mesh.rotation.x != 0) { this.mesh.rotation.x += Math.abs(delta * this.speedUp * 0.5 * this.timeSpan); if (Math.abs(this.mesh.rotation.x - 2 * Math.PI) &lt; 0.1) { this.mesh.rotation.x = 0; } } else { this.mesh.rotation.x += delta * this.velocity; this.time -= delta; this.velocity = this.speedUp * this.time; } } </code></pre> <p>The problem is that I cannot think of a solution or method in order to accomplish my topic. It would not be so complex if I the variable <code>delta</code> would be constant. <br /> It should be <em>around</em> <code>60fps = 1000/60</code> because I'm using <code>requestAnimationFrame()</code>.</p> <p>I have also found <a href="https://stackoverflow.com/questions/2708476/rotation-interpolation">this question</a> which could help finding the solution.</p> <p>I think the code should either</p> <ul> <li><p>slow down the velocity before the actual end is reached. <br /> That should be the case if the final angle is <strong>a little bit greater</strong> than the desired (start) angle.</p></li> <li><p>or should speed up the rotation speed after the actual end is reached. <br /> That should be the case if the final angle is <strong>a little bit smaller</strong> than the desired (start) angle.</p></li> </ul> <p>But what is when the angle is a hemicycle away from the desired one (i.e. 180° or PI)?</p> <p>In order to clarify my question, here are my knowns and unknowns:</p> <p><strong>Known:</strong></p> <ul> <li>Start velocity</li> <li>Time interval</li> <li>Start angle (usually 0)</li> </ul> <p><strong>I want the cube</strong> to have the same start angle/position at the end of the rotation. Because the FPS count is not constant, I have to shorten or lengthen the time interval in order to get the cube into the desired position.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload