File: cs_153.html

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (141 lines) | stat: -rw-r--r-- 6,537 bytes parent folder | download
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 Articulated Bodies</TITLE>

<META NAME="description" CONTENT="Crystal Space: csPhyziks Articulated Bodies">
<META NAME="keywords" CONTENT="Crystal Space: csPhyziks Articulated 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="SEC330"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_152.html#SEC329"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_154.html#SEC331"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> &lt;&lt; </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"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <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.4 Articulated Bodies </H3>
<!--docid::SEC330::-->
<P>

An articulated body is a rigid body that can have one or more other rigid
bodies connected to it by joints.  Such as a chain or a human figure.
Currently revolute (like a hinge) joints and prismatic (like an air pump)
joints are implemented.  Also the articulated body can not at present have any
closed loops in it.  Articulated bodies can have one end fixed immovably to
the world reference frame, be free floating, or be attached to an entity whose
movement is specified by the user.
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>// Use new_ctRigidBody makes sure the rb will have
// a suitable reference frame.
rb = ctRigidBody::new_ctRigidBody();
// Create an articulated body with a rigid body.
ab_parent = new ctArticulatedBody(rb);
// Only have to add the root; no need to add
// children to world.
phyz_world.add_add_articulatedbodybase(ab_parent);

ab_child = new ctArticulatedBody(rb2);
ctVector3 joint_offset_parent_to_child(0, -0.1, 0);
// Line of action for this joint.
ctVector3 joint_action(0, 0, 1);
// Link the child to the parent with a revolute joint.
ab_parent-&#62;link_revolute(
  ab_child,
  joint_offset_parent_to_child,
  joint_offset_ctop,
  joint_action);
</pre></td></tr></table></P><P>

Now when evolved the articulated body will move in a dynamically correct
manner in response to any external and internal forces (if the Featherstone
solver is used).
</P><P>

It is possible to define your own joints from `<SAMP>ctJoint</SAMP>'.  You can then
overload the <CODE>get_actuator_magnitude()</CODE> method to implement a joint with
a motor that will exert whatever force you like at that joint.  There is such
a joint implemented that enforces angle constraints on the joint,
`<SAMP>ctConstrainedRevoluteJoint</SAMP>'.  Add this joint using:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>parent_ab-&#62;link_joint(new_constrained_joint, child_ab);
</pre></td></tr></table></P><P>

You can set the angles that joint is constrained to using:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>set_constraint(max_angle, min_angle);
</pre></td></tr></table></P><P>

Test out your joint and modify the spring and damping constants to get the
proper behavior.  For instance, if your joint bounces back too much at the
constraint, your spring constant is too high.
</P><P>

You can attach the root of an articulated body to some object from your own
side of the code.  The attached articulated body's root will move however you
specify and the correct physical behavior will result for the rest of the
artibulated body.
</P><P>

Do this by subclassing `<SAMP>ctKinematicEntity</SAMP>' and implementing all its
methods.  (Minimally, you need to implement <CODE>get_a()</CODE>.) These methods
tell the physics module how your object moves.  You can use this to attach
hair, or a chain, or whatever you like to your game characters.  After you
create your subclass, you attach your articulated body root to it with:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>abroot-&#62;attach_to_entity(&#38;your_kinematic_entity);
</pre></td></tr></table></P><P>

Make sure you have grounded your root first with
<CODE>abroot-&#62;make_grounded()</CODE>.  Now if you want to detach that chain you
should just be able to call <CODE>abroot-&#62;make_ungrounded()</CODE>.
</P><P>

<A NAME="csPhyziks Impulses"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_152.html#SEC329"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_154.html#SEC331"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_143.html#SEC311"> &lt;&lt; </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"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <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>