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


C++ ofVec2f::dot方法代码示例

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


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

示例1: waterFlowErosion

void WaterErosion::waterFlowErosion(int x, int y, ofVec2f directionVector, float water, float sediments, float lastSlope)
{
	if ((x >= 0 && x < width) && (y >= 0 && y < height))
	{
		int aValue = flowMap.getPixels()[(y * width + x) * 4 + 3];
		int bValue = flowMap.getPixels()[(y * width + x) * 4 + 2];
		int gValue = flowMap.getPixels()[(y * width + x) * 4 + 1];
		int rValue = flowMap.getPixels()[(y * width + x) * 4 + 0];

		int	hValue = heightMap.getPixels()[y * width + x];

		ofVec2f newDir;

		int	slope	= water ; 
		int step	= 0;

		int	radius	= 1;


		for (int fy = -radius; fy <= radius; fy++) {
			for (int fx = -radius; fx <= radius; fx++)
			{
				if (fy != 0 || fx != 0)
				{
					int nY = y + fy;
					int nX = x + fx;

					if ((nX >= 0 && nX < width) && (nY >= 0 && nY < height))
					{
						
						int localCell = heightMap.getPixels()[nY * width + nX];
						int localSlope = localCell - hValue;

						if (localSlope < slope)
						{
							ofVec2f localDir = ofVec2f(fx, fy);
							float theDot = directionVector.dot(localDir);
							
							if (lastSlope > -2) {
								if (theDot > -0.1 && theDot < 1 && aValue != 0)
								{
									slope = localSlope;
									newDir = ofVec2f(fx, fy);
								}
							}
							else {
								if (theDot >= 0 && aValue != 0)
								{
									slope = localSlope;
									newDir = ofVec2f(fx, fy);
									step = (localSlope > 0) ? localSlope : 0;
								}
							}
							
						}
					}
					else {
						return;
					}
				}
			}
		}

		

		if (newDir != ofVec2f(0, 0))
		{
			flowMap.getPixels()[(y * width + x) * 4 + 3] = 0;

			int tmpSlope = slope;
			if (water > 0) 
			{
				int step = slope;

				if (slope >= 0)
				{
					if (rValue > 0)
					{
						water += rValue;
						flowMap.getPixels()[(y * width + x) * 4 + 0] = 0;
					}
					water = water - slope;
					slope = -water;
				}

				float saturation = sediments / water;
				float force = water + abs(slope * 0.66 + lastSlope * 0.34 );

				if (slope <= lastSlope && saturation < water/8.0f)
				{
					float carryingCap = (water * maxSaturation - saturation) / (water * maxSaturation);
					float amount = (carryingCap > 0) ? (carryingCap * abs(force) ) * removeSoil: 0;

					if (amount < 0) {
						amount = 0;
					}
					else if (amount > 3) {
						amount = 3;		
					}
	
//.........这里部分代码省略.........
开发者ID:UlrikBronnum,项目名称:TerrainGenerator,代码行数:101,代码来源:WaterErosion.cpp


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