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


C++ Box2i::left方法代码示例

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


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

示例1: triangleRender

static bool triangleRender(const Triangle2i& triangle,SmartPointer<Texture> _rgb,SmartPointer<Texture> _alpha,Color4f color,const Box2i& box, bool bWrite)
{
	XgeDebugAssert(_rgb->bpp==24 && _alpha->bpp==8 && _rgb->width==_alpha->width && _rgb->height==_alpha->height);

	int x1=triangle.p0.x,y1=triangle.p0.y;
	int x2=triangle.p1.x,y2=triangle.p1.y;
	int x3=triangle.p2.x,y3=triangle.p2.y;

	unsigned char* rgb     =_rgb  ->buffer;
	unsigned char* alpha   =_alpha->buffer;
	int            W       =_rgb  ->width;

	int minx = min3(x1, x2, x3) , maxx = max3(x1, x2, x3);
	int miny = min3(y1, y2, y3) , maxy = max3(y1, y2, y3);

	//must be completely be contained in the current area
	if (!(minx>=box.left() && maxx<=box.right() && miny>=box.bottom() && maxy<=box.top()))
	{
		XgeDebugAssert(!bWrite);
		return false;
	}

	int Sign=(((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))>=0)?(+1):(-1);

	for(int y = miny; y <= maxy; y++)
	for(int x = minx; x <= maxx; x++)
	{
		// if the pixel is inside....
		if
		(
			(Sign*((x2 - x1) * (y - y1) - (y2 - y1) * (x - x1)) >= 0) &&
			(Sign*((x3 - x2) * (y - y2) - (y3 - y2) * (x - x2)) >= 0) &&
			(Sign*((x1 - x3) * (y - y3) - (y1 - y3) * (x - x3)) >= 0)
		)
		{
			int idx=y*W+x;

			//test if it has already been written
			//note: for each pixel consider also the pixel (-1,0) (+1,0) (0,-1) (0,+1)
			if (!bWrite && (alpha[idx] || alpha[idx-1] || alpha[idx+1] ||alpha[idx-W] || alpha[idx+W]))
				return false;
			
			//if write....
			if (bWrite)
			{
				unsigned char R=(unsigned char)(255.0f*color.r);
				unsigned char G=(unsigned char)(255.0f*color.g);
				unsigned char B=(unsigned char)(255.0f*color.b);

				rgb[idx*3+0] = R;
				rgb[idx*3+1] = G;
				rgb[idx*3+2] = B;

				rgb[(idx-1)*3+0] = rgb[(idx+1)*3+0] = rgb[(idx-W)*3+0] = rgb[(idx+W)*3+0] =R ;
				rgb[(idx-1)*3+1] = rgb[(idx+1)*3+1] = rgb[(idx-W)*3+1] = rgb[(idx+W)*3+1] =G ;
				rgb[(idx-1)*3+2] = rgb[(idx+1)*3+2] = rgb[(idx-W)*3+2]  =rgb[(idx+W)*3+2] =B ;

				//sign as drawn
				alpha [idx  ] = 0x01;
				alpha [idx-1] = 0x01;
				alpha [idx+1] = 0x01;
				alpha [idx-W] = 0x01;
				alpha [idx+W] = 0x01;
			}
		}
	}

	return true;
}
开发者ID:AlessandroGiacomini,项目名称:pyplasm,代码行数:69,代码来源:unwrapper.cpp


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