home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / dxma.exe / DXMA05.cab / samples / da / java / exercises / Geometry / Geometry.java next >
Encoding:
Java Source  |  1997-11-13  |  1.8 KB  |  50 lines

  1. // This applet constructs a spinning cube with a time varying color.  It
  2. // illustrates how one can import a geometry, manipulate it, and view it
  3. // with a camera.
  4. //
  5. // Copyright (c) 1997 Microsoft Corporation
  6.  
  7. import com.ms.dxmedia.*;
  8. import java.net.*;
  9.  
  10. // This class extends the Model class.  The createModel method in this class
  11. // is where you construct your animation.
  12. class GeometryModel extends Model {
  13.  
  14.   // Create the animation in the createModel method.
  15.   public void createModel(BvrsToRun blist) {
  16.  
  17.     // Build up a URL to where the geometry resides (import relative to it).
  18.     URL mediaBase = getImportBase();
  19.     URL geoBase = buildURL(mediaBase, "geometry/");
  20.  
  21.     // Import a [-1,1]**3 cube, 2 meters in each dimension
  22.     GeometryBvr cubeGeo = importGeometry(buildURL(geoBase, "cube.x"));
  23.  
  24.     // Spin it around the Z and Y axis.
  25.     cubeGeo = cubeGeo.transform(compose(rotate(yVector3, localTime),
  26.                         rotate(zVector3, mul(localTime, toBvr(1.3)))));
  27.  
  28.     // Make the color time-varying.
  29.     cubeGeo = cubeGeo.diffuseColor(colorHsl(mul(localTime, toBvr(0.3)),
  30.                              toBvr(0.8), toBvr(0.6)));
  31.  
  32.     // set a camera by specifying projection point and near clipping plane
  33.     CameraBvr camera = perspectiveCamera(toBvr(5), toBvr(2));
  34.  
  35.     // render cube into an image
  36.     ImageBvr cubeImg = union(cubeGeo, directionalLight).render(camera);
  37.     // scale the image to fit in viewport, reduce size by 1/35th, about 3cms
  38.     cubeImg = cubeImg.transform(scale2(toBvr(1.0/70.0)));
  39.  
  40.     // set model to the result.
  41.     setImage(overlay(cubeImg, solidColorImage(blue)));
  42.   }
  43. }
  44.  
  45. public class Geometry extends DXMApplet {
  46.   public void init() {
  47.     super.init() ;
  48.     setModel (new GeometryModel());
  49.   }
  50. }