Previous Topic Tutorial Home Page Next Topic
Construct a 3-D rendered Image


Constructs one of the puzzle images by rendering three intertwined and animate instances of a doughnut.
public ImageBvr createGeoImage() {

construct a color with a time- varying hue
NumberBvr hue1 = mul(localTime, toBvr(0.2));
ColorBvr col = colorHsl(hue1, toBvr(0.5), toBvr(0.5));

import a half doughnut in the positive Y half space
GeometryBvr halfDonut =
importGeometry(buildURL(_geoBase,"hlfdonut.x"));

Construct a complete doughnut by combining with the second half. The resulting doughnut is centered around the origin and is of [-1,1] extent in X and Y.
GeometryBvr donut = union(halfDonut,
halfDonut.transform(rotate(xVector3, toBvr(Math.PI))));

The first doughnut rotates around the Y axis and has the time-varying color.
GeometryBvr donut0 =
donut.transform(compose(rotate(yVector3, localTime),
scale3(toBvr(0.3)))).diffuseColor(col);

The second doughnut is based on the first one scaled down by 25%, shifted by 0.2 in positive Z, and animated at a 30% faster rate than the first one.
GeometryBvr donut1 = (GeometryBvr)
donut0.transform(compose(translate(0,0,0.2),
scale3(0.75)))

when the first doughnut progresses by one unit, this second doughnut progresses by 1.3 units.
.substituteTime(mul(localTime, toBvr(1.3)));

The third doughnut is based on the first one scaled down by 25%, shifted by 0.2 in negative Z, and animated at a 40% slower rate than the first one.
GeometryBvr donut2 = (GeometryBvr)
donut0.transform(compose(translate(0,0,-0.2),
scale3(0.75))).substituteTime(mul(localTime, toBvr(0.6)));

Construct a 3-D rotational transform with a time-varying axis of rotation and a time-varying angle of rotation.
Transform3Bvr xf = rotate(vector3(sin(localTime),
cos(localTime), sin(mul(toBvr(1.34), localTime))),
mul(localTime, toBvr(0.62)));

The geometry for the image is the aggregation of the three doughnuts from above with the animate rotational transform applied.
GeometryBvr donuts = union(donut0, union(donut1, donut2)).transform(xf);

a camera with projection point at 3 and near plane at 2
CameraBvr cam = perspectiveCamera(toBvr(3),toBvr(2));

GeometryBvr geoWithLight = union(donuts, directionalLight);

ImageBvr im = geoWithLight.render(cam);

This translates the image so that its lower left corner is approximately at the origin. This approximation allows the image (doughnuts really) to get clipped slightly.
im = im.transform(translate(0.5,0.5));

return overlay(im, solidColorImage(white));
}


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

Previous Topic Tutorial Home Page Next Topic