| 123456789101112131415161718192021222324252627282930313233 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>MotionPath</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/motionpath.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>MotionPath</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#sample-code">Sample Code</a></li><li><a href="#what-are-way-points">What Are Way Points?</a></li><li><a href="#create-a-motionpath">Create a MotionPath</a></li><li><a href="#motionpathlistener">MotionPathListener</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>A MotionPath describes the motion of a spatial between waypoints. The path can be linear or rounded. You use MotionPaths to remote-control a spatial, or the camera.</p></div>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>If you want to remote-control a whole cutscene with several spatials moving at various times, then we recommened you use MotionPaths together with <a href="../../jme3/advanced/cinematics.html">Cinematics</a>.</p></div></td></tr></table></div></div></div>
- <div class="sect1"><h2 id="sample-code">Sample Code</h2><div class="sectionbody"><div class="ulist"><ul><li><p><a href="https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/animation/TestMotionPath.java">TestMotionPath.java</a></p></li><li><p><a href="https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/animation/TestCameraMotionPath.java">TestCameraMotionPath.java</a></p></li></ul></div></div></div>
- <div class="sect1"><h2 id="what-are-way-points">What Are Way Points?</h2><div class="sectionbody"><div class="paragraph"><p>When shooting a movie scene, the director tells actors where to walk, for example, by drawing a series of small crosses on the floor. Cameramen often mount the camera on rails (so called dolly track) so they can follow along complex scenes more easily.</p></div>
- <div class="paragraph"><p>In JME3, you use MotionPaths to specify a series of positions for a character or the camera. The MotionPath automatically updates the transformation of the spatial in each frame to make it move from one point to the next.</p></div>
- <div class="ulist"><ul><li><p><strong>A way point</strong> is one positions on a path.</p></li><li><p><strong>A MotionPath</strong> contains a list of all way points of one path.</p></li></ul></div>
- <div class="paragraph"><p>The final shape of the path is computed using a linear interpolation or a <a href="http://www.mvps.org/directx/articles/catmull/">Catmull-Rom</a> spline interpolation on the way points.</p></div></div></div>
- <div class="sect1"><h2 id="create-a-motionpath">Create a MotionPath</h2><div class="sectionbody"><div class="paragraph"><p>Create a Motionpath object and add way points to it.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">MotionPath path = <span class="keyword">new</span> MotionPath();
- path.addWayPoint(<span class="keyword">new</span> Vector3f(<span class="integer">10</span>, <span class="integer">3</span>, <span class="integer">0</span>));
- path.addWayPoint(<span class="keyword">new</span> Vector3f(<span class="integer">8</span>, -<span class="integer">2</span>, <span class="integer">1</span>));
- ...</code></pre></div></div>
- <div class="paragraph"><p>You can configure the path as follows.</p></div>
- <table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 50%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">MotionPath Method</th><th class="tableblock halign-left valign-top">Usage</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.setCycle(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Sets whether the motion along this path should be closed (true) or open-ended (false).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.addWayPoint(vector)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Adds individual waypoints to this path. The order is relevant.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.removeWayPoint(vector)<br>
- removeWayPoint(index)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Removes a way point from this path. You can specify the point that you want to remove as vector or as integer index.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.setCurveTension(0.83f)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Sets the tension of the curve (Catmull-Rom Spline). A value of 0.0f results in a straight linear line, 1.0 a very round curve.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.getNbWayPoints()</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Returns the number of waypoints in this path.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.enableDebugShape(assetManager,rootNode)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Shows a line that visualizes the path. Use this during development and for debugging so you see what you are doing.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>path.disableDebugShape()</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Hides the line that visualizes the path. Use this for the release build.</p></div></div></td></tr></tbody></table></div></div>
- <div class="sect1"><h2 id="motionpathlistener">MotionPathListener</h2><div class="sectionbody"><div class="paragraph"><p>You can hook interactions into a playing MotionPath. Register a MotionPathListener to the MotionPath to track whether way points have been reached, and then trigger a custom action. The onWayPointReach() method of the interface gives you access to the MotionEvent object <code>control</code>, and an integer value representing the current wayPointIndex.</p></div>
- <div class="paragraph"><p>In this example, you just print the status at every way point. In a game you could trigger actions here: Transformations, animations, sounds, game actions (attack, open door, etc).</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">path.addListener( <span class="keyword">new</span> MotionPathListener() {
- <span class="directive">public</span> <span class="type">void</span> onWayPointReach(MotionEvent control, <span class="type">int</span> wayPointIndex) {
- <span class="keyword">if</span> (path.getNbWayPoints() == wayPointIndex + <span class="integer">1</span>) {
- println(control.getSpatial().getName() + <span class="string"><span class="delimiter">"</span><span class="content"> has finished moving. </span><span class="delimiter">"</span></span>);
- } <span class="keyword">else</span> {
- println(control.getSpatial().getName() + <span class="string"><span class="delimiter">"</span><span class="content"> has reached way point </span><span class="delimiter">"</span></span> + wayPointIndex);
- }
- }
- });</code></pre></div></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|