当前位置: 首页>>代码示例>>C++>>正文


C++ Facet::GetMaterial方法代码示例

本文整理汇总了C++中Facet::GetMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ Facet::GetMaterial方法的具体用法?C++ Facet::GetMaterial怎么用?C++ Facet::GetMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facet的用法示例。


在下文中一共展示了Facet::GetMaterial方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GouraudFacet

void Scene::GouraudFacet (Facet& f)
//
// Draws a facet using Gourauds's color interpolation model.
// A scan line approach is taken for drawing this facet.
//
// Uses the global intermediate storage array pix.
//
// If outline == True then the facet ist outlined using the 
// current line drawing color.
//
{
    float rstep,gstep,bstep,rr,gg,bb;
    long /*previous_color,*/ color;
    int maxy,miny,maxx,minx,k,mono;    
    Pixel2D p;
 
    // number of vertices
    int n = f.GetNumVertices();
    
    // facet is degenerate or has too many facets
    if (n < 3 || n > MaxVertices) return;

    Material *Mp;
    static Material M;
    if (coloring == PerVertex) {
        if (f.material) {
	    M.ambient = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } else if (coloring == Global) {
	Mp = f.GetMaterial();
    } else /* (coloring == PerFacet) */ {
	M.color   = f.front;
	if (f.material) {
	    M.ambient = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } 


    // remember previous line color
    //previous_color = linecolor;
    ColorF previous_color = foreground_color;

    maxy = miny = f[0].p.py;
    for (int i = 0; i < n; i++) {
	const Vertex& Vi = f[i];
      
        // copy projected vertex coordinates to polygon array
        pix[i] = Vi.p;

        // find minimum and maximum y-value
	if (pix[i].py > maxy) 
	    maxy = pix[i].py;
        else if (pix[i].py < miny) 
	    miny = pix[i].py;

        // get color at each vertex (vertex color + illumination effect)
	if (coloring == PerVertex) {
	    M.color.red   = float(Vi.red) / 255;
	    M.color.green = float(Vi.green) / 255;
	    M.color.blue  = float(Vi.blue) / 255;
	}
	PhongColor(Vi.x,Vi.y,Vi.z, Vi.nx,Vi.ny,Vi.nz,
		   Mp,r[i],g[i],b[i]);
    }
    
    // special case of a black/and white display
    if (displaymono) {        
	Polygon(n,pix,White,Fill);	// draw a white background polyogon
	SetColor(Black);	// set foreground color to black for the dots
    }
 
    // fill facet using a scan line approach  
    // loop through the scanlines
    // --------------------------

    for ( p.py = miny; p.py <= maxy; (p.py)++ ) {
	
        // polygon is wider than 30000 pixel
	minx =  30000; maxx = -30000;

	int imin = 0, imax = 0;
	for (int i = 0, j = n-1; i < n; j = i++) {
	    
	    int pjy = pix[j].py,
		piy = pix[i].py;
 
//.........这里部分代码省略.........
开发者ID:lucafuji,项目名称:Gene-Correlation,代码行数:101,代码来源:scnshade.cpp

示例2: FlatFacet

void Scene::FlatFacet (Facet& f)
//
// If shading is 'Flat' the facet is drawn using flat shading, otherwise
// if shading is 'false' it will be filled with the background color. 
//
// Uses the global intermediate storage array pix.
//
{
    int i,j;
    float cx,cy,cz,nx,ny,nz,nk;
    short r,g,b;
    long color;
    
    // number of vertices
    int n = f.GetNumVertices();
    
    // facet is degenerate (a line) ----- CURRENTLY DEGENERATE NOT ALLOWED
    if (n == 2) {
	Line(f[0].p,f[1].p);
	return;
    }

    // can't happen !
    if (n < 2 || n > MaxVertices) {
	Warn("Scene::FlatFacet: number of vertices out of range");
	return;
    }

    static Material M;
    Material *Mp;
    if (coloring == Global) {
	Mp = f.GetMaterial();
    } else {
        M.color = f.front;
	if (f.material) {
	    M.ambient  = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } 
     
    // copy projected vertex coordinates to polygon array
    for (i = 0; i < n; i++) pix[i] = f[i].p;
     
    // compute color of facet from reflection properties
    if (shading == Facet::Flat) { 
	
	f.Normal(nx,ny,nz,nk);
	f.Center(cx,cy,cz);

	PhongColor(cx,cy,cz,nx,ny,nz,Mp,r,g,b);

	// find color in colormap
	//color = LookupColor(r,g,b,f.GetMaterial());
	color = LookupColor(r,g,b,&mat);

    // else if (shading == false) then use the background color
    } else
        color = backcolor;

    // =======================================================
    // testing: fog for edgelines to get a depth cueing effect
    // =======================================================
    ColorF previous_color;
    if (fog_opacity) {
      previous_color = foreground_color;
      SetColor( ColorF_Weighted(0.5*(1-tanh((6/fog_opacity)
			        *(hypot(cx,cy,cz)-fog_distance-1))),
				previous_color,fog_color) );
    }

    // draw outlines if requested
    if (edgelines == 1) 
        Polygon(n,pix,color,Outline|Fill);
    else if (edgelines == 0)
        Polygon(n,pix,color,Fill);
    else if (edgelines == Facet::Individual ) {
	if (f.edgelines == 1)
	    Polygon(n,pix,color,Outline|Fill); 
	else if (f.edgelines == 0)
	    Polygon(n,pix,color,Fill);
	else if (f.edgelines == Facet::Individual) {
	    Polygon(n,pix,color,Fill);
	    for (i = 0, j = n-1; i < n; j = i++) 
	      if ( f.GetEdgeLine(j) ) Line(pix[j],pix[i]);
	}	
    }

    if (fog_opacity) SetColor(previous_color);
}
开发者ID:lucafuji,项目名称:Gene-Correlation,代码行数:95,代码来源:scnshade.cpp


注:本文中的Facet::GetMaterial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。