Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bad97183153701b09df5fae1052b1c30 > files > 4185

crystalspace-doc-1.2.1-5mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<head>
<title>Crystal Space 1.2.1: 4.10.7 Mesh Movement</title>

<meta name="description" content="Crystal Space 1.2.1: 4.10.7 Mesh Movement">
<meta name="keywords" content="Crystal Space 1.2.1: 4.10.7 Mesh Movement">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="HOWTO-Mesh-Movement"></a>
<a name="0"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="HOWTO-Mesh-LightAnim.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="MeshObject-Genmesh.html#0" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="MeshObject.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<hr size="1">
<h3 class="subsection"> 4.10.7 Mesh Movement </h3>

<p>This section describes how to move meshes around in your world.
</p>
<a name="1"></a>
<h4 class="subsubheading"> Object and World Space </h4>

<p>It is very important to understand the concept of object and world
space when talking about moving objects. Object space is the coordinate
system that is used for describing the object itself independent of where
it is. Depending on the type of object it is usually convenient to place
the origin of that object space at a central spot. For an actor you
probably want it in at the center of the feet so that you can move the (0,0,0)
point on the ground and the actor will stand correctly.
</p>
<p>World space is where the object will end up after it has been moved.
Even after an object is moved to some other location the object coordinates
will be unmodified (unless <code>HardTransform</code> is used, see later for that).
</p>
<a name="2"></a>
<h4 class="subsubheading"> The <samp>&lsquo;iMovable&rsquo;</samp> </h4>

<p>The basic class that is use to control the position of a mesh is
the <samp>&lsquo;iMovable&rsquo;</samp>. Every mesh wrapper has one (note that it is the
engine that is responsible for knowing where a mesh is, the mesh itself
does not care except when it wants to be rendered or lit).
</p>
<p>A movable contains a list of sectors and a transformation
(<samp>&lsquo;csReversibleTransform&rsquo;</samp>) from object to world space. A transformation
is itself a position (<samp>&lsquo;csVector3&rsquo;</samp>) and a matrix (<samp>&lsquo;csMatrix3&rsquo;</samp>).
</p>
<p>The reason that a movable contains a list of sectors and not just one
sector is that a mesh can be in several sectors at the same time. This
happens when the mesh crosses a portal and one side of the mesh is in
sector A while the other is in sector B. The engine keeps track of this
and will correctly render such objects provided the list of sectors is
correctly. Unfortunately the engine gives little support for detecting
in which sectors a mesh will be after it moves. This support will certainly
arrive at some point in the near future.
</p>
<a name="3"></a>
<h4 class="subsubheading"> Moving a Mesh </h4>

<p><samp>&lsquo;iMovable&rsquo;</samp> contains various functions to help control movement. Here
is an example of some code that places an object in some sector and position:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">iMeshWrapper* mesh = ...;
iMovable* movable = mesh-&gt;GetMovable ();
movable-&gt;SetSector (room);
movable-&gt;SetPosition (csVector3 (2, 3, 1));
movable-&gt;UpdateMove ();
</pre></td></tr></table>
<p>One important function is <code>UpdateMove()</code>. This function MUST
be called after moving an object. It makes sure internal data structures
(for visibility and whatever) are recalculated for the new position of
the object.
</p>
<p>Here is another example where you let the mesh point to some point in space:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">iMeshWrapper* mesh;
iMovable* movable = mesh-&gt;GetMovable ();
csVector3 pos (1, 1, 0);
movable-&gt;SetPosition (pos);
movable-&gt;GetTransform().LookAt(
  csVector3 (5, 2, 0)-pos, csVector3 (0, 1, 0));
movable-&gt;UpdateMove ();
</pre></td></tr></table>
<p>The <code>LookAt()</code> function is very nice. It takes a position relative
to the position where the object is and points the object in the direction
of that point. The up-vector will be used to control the orientation along
that axis. To really make this work well it is recommended that you design
your objects so that X is one unit to the right, Y is one unit above, and
Z points forwards. This is the way that CS works. But <code>LookAt()</code>
can be used for any configuration.
</p>
<p>Note: <code>movable-&gt;GetTransform()</code> returns the <samp>&lsquo;csReversibleTransform&rsquo;</samp>
itself on which you can do various manipulations.
</p>
<a name="4"></a>
<h4 class="subsubheading"> Hierarchical Transformations </h4>

<p>Sometimes meshes can be put in a hierarchical relationship. This means that
there is a parent mesh and children which have a position relative to that
parent. For those children the movable is also used with a few small
exceptions. First of all the list of sectors is not used as it is the
parent mesh that will contain the correct list of sectors for all meshes
in its hierarchy. Second the transform in the movable defines the position
of the mesh relative to its parent. So if you call
<code>movable-&gt;GetTransform()</code> you will not get the transform which will
result in the position of the object but only the transform relative to
the parent's local object space. To get the transform which will transform
object space of that mesh to world space you need to call
<code>GetFullTransform()</code>. Note that modifying this transform will not have
any effect on the mesh (unlike modifying the transform returned by
<code>GetTransform()</code>).
</p>
<a name="5"></a>
<h4 class="subsubheading"> The <code>HardTransform()</code> Function </h4>

<p>Some meshes also support the <code>HardTransform()</code> function. This function
relocates the object space coordinates itself. In other words, it changes
the object space origin of the object. This can be useful if you have objects
that were designed with an origin that is less that desirable and you first
want to move them so that the origin is ok. That can make later transformations
from object to world space easier. <code>HardTransform()</code> is not a function
of <samp>&lsquo;iMovable&rsquo;</samp> but of <samp>&lsquo;iMeshWrapper&rsquo;</samp> (which will in turn delegate
this to the mesh object itself).
</p>
<a name="6"></a>
<h4 class="subsubheading"> Finding Mesh Movement Direction </h4>

<p>0,0,1 is the vector pointing forward in local object space for the mesh.
Using the transform from the movable you can translate this to world space.
With This2Other() you can transform the object space vector to world space. So:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">csVector3 v = mesh-&gt;GetMovable()-&gt;GetTransform()-&gt;This2Other (
	csVector3 (0, 0, 1));
</pre></td></tr></table>
<p>'v' will be the vector one unit in front of the mesh (in the direction the
mesh is facing).
</p>
<a name="7"></a>
<h4 class="subsubheading"> Include Files </h4>

<p>The include files useful for this section are:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">#include &lt;csgeom/transfrm.h&gt;
#include &lt;iengine/movable.h&gt;
#include &lt;iengine/mesh.h&gt;
</pre></td></tr></table>
<hr size="1">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="HOWTO-Mesh-LightAnim.html#0" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="MeshObject-Genmesh.html#0" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="MeshObject.html#0" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 </font>
 <br>

</p>
</body>
</html>