Utility Functions
Takes an index to a page and a direction of motion.
Returns the given page animated in the proper direction,
both left and right page flips are supported. |
public static GeometryBvr flip(NumberBvr ind, int dir) {
orientation of page flip depends on dir |
Transform3Bvr flipTrans = rotate(yVector3, mul(toBvr(dir),
mul(toBvr(flipRate), localTime)));
starting angle of page depends on dir |
GeometryBvr page = ((GeometryBvr)picFrames.nth(ind)).transform(
(Transform3Bvr)cond(toBvr(dir == +1), leftTrans, rightTrans));
return page.transform(flipTrans);
}
Flipping a page commences with startSnd and transitions to flipSound,
stereo sound is used to reflect the direction of the page flip. |
public static SoundBvr flippingSnd(int dir) {
double panRate = 2/period;
in period time it goes from 0 to 2
return (SoundBvr)until(startSnd.pan(-1 * dir), in -dir speaker
timer(toBvr(1.0)),
substitute for startLen
flipSnd.loop().pan(mul(toBvr(dir),
varries from -dir to +dir.
sub(mul(toBvr(panRate), localTime), toBvr(1)))));
}
Pastes a picture on a unit-sized page while preserving its
aspect ratio. The picture is left-centered. The extra
space is filled with paper texture. |
public static ImageBvr normalPic(ImageBvr pic) {
Bbox2Bvr picBbox = pic.boundingBox();
Point2Bvr ur = picBbox.getMax();
NumberBvr dim = maxNumBvr(ur.getX(), ur.getY());
ImageBvr croppedTex = paperTex.tile().crop(point2(neg(dim), neg(dim)),
point2(dim, dim));
return overlay(pic, croppedTex).mapToUnitSquare();
}
Constructs a number behavior which is a certain number
or 0 depending on if the given key is pressed or not. |
static NumberBvr keyIntegral(int key) {
NumberBvr cAngleRate = toBvr(Math.PI/8);
rate of motion of camera angle
NumberBvr factor = (NumberBvr)cond(keyState(key), cAngleRate, toBvr(0));
return integral(factor);
}
Takes a page of the album and renders it into an image
based on consistent camera and lights. Animates the camera
based on the up and down arrow keys. |
static ImageBvr renderPage(GeometryBvr page) {
create an interactive angle to animate the camera |
NumberBvr initialAngle = toBvr(Math.PI/20);
NumberBvr cameraAngle = add(initialAngle,
sub(keyIntegral(Event.UP),
keyIntegral(Event.DOWN)));
use the angle to rotate the camera |
Transform3Bvr cameraTrans = rotate(xVector3, cameraAngle);
CameraBvr camera = perspectiveCamera(toBvr(5),
toBvr(4)).transform(cameraTrans);
scale the resulting image, map 1 unit to 50 pixels |
Transform2Bvr scaleTrans = scale2(mul(toBvr(PAGESIZE),pixelBvr));
GeometryBvr scene = union(ambientLight, page);
return scene.render(camera).transform(scaleTrans);
}
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.