コード例 #1
0
static void hook (MpParametricSurfaceDef &def, Scene &scene, void *ptr)
{
  // the viewing window is passed as argument
  ViewWindow &view = *(ViewWindow*)ptr;

  Material gold(0.3, ColorF(1.0,0.84,0.0), 0.5, 1.8);
  scene.SetFacetMaterial(gold);

  cout << scene.GetNumFacets() << " Facets, "      // print some memory information
       << 0.001*scene.GetMemoryUsage() << " KByte allocated" << endl;
  
  float x0,x1,y0,y1,z0,z1;                       // get extent of scene in space
  scene.Extent(x0,x1,y0,y1,z0,z1);

  float dist = MpMax(x1-x0,y1-y0,z1-z0),                     // distance parameter
        ax = (x1+x0)/2,   ay = (y1+y0)/2,   az = (z1+z0)/2,
        cx = 1.4*dist+ax, cy = 1.2*dist+ay, cz = 1.0*dist+az;

  scene.Look(Vector3D(cx,cy,cz),                       // camera position vector
             Vector3D(-cx+ax,-cy+ay,-cz+az),            // look direction vector
             FieldOfView(40),                   // field of view angle in degree
             0);                            // "twist your head" angle in degree

  MpImage& image = *(view.canvas->image);        // access scroll window's image

  scene.Open(image);                           // direct drawing to raster image
  //scene.SetViewPort(30,30,size-60,size-60); // if omitted viewport is whole image

  scene.SetGlobalShading(Facet::Gouraud);
                                   // surface shading (None, Flat, Gouraud, ...)
  scene.SetGlobalEdgeLines(Facet::Individual); 	      // edgeline drawing option
 
  scene.SetBackground(ColorF(0.3,0.6,0.9));    // draw background with RGB color
  scene.SetColor(ColorF(0,0,0));                  // define color for edge lines
  scene.Show();                                            // render the surface
  scene.Close();                                      // call always after close

  view.MpScrollImageWindow::Configure(image);  // update new scroll window image
  					            // to make our image visible
}