Section4: Including 3D Geometries
Now we want to create a weather vane, sailboat, and seagull which will look
like they are part of the 2D scene we created with our cellImages. In this
part of the tutorial, the process of creating the weather vane will be
explained. The sailboat and seagull, although more complex, are created in
similar fashion.
Here we have a class called weatherVane with a static method called getGeo,
which returns a GeometryBvr. This kind of class can be refered to as a
DirectAnimation module because it describes a set of media, in this case
geometries, and behaviors built around that media, that form a more complex
DirectAnimation behavior, in this case a GeometryBvr. |
public class weatherVane extends Statics {
public static GeometryBvr getGeo(NumberBvr windAngle,
NumberBvr windDistance, URL importBase) {
Here we import pieces of geometry such as scoops and arrows, which will
be used to construct the weather vane. |
GeometryBvr nsewGeo = importGeometry(buildURL(importBase, "nsew.x"));
GeometryBvr arrowGeo = importGeometry(buildURL(importBase, "arrow.x"));
GeometryBvr scoopGeo = importGeometry(buildURL(importBase, "scoops.x"));
The arrows are going to rotate based on the wind angle. |
GeometryBvr arrow = arrowGeo.transform(rotate(yVector3, windAngle));
The scoops will spin based on the wind speed. |
GeometryBvr scoops =
scoopGeo.transform(
compose(rotate(yVector3, mul(toBvr(8),windDistance)),
scale3(toBvr(1.25))));
Combine these to form the complete weather vane (our first
DirectAnimation module). |
return union(arrow, union(scoops, union(nsewGeo, directionalLight)));
}
}
Back in the lhouseModel class, use the getGeo() model to construct
the vane, and transform it to match the perspective of the scene. |
GeometryBvr vane =
weatherVane.getGeo(windAngle,windDistance, geoBase).transform(
compose(translate(toBvr(-1.1),toBvr(-0.5),toBvr(0)),
compose(rotate(xVector3, toBvr(Math.PI/12)),
compose(rotate(yVector3, toBvr(Math.PI/4)),
scale3(toBvr(0.6))))));
In order to use the geometry in the scene, convert the geometry
to an image. Here, define a helper method that takes any geometry,
and the upper right corner of the scene. It then return a rendered and
scaled image. |
private ImageBvr geometryImage(GeometryBvr geo, Point2Bvr UR) {
CameraBvr camera =
perspectiveCamera(toBvr(1),toBvr(0))
.transform(translate(toBvr(0), toBvr(0), toBvr(2)));
NumberBvr scaleFactor = (NumberBvr)
cond(lte(UR.getX(), UR.getY()), UR.getX(), UR.getY());
return geo.render(camera).transform(scale2(mul(toBvr(2.8), scaleFactor)));
}
Overlay all of the rendered geometry images over the image composed of
all the sprites. |
ImageBvr composite =
overlay(geometryImage(gull, imageUR),
overlay(geometryImage(sailBoat.getGeo(windSpeed, geoBase), imageUR),
overlay(geometryImage(vane, imageUR), allSprites.getImageBvr())));
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.