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


C++ Corner::set_gradient_y方法代码示例

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


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

示例1: set_tera_height

void World::set_tera_height(Plasma &plasma)
{
	memset(corner_matrix, 0, sizeof(Corner)*(max_x_loc+1)*(max_y_loc+1));

	// short seaHeight = TerrainRes::max_height(TERRAIN_OCEAN);
	short seaHeight = 0;			// no more sea
	int y;
	int x;
	for(y = 0; y <= max_y_loc; ++y )
	{
		for(x = 0; x <= max_x_loc; ++x)
		{
			Corner *cornerPtr = get_corner(x,y);
			cornerPtr->set_altitude(plasma.get_pix(x,y));
			cornerPtr->set_sea_altitude(seaHeight);

			// set gradient_x
			float gradientX;
			if(x <= 0)
			{
				err_when(x < 0);
				gradientX = float(4*plasma.get_pix(x+1,y) - plasma.get_pix(x+2,y) - 3*plasma.get_pix(x,y)) 
					/ (2 * LOCATE_WIDTH);
			}
			else if( x >= max_x_loc )
			{
				err_when(x > max_x_loc);
				gradientX = float(plasma.get_pix(x-2,y) - 4*plasma.get_pix(x-1,y) + 3*plasma.get_pix(x,y)) 
					/ (2 * LOCATE_WIDTH);
			}
			else
			{
				gradientX = float(plasma.get_pix(x+1,y) - plasma.get_pix(x-1,y)) 
					/ (2 * LOCATE_WIDTH);
			}

//			if( gradientX >= 0.0f && gradientX <= 0.25f )
//				gradientX += 0.15f;
//			else if( gradientX < 0.0f && gradientX >= -0.25f )
//				gradientX -= 0.15f;
			cornerPtr->set_gradient_x( gradientX );

			// set gradient_y
			float gradientY;
			if(y <= 0)
			{
				err_when(y < 0);
				gradientY = float(4*plasma.get_pix(x,y+1) - plasma.get_pix(x,y+2) - 3*plasma.get_pix(x,y))
					/ (2 * LOCATE_HEIGHT);
			}
			else if( y >= max_y_loc )
			{
				err_when(y > max_y_loc);
				gradientY = float(plasma.get_pix(x,y-2) - 4*plasma.get_pix(x,y-1) + 3*plasma.get_pix(x,y))
					/ (2 * LOCATE_HEIGHT);
			}
			else
			{
				gradientY = float(plasma.get_pix(x,y+1) - plasma.get_pix(x,y-1))
					/ (2 * LOCATE_HEIGHT);
			}

//			if( gradientY >= 0.0f && gradientY <= 0.25f )
//				gradientY += 0.15f;
//			else if( gradientY < 0.0f && gradientY >= -0.25f )
//				gradientY -= 0.15f;
			cornerPtr->set_gradient_y( gradientY );

		}
	}

	// calculate polynomial coefficient
	for(y = 0; y < max_y_loc; ++y )
	{
		for(x = 0; x < max_x_loc; ++x)
		{
			LocationCorners lc;
			get_loc_corner(x,y, &lc);
			short &z0 = lc.top_left->altitude;
			short &z1 = lc.top_right->altitude;
			short &z2 = lc.bottom_left->altitude;
			short &z3 = lc.bottom_right->altitude;
			short &duz0w = lc.top_left->gradient_x;		// du/dz * LOCATE_WIDTH
			short &dvz0h = lc.top_left->gradient_y;
			short &duz1w = lc.top_right->gradient_x;
			short &dvz1h = lc.top_right->gradient_y;
			short &duz2w = lc.bottom_left->gradient_x;
			short &dvz2h = lc.bottom_left->gradient_y;
			short &duz3w = lc.bottom_right->gradient_x;
			short &dvz3h = lc.bottom_right->gradient_y;

			lc.loc_ptr->c30 = (duz1w + duz0w - (z1-z0) * 2) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT);
			lc.loc_ptr->c21 = (duz3w + duz0w - duz1w - duz2w) << (C_MULTIPLIER_SHIFT - 1 - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT);
			lc.loc_ptr->c12 = (dvz3h + dvz0h - dvz1h - dvz2h) << (C_MULTIPLIER_SHIFT - 1 - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT);
			lc.loc_ptr->c03 = (dvz2h + dvz0h - (z2-z0) * 2) << (C_MULTIPLIER_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT);
			lc.loc_ptr->c20 = ( (z1-z0) * 3 - duz1w - duz0w * 2 ) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT);
			lc.loc_ptr->c11 = (( z3 + z0 - z1 - z2 ) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT))
				- (lc.loc_ptr->c21 << LOCATE_WIDTH_SHIFT) - (lc.loc_ptr->c12 << LOCATE_HEIGHT_SHIFT);
			lc.loc_ptr->c02 = ( (z2-z0) * 3 - dvz2h - dvz0h * 2 ) << (C_MULTIPLIER_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT);
			lc.loc_ptr->c00 = z0 << C_MULTIPLIER_SHIFT;
//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:ogenmap.cpp


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