import com.ms.dxmedia.*; All DirectAnimation classes
import com.ms.ui.*; The AFC classes
import java.awt.*; The event handle classes
import java.net.URL; The Java URL classes
|
public class AFCScroll extends AwtUIApplet {
public void init() {
setLayout(new UIBorderLayout());
Use AFC's AwtUIApplet to construct the applet. |
UIPanel ctrls = new AFCControls();
Get the AFC (scrollbar) part of the Applet. |
Canvas cv = new DXMImage();
Get the DirectAnimation part of the Applet. |
add("North",cv);
add("South",ctrls);
cv.setSize(getSize().width - 15,getSize().height - 15);
setBackground(Color.orange);
}
}
The resize the DirectAnimation part, otherwise it will take over the
entire viewport. |
class AFCControls extends UIPanel {
The scrollbar gets created in the AFCControls Class. |
AFCControls() {
setLayout(new UIGridLayout(1, 1));
_speedBar = new UIScrollBar(0, 0, 30, 3, 1, 15);
_speedBar.setBackground(Color.orange);
add(_speedBar);
}
Create the scrollbar using AFC's UIScrollBar class. |
public boolean handleEvent(Event e) {
switch (e.id) {
case Event.SCROLL_LINE_UP:
case Event.SCROLL_LINE_DOWN:
case Event.SCROLL_PAGE_UP:
case Event.SCROLL_PAGE_DOWN:
case Event.SCROLL_ABSOLUTE:
Handle relevant events when the user interacts with the scrollbar. |
ImageModel.setSpeed(_speedBar.getScrollPos());
return true;
}
return false;
}
UIScrollBar _speedBar;
}
class DXMImage extends DXMCanvas {
DXMImage() {
setModel(new ImageModel());
}
}
The position of the scrollbar sent to the setSpeed() of the
ImageModel class. |
class ImageModel extends Model {
public void createModel(BvrsToRun bvrs) {
In the ImageModel class the createModel method is where you construct
your animation. |
URL mediaBase = getImportBase();
URL geoBase = buildURL(mediaBase, "geometry/");
GeometryBvr geo = importGeometry(buildURL(geoBase, "cube.x"));
_speed = new ModifiableBehavior(toBvr(4));
NumberBvr spinYRate = (NumberBvr)_speed.getBvr();
NumberBvr spinZRate = mul(spinYRate, toBvr(1.3));
geo = geo.transform(compose(rotate(yVector3, integral(spinYRate)),
rotate(zVector3, integral(spinZRate))));
Create a ModifiableBehavior (_speed) which will be linked to the
position of the scrollbar. This behavior will then be used to set
the speed of rotation for the cube. |
CameraBvr cam = perspectiveCamera(toBvr(5), toBvr(2));
Create a camera to view the cube. |
setImage(overlay(union(geo, directionalLight).render(cam)
.transform(scale2(mul(toBvr(20),pixelBvr))),solidColorImage(blue)));
}
Display the cube on a blue background. |
static void setSpeed(int speed) {
_speed.switchTo(toBvr(speed/3.0));
}
static ModifiableBehavior _speed;
}
This method is used in the AFCControls class to change _speed. |
That's all there is to it. Happy animating... |