Previous Topic Tutorial Home Page Next Topic
Changing the Color of the Sphere

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.
public class VBScript extends DXMApplet {
private VBScriptModel _Model;
VBScript() {
_Model = new VBScriptModel();
setModel(_Model);
}
Public method accessable to VBScript subroutines in Using_VBScript.html
public void updateColor() {
_Model.updateColor(R,G,B);
}
Public method accessable to VBScript subroutines in Using_VBScript.html
public double R,G,B;
}

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.
public void updateColor(double R, double G, double B) {
ColorBvr newClr = colorRgb(toBvr(R),toBvr(G),toBvr(B));
sphereClrSw.switchTo(newClr);
}
Set up a simple model consisting of a sphere whose color can be switched upon notification.
class VBScriptModel extends Model {

public void createModel(BvrsToRun blist)
{
URL geoBase = buildURL(getImportBase(), "../../../../../Media/geometry/");

Create the sphere's initial color.
ColorBvr initClr = colorRgb(1,1,1);

Create a switcher behavior that will change whenever the scrollbars update the color.
sphereClrSw = new ModifiableBehavior(initClr);

Create a sphere and apply sphereClrSw's behavior to it
GeometryBvr sphereGeo =
importGeometry(buildURL(geoBase,"sphere.x"));
GeometryBvr coloredSphereGeo =
sphereGeo.diffuseColor((ColorBvr)sphereClrSw.getBvr());

Create a camera and light to render sphere.
CameraBvr Cam =
perspectiveCamera(toBvr(1),toBvr(0)).transform(
translate(0,0,50) );
GeometryBvr lightGeo =
directionalLight.transform(
translate(0,0,4));

Display the color changing sphere.
setImage(overlay(
union(coloredSphereGeo, lightGeo).render(Cam),
solidColorImage(white)));
}

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic