<HTML>
<HEAD>
<TITLE>DirectX Media SDK DirectAnimation Tutorial</TITLE>
<LINK REL=STYLESHEET HREF="../../../../../webcd/da/tutorial.css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="ROBOTS" CONTENT="noindex">
</HEAD>
<BODY BGCOLOR="WHITE" LINK=#0033CC TOPMARGIN=0 LEFTMARGIN=20>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->

<DIV CLASS="flush">
<TABLE WIDTH=100% BORDER=0 BGCOLOR=#000000>
<TR ALIGN=RIGHT><TD VALIGN=TOP><FONT CLASS=desc1 SIZE=2>
<A HREF="Section1.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_prev.gif"
 WIDTH=71 HEIGHT=16 BORDER=0 ALT="Previous Topic">
</A><A HREF="../../../../../webcd/da/tutorial_main.htm" TARGET="_top">
<IMG SRC="../../../../../media/image/d_home.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Tutorial Home Page"></A>
<A HREF="Section3.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</A></FONT></TD><TD WIDTH=30></TD></TR></TABLE></DIV>
<FONT CLASS=title><CENTER>Section 2: Display the Movie Model in DXMCanvas</CENTER></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This class extends the DXMCanvas class.  The model you set in this class,
 by calling the setModel() method, is the model that will be displayed.</TD></TR></FONT></TABLE>
<FONT CLASS=code>class DxmMovie extends DXMCanvas {<BR>
<DIV STYLE="margin-left: 0.125in">DxmMovie() {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">_model = new VCRModel();<BR>
setModel(_model);<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV><BR>
<DIV STYLE="margin-left: 0.125in">VCRModel _model;<BR>
</DIV>}<BR>
</FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This class extends the Model class.  The createModel method in this class
 is where you construct your model.</TD></TR></FONT></TABLE>
<FONT CLASS=code>class VCRModel extends Model {<BR>
</FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Import a movie in the model and have a switcher behavior to control
 the playback rate.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">public void createModel(BvrsToRun bvrs) {<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Create a movie behavior by importing an avi file.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">URL movieBase = buildURL(getImportBase(), "Movie/");<BR>
ImageBvr[] imgArr = {null};<BR>
SoundBvr[] sndArr = {null};<BR>
NumberBvr lenNum = importMovie(buildURL(movieBase, "movie.avi"),<BR>
</DIV><DIV STYLE="margin-left: 2.1875in">imgArr, sndArr);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> The playback rate switcher starts with 1, the normal rate.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">_rateSw = new ModifiableBehavior(toBvr(1));<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> The playback position of the movie is the sum of the rate.  Use
 modulus to loop the movie since positions less than 0 or greater than
 the length of the movie yields emptyImage.  The specialMod is a
 private function that always returns a positive number less than
 lenNum.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">NumberBvr posNum = specialMod(integral((NumberBvr)_rateSw.getBvr()), lenNum);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Use AppTriggeredEvent for the restart event.  When the restart button
 is pressed, the event will be triggered.  Construct a recursive
 position behavior - the resetablePosNum - that resets to itself when
 the event occurs.  Note that integral has implicit time.  When a
 restart posNum at the time _resetEv occurs, integration starts from
 0.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">_resetEv = new AppTriggeredEvent();<BR>
NumberBvr resetablePosNum = NumberBvr.newUninitBvr();<BR>
resetablePosNum.init(until(posNum, _resetEv, resetablePosNum));<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Play the movie on top of a black background.  Use substituteTime
 to control the position of a movie.  The localTime for movies
 is implicit.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">setImage(overlay((ImageBvr)imgArr[0].substituteTime(resetablePosNum),<BR>
</DIV><DIV STYLE="margin-left: 1.3125in">solidColorImage(black)));<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Loop the sound here.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">setSound((SoundBvr)sndArr[0].loop().substituteTime(resetablePosNum));<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This function does a "special" mod for negative numbers.  It returns
 the linear distance between the passed-in numerator and the biggest
 multiple of the denominator smaller than the numerator.
 For example, specialMode(-1, 5) = 4, specialMod(-4, 5) = 1.
 This is defined so that a decreasing number behavior passed in as the
 numerator yields a consistent result whether its value is positive or
 negative.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">NumberBvr specialMod(NumberBvr numNum, NumberBvr denomNum) {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">return (NumberBvr)cond(gt(numNum, toBvr(0)),<BR>
</DIV><DIV STYLE="margin-left: 1.6875in">mod(numNum, denomNum),<BR>
sub(denomNum, mod(abs(numNum), denomNum)));<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This method changes the value of the rate switcher to the given rate.
 This is called by the event handlers of the playback controls.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">void setRate(int rate) {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">_rateSw.switchTo(toBvr(rate*0.1));<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This method is called when the restart button is pressed.  It resets
 the rate to the normal playback rate, and triggers the event to
 restart the movie.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">void restart() {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">setRate(10);<BR>
_resetEv.trigger();<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV><BR>
<DIV STYLE="margin-left: 0.125in">AppTriggeredEvent _resetEv;<BR>
ModifiableBehavior _rateSw;<BR>
</DIV>}<BR>
<BR>
</FONT><FONT CLASS=link><A ID=cpslug HREF="../../../../../help/da/dalegal.htm" TARGET="_top">&#169; 1997 Microsoft Corporation. All rights reserved. Terms of Use.</A></FONT>
<BR>
<BR>
<DIV CLASS="flush">
<TABLE WIDTH=100% BORDER=0 BGCOLOR=#000000>
<TR ALIGN=RIGHT><TD VALIGN=TOP><FONT CLASS=desc1 SIZE=2>
<A HREF="Section1.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_prev.gif"
 WIDTH=71 HEIGHT=16 BORDER=0 ALT="Previous Topic">
</A><A HREF="../../../../../webcd/da/tutorial_main.htm" TARGET="_top">
<IMG SRC="../../../../../media/image/d_home.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Tutorial Home Page"></A>
<A HREF="Section3.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</A></FONT></TD><TR><TD WIDTH=30></TD></TR></TABLE></DIV>

</BODY>
</HTML>
