<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="Section2.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>
<IMG SRC="../../../../../media/image/d_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</FONT></TD><TD WIDTH=30></TD></TR></TABLE></DIV>
<FONT CLASS=title><CENTER>Changing the Color of the Sphere</CENTER></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Here in the VBScript class, you see the R,G, and B data members. The
 updateColor method just passes the data along to the VBScriptModel model
 class, where it will be used to change the color of the sphere.</TD></TR></FONT></TABLE>
<FONT CLASS=code>public class VBScript extends DXMApplet {<BR>
<DIV STYLE="margin-left: 0.125in">private VBScriptModel _Model;<BR>
VBScript() {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">_Model = new VBScriptModel();<BR>
setModel(_Model);<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}</FONT>
<BR>
</DIV><TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Public method accessable to VBScript subroutines in Using_VBScript.html</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">public void updateColor() {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">_Model.updateColor(R,G,B);<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}</FONT>
<BR>
</DIV><TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Public method accessable to VBScript subroutines in Using_VBScript.html</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">public double R,G,B;<BR>
</DIV>}</FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> The VBScript class accesses this method to update the color of the sphere.
 This is done by switching sphereClrSw to a color based on the R,G, and B
 values obtained from the scrollbars.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">public void updateColor(double R, double G, double B) {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">ColorBvr newClr = colorRgb(toBvr(R),toBvr(G),toBvr(B));<BR>
sphereClrSw.switchTo(newClr);<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}</FONT>
<BR>
</DIV><TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Set up a simple model consisting of a sphere whose color can be switched
 upon notification.</TD></TR></FONT></TABLE>
<FONT CLASS=code>class VBScriptModel extends Model {<BR>
<BR>
<DIV STYLE="margin-left: 0.125in">public void createModel(BvrsToRun blist)<BR>
{<BR>
</DIV><DIV STYLE="margin-left: 0.25in">URL geoBase = buildURL(getImportBase(), "../../../../../Media/geometry/");<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Create the sphere's initial color.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">ColorBvr initClr = colorRgb(1,1,1);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Create a switcher behavior that will change whenever the scrollbars
 update the color.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">sphereClrSw = new ModifiableBehavior(initClr);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Create a sphere and apply sphereClrSw's behavior to it</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">GeometryBvr sphereGeo =<BR>
</DIV><DIV STYLE="margin-left: 0.5in">importGeometry(buildURL(geoBase,"sphere.wrl"));<BR>
</DIV><DIV STYLE="margin-left: 0.25in">GeometryBvr coloredSphereGeo =<BR>
</DIV><DIV STYLE="margin-left: 0.5in">sphereGeo.diffuseColor((ColorBvr)sphereClrSw.getBvr());<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Create a camera and light to render sphere.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">CameraBvr  Cam =<BR>
</DIV><DIV STYLE="margin-left: 0.375in">perspectiveCamera(toBvr(1),toBvr(0)).transform(<BR>
</DIV><DIV STYLE="margin-left: 0.75in">translate(0,0,50) );<BR>
</DIV><DIV STYLE="margin-left: 0.25in">GeometryBvr lightGeo =<BR>
</DIV><DIV STYLE="margin-left: 0.5in">directionalLight.transform(<BR>
</DIV><DIV STYLE="margin-left: 0.75in">translate(0,0,4));<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Display the color changing sphere.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">setImage(overlay(<BR>
</DIV><DIV STYLE="margin-left: 0.375in">union(coloredSphereGeo, lightGeo).render(Cam),<BR>
</DIV><DIV STYLE="margin-left: 0.5in">solidColorImage(white)));<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV><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="Section2.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>
<IMG SRC="../../../../../media/image/d_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</FONT></TD><TR><TD WIDTH=30></TD></TR></TABLE></DIV>
</BODY>
</HTML>
