1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!--
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: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: csPhyziks Bodies</TITLE>
<META NAME="description" CONTENT="Crystal Space: csPhyziks Bodies">
<META NAME="keywords" CONTENT="Crystal Space: csPhyziks Bodies">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC328"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_150.html#SEC327"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_152.html#SEC329"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_159.html#SEC338"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 6.7.2 Bodies </H3>
<!--docid::SEC328::-->
<P>
The inheritance hierarchy for bodies looks something like this:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>ctPhysicalEntity
=> ctWorld
=> ctArticulatedBody
=> ctDynamicEntity
=> ctSoftBody
=> ctRigidBody
</pre></td></tr></table></P><P>
Here is a brief summary of the various bodies:
</P><P>
<DL COMPACT>
<DT><CODE>ctPhysicalEntity</CODE>
<DD>A body with position and velocity. Any body inheriting from this can be added
to a world.
<DT><CODE>ctArticulatedBody</CODE>
<DD>A body that in composed of a number of rigid bodies connected via joints.
<DT><CODE>ctDynamicEntity</CODE>
<DD>A body that has mass.
<DT><CODE>ctSoftBody</CODE>
<DD><EM>Not implemented</EM>.
<DT><CODE>ctRigidBody</CODE>
<DD>A rigid body with rotational state and an inertia tensor.
</DL>
<P>
Let's look at `<SAMP>ctRigidBody</SAMP>'. Probably the most common type of body. Any
solid object without moving parts is most likely a rigid body. The best way
to create one and add it to a world is like so:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>ctWorld phyz_world;
ctRigidBody* rb = ctRigidBody::new_ctRigidBody();
phyz_world.add_rigidbody(rb);
</pre></td></tr></table></P><P>
This will set up reference frame correctly. Creating a rigid-body with the
C++ `<SAMP>new</SAMP>' operator will not do so.
</P><P>
Now you need to specify some properties: position, mass, and an inertia
tensor. <EM>Note</EM>: Be sure you set the mass before calculating the
`<SAMP>I_tensor</SAMP>', since `<SAMP>I_tensor</SAMP>' is dependent upon mass.
</P><P>
<TABLE><tr><td> </td><td class=example><pre>rb->set_m(15.0); // Set mass.
rb->set_pos(0, 10, 0); // Set position.
// Defaults to zero if you omit following step.
rb->set_v(ctVector3(1, 0, 0));
// Calculate inertia tensor of a rectangular block.
rb->calc_simple_I_tensor(0.2, 0.4, 0.2);
</pre></td></tr></table></P><P>
That last step will calculate an inertia tensor for a solid rectangular block
of uniform density, with dimensions of width 0.2, height 0.4 and depth 0.2
(x,y,z). An inertia tensor is used to calculate the response to angular
forces and impulses. Every shape of object has a different type of inertia
tensor. You must set a mass before you specify the inertia tensor.
</P><P>
You can set the orientation of the body directly (by setting the
transformation matrix), or like so:
</P><P>
<TABLE><tr><td> </td><td class=example><pre>// Axis around which to rotate body.
ctVector3 rotaxisxy(1, 1, 0);
rb->rotate_around_line(rotaxisy, degree_to_rad(45));
</pre></td></tr></table></P><P>
Angular velocity is specified by a vector that points in the direction of the
axis of rotation. The magnitude of that vector determines how fast it
rotates.
</P><P>
<A NAME="csPhyziks Forces"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_150.html#SEC327"> < </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_152.html#SEC329"> > </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> << </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_149.html#SEC326"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_159.html#SEC338"> >> </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
This document was generated
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>
|