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


C++ Point::GetLength方法代码示例

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


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

示例1: RecalculatePath

void MovingObjectModel::RecalculatePath()
{
	//Only do stuff if the path contains elements.
	if(m_Path != NULL && !m_Path->empty())
	{
		auto next = m_Path->at(0);

		Point tempDirection = next - GetPosition();
		float distance = tempDirection.GetLength();
		tempDirection = tempDirection.GetNormalizedPoint();

		Point oppositDirection = m_Direction.GetNegatedPoint();
		oppositDirection = oppositDirection.GetNormalizedPoint();

		//If direction got negated, we overshot our target or if we have reached our next goal
		if(tempDirection == &oppositDirection || distance < 0.01f)
		{
			m_Path->erase(m_Path->begin());

			if(m_Path->empty())
			{
				m_MovementSpeed = 0;
			}
			else
			{
				next = m_Path->at(0);
				auto pos = GetPosition();

				Point newDirection = next - pos;
				newDirection = newDirection.GetNormalizedPoint();

				if(m_Owner != NULL)
				{
					m_Owner->setLookAt2D(newDirection.X, newDirection.Y);
				}
				else
				{
					SetDirection(newDirection.X, newDirection.Y);
				}
			}

		}
	}
}
开发者ID:gnub,项目名称:itugameengine,代码行数:44,代码来源:PhysicsModel.cpp

示例2: if

void Voronoi::Thread :: _calculate( double x, double y, double z, double da[4], double pa[12])
{
	int xi = Floor(x); // Standard floor flushes the processor pipeline. This is from Global.h included in g3.h
	int yi = Floor(y);
	int zi = Floor(z);

	da[0] = da[1] = da[2] = da[3] = DBL_MAX;
	Point<double, 3> V;
	for(int xx=xi-1; xx<=xi+1; ++xx)
	{
		for(int yy=yi-1; yy<=yi+1; ++yy)
		{
			for(int zz=zi-1; zz<=zi+1; ++zz)
			{ // Things in this inner loop will happen 27 times:
				const float * p = _getPoint( xx, yy, zz);
				V = Point<double, 3>( x - (p[0] + xx), y - (p[1] + yy), z - (p[2] + zz));
				double d;
				switch (m_eDistance)
				{
				default:
				case eLength:// Euclidean (shortest line).
					d = V.GetLength();
					break;

				case eLength2:// The length squared. Saves the slow Square Root for some calculations.
					d = V.GetSquaredLength();
					break;
/*
				case eManhattan:// The length of the distance in axial directions (as if travelling around a city). Saves the slow Square Root for some calculations.
					d = V.GetManhattan();
					break;

				case eChebychev:// The length of the longest Axial journey. Saves the slow Square Root for some calculations.
					d = V.GetChebychev();
					break;

				case eQuadratic:// The sum of everything multiplied by everything else!
					d = V.GetQuadratic();
					break;
				case eMinkowski4:// Minkowski(4); pow(x*x*x*x+y*y*y*y+z*z*z*z,0.25);   p=4 in: pow(pow(x.abs(), p) + pow(y.abs(), p) + pow(z.abs(), M_E), 1.0/p);
					d = V.GetMinkowski( 4.0f);
					break;
				case eMinkowski5:// Same as Minkowski(0.5);
					d = V.GetMinkowski( 0.5f);
					break;
*/
				}

				if (d < da[0])
				{
					da[3] = da[2];
					da[2] = da[1];
					da[1] = da[0];

					da[0] = d; // Insert at 0

					pa[9] = pa[6];
					pa[10] = pa[7];
					pa[11] = pa[8];

					pa[6] = pa[3];
					pa[7] = pa[4];
					pa[8] = pa[5];

					pa[3] = pa[0];
					pa[4] = pa[1];
					pa[5] = pa[2];

					pa[0] = p[0] + xx;
					pa[1] = p[1] + yy;
					pa[2] = p[2]+zz;
				}
				else if (d < da[1])
				{
					da[3] = da[2];
					da[2] = da[1];

					da[1] = d;            // Insert at 1

					pa[9] = pa[6];
					pa[10] = pa[7];
					pa[11] = pa[8];

					pa[6] = pa[3];
					pa[7] = pa[4];
					pa[8] = pa[5];

					pa[3] = p[0] + xx;
					pa[4] = p[1] + yy;
					pa[5] = p[2] + zz;
				}
				else if (d < da[2])
				{
					da[3] = da[2];
					da[2] = d;                             // Insert at 2

					pa[9] = pa[6];
					pa[10] = pa[7];
					pa[11] = pa[8];

//.........这里部分代码省略.........
开发者ID:DragonJoker,项目名称:ProceduralGenerator,代码行数:101,代码来源:GeneratorVoronoi.cpp


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