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


C++ AVector::SquaredLength方法代码示例

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


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

示例1: TestIntersection

//----------------------------------------------------------------------------
bool Bound::TestIntersection (const Bound& bound, float tmax,
							  const AVector& velocity0, const AVector& velocity1) const
{
	if (bound.GetRadius() == 0.0f || GetRadius() == 0.0f)
	{
		return false;
	}

	AVector relVelocity = velocity1 - velocity0; // 相对速度
	AVector cenDiff = bound.mCenter - mCenter; // 相对位移
	float a = relVelocity.SquaredLength();
	float c = cenDiff.SquaredLength();
	float rSum = bound.mRadius + mRadius;
	float rSumSqr = rSum*rSum;

	if (a > 0.0f)
	{
		float b = cenDiff.Dot(relVelocity);
		if (b <= 0.0f)
		{
			if (-tmax*a <= b)
			{
				return a*c - b*b <= a*rSumSqr;
			}
			else
			{
				return tmax*(tmax*a + 2.0f*b) + c <= rSumSqr;
			}
		}
	}

	return c <= rSumSqr;
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:34,代码来源:PX2Bound.cpp

示例2: IsSmallTransScope

//----------------------------------------------------------------------------
bool InputPushTransformController::IsSmallTransScope()
{
	AVector smallScope = mMaxPosSmall - mMinPosSmall;
	float lengthSquare = smallScope.SquaredLength();

	return 0.0f != lengthSquare;
}
开发者ID:PhoenixSteam,项目名称:Phoenix3D,代码行数:8,代码来源:PX2InputPushTransformController.cpp

示例3: GetRangeActors

//-----------------------------------------------------------------------------
void Scene::GetRangeActors (std::vector<Actor*> &actors, const APoint &center, 
	float radius, bool useActorSelfRadius, const std::bitset<16> &bits)
{
	actors.clear();

	if (SMT_NONE == mSceneManageType)
	{
		for (int i=0; i<GetNumActors(); i++)
		{
			Actor *actor = GetActor(i);
			if (!actor->IsVisible())
				continue;

			const APoint &pos = actor->GetPosition();
			AVector dir = pos - center;
			float lengthSquare = dir.SquaredLength();

			float adjustLength = radius;
			if (useActorSelfRadius)
			{
				adjustLength += actor->GetSelfRadius();
			}

			if (lengthSquare < adjustLength*adjustLength)
			{
				if (actor->IsContainAllBits(bits))
				{
					actors.push_back(actor);
				}
			}
		}
	}
	else
	{
		if (SMT_OCTREE == mSceneManageType)
		{
		}
		else if (SMT_CELL2D == mSceneManageType)
		{
			mCellSpace->CalculateNeighbors(actors, center, radius, 
				useActorSelfRadius, bits);
		}
	}
}
开发者ID:SylviaTanenbaum,项目名称:3d-simulation-and-game,代码行数:45,代码来源:PX2Scene.cpp

示例4: Curvature

//----------------------------------------------------------------------------
float CurveSegment::Curvature (float u) const
{
    AVector velocity = PU(u);
    float speedSqr = velocity.SquaredLength();

    if (speedSqr >= Mathf::ZERO_TOLERANCE)
    {
        AVector acceleration = PUU(u);
        AVector cross = velocity.Cross(acceleration);
        float numer = cross.Length();
        float denom = Mathf::Pow(speedSqr, 1.5f);
        return numer/denom;
    }
    else
    {
        // Curvature is indeterminate, just return 0.
        return 0.0f;
    }
}
开发者ID:Kiichi77,项目名称:WildMagic,代码行数:20,代码来源:Wm5CurveSegment.cpp

示例5: Torsion

//----------------------------------------------------------------------------
float CurveSegment::Torsion (float u) const
{
    AVector velocity = PU(u);
    AVector acceleration = PUU(u);
    AVector cross = velocity.Cross(acceleration);
    float denom = cross.SquaredLength();

    if (denom >= Mathf::ZERO_TOLERANCE)
    {
        AVector jerk = PUUU(u);
        float numer = cross.Dot(jerk);
        return numer/denom;
    }
    else
    {
        // Torsion is indeterminate, just return 0.
        return 0.0f;
    }
}
开发者ID:Kiichi77,项目名称:WildMagic,代码行数:20,代码来源:Wm5CurveSegment.cpp

示例6: GetRangeActors

//----------------------------------------------------------------------------
void Scene::GetRangeActors(std::vector<Actor*> &actors, const APoint &center,
	float radius, bool useActorSelfRadius, const std::bitset<PX2_ACTOR_BS_SIZE> &bits)
{
	actors.clear();

	if (SMT_NONE == mSceneManageType)
	{
		for (int i = 0; i < GetNumChildren(); i++)
		{
			Actor *actor = DynamicCast<Actor>(GetChild(i));
			if (!actor->IsShow()) continue;

			const APoint &pos = actor->LocalTransform.GetTranslate();
			AVector dir = pos - center;
			float lengthSquare = dir.SquaredLength();

			float adjustLength = radius;
			if (useActorSelfRadius)
			{
				adjustLength += actor->GetRadius();
			}

			if (lengthSquare < adjustLength*adjustLength)
			{
				if (actor->IsContainAllBits(bits))
				{
					actors.push_back(actor);
				}
			}
		}
	}
	else
	{
		if (SMT_OCTREE == mSceneManageType)
		{
		}
		else if (SMT_CELL2D == mSceneManageType)
		{
			mCellSpace->CalculateNeighbors(actors, center, radius,
				useActorSelfRadius, bits);
		}
	}
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:44,代码来源:PX2Scene_Manager.cpp

示例7: CalculateNeighbors

//-----------------------------------------------------------------------------
void CellSpace::CalculateNeighbors(std::vector<Actor*> &actors,
	const APoint &targetPos, float queryRadius, bool useActorSelfRadius,
	const std::bitset<PX2_ACTOR_BS_SIZE> &bits)
{
	AVector radiusDir = AVector(queryRadius, queryRadius, queryRadius);
	APoint min = targetPos - radiusDir;
	APoint max = targetPos + radiusDir;

	AxisAlignedBox3f queryBox(min, max);

	std::vector<Cell>::iterator curCell = mCells.begin();
	for (; curCell != mCells.end(); ++curCell)
	{
		if (curCell->AlignedBox.TestIntersection(queryBox) &&
			!curCell->Members.empty())
		{
			std::list<Actor*>::iterator it = curCell->Members.begin();
			for (; it != curCell->Members.end(); ++it)
			{
				if (!(*it)->IsShow())
					continue;

				AVector disDir = (*it)->LocalTransform.GetTranslate() - targetPos;
				float distanceSquared = disDir.SquaredLength();

				float adjustDist = queryRadius;
				if (useActorSelfRadius)
				{
					adjustDist += (*it)->GetRadius();
				}

				if (distanceSquared <= adjustDist*adjustDist)
				{
					if ((*it)->IsContainAllBits(bits))
					{
						actors.push_back(*it);
					}
				}
			}
		}
	}
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:43,代码来源:PX2CellSpace.cpp

示例8: GrowToContain

//----------------------------------------------------------------------------
void Bound::GrowToContain (const Bound& bound)
{
	if (bound.GetRadius() == 0.0f)
	{
		// The node is a dummy node and cannot affect growth.
		return;
	}

	if (GetRadius() == 0.0f)
	{
		mCenter = bound.GetCenter();
		mRadius = bound.GetRadius();
		
		return;
	}

	AVector centerDiff = bound.mCenter - mCenter;
	float lengthSqr = centerDiff.SquaredLength();
	float radiusDiff = bound.mRadius - mRadius;
	float radiusDiffSqr = radiusDiff*radiusDiff;

	if (radiusDiffSqr >= lengthSqr)
	{
		if (radiusDiff >= 0.0f)
		{
			mCenter = bound.mCenter;
			mRadius = bound.mRadius;
		}
		return;
	}

	float length = Mathf::Sqrt(lengthSqr);
	if (length > Mathf::ZERO_TOLERANCE)
	{
		float coeff = (length + radiusDiff)/(2.0f*length);
		mCenter += coeff*centerDiff;
	}

	mRadius = 0.5f*(length + mRadius + bound.mRadius);
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:41,代码来源:PX2Bound.cpp

示例9: CreateScene

//----------------------------------------------------------------------------
void VolumeTextures::CreateScene ()
{
	mScene = new0 Node();
	mAlphaState = new0 AlphaState();
	mAlphaState->BlendEnabled = true;
	mRenderer->SetOverrideAlphaState(mAlphaState);
	mCullState = new0 CullState();
	mCullState->Enabled = false;
	mRenderer->SetOverrideCullState(mCullState);

	// Create the grid of square meshes.
	const int numSlices = 64;
	const int numSamples = 32;

	// The vertex format that is shared by all square meshes.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT3, 0);
	int vstride = vformat->GetStride();

	// The index buffer that is shared by all square meshes.
	int numIndices = 6*(numSamples-1)*(numSamples-1);
	IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int));
	int* indices = (int*)ibuffer->GetData();
	for (int i1 = 0; i1 < numSamples - 1; ++i1)
	{
		for (int i0 = 0; i0 < numSamples - 1; ++i0)
		{
			int v0 = i0 + numSamples * i1;
			int v1 = v0 + 1;
			int v2 = v1 + numSamples;
			int v3 = v0 + numSamples;
			*indices++ = v0;
			*indices++ = v1;
			*indices++ = v2;
			*indices++ = v0;
			*indices++ = v2;
			*indices++ = v3;
		}
	}

	// Create the volume texture.  Three Gaussian distributions are used for
	// the RGB color channels.  The alpha channel is constant.
	const int bound = 64;
	Texture3D* texture = new0 Texture3D(Texture::TF_A8R8G8B8, bound, bound,
	                                    bound, 1);
	unsigned char* data = (unsigned char*)texture->GetData(0);
	const float mult = 1.0f/(bound - 1.0f);
	const float rParam = 0.01f;
	const float gParam = 0.01f;
	const float bParam = 0.01f;
	const float extreme = 8.0f;
	APoint rCenter( 0.5f*extreme,  0.0f,         0.0f);
	APoint gCenter(-0.5f*extreme, -0.5f*extreme, 0.0f);
	APoint bCenter(-0.5f*extreme, +0.5f*extreme, 0.0f);
	unsigned char commonAlpha = 12;
	APoint point;
	for (int z = 0; z < bound; ++z)
	{
		point[2] = -extreme + 2.0f*extreme*mult*z;
		for (int y = 0; y < bound; ++y)
		{
			point[1] = -extreme + 2.0f*extreme*mult*y;
			for (int x = 0; x < bound; ++x)
			{
				point[0] = -extreme + 2.0f*extreme*mult*x;

				AVector diff = point - rCenter;
				float sqrLength = diff.SquaredLength();
				float rGauss = 1.0f - rParam*sqrLength;
				if (rGauss < 0.0f)
				{
					rGauss = 0.0f;
				}

				diff = point - gCenter;
				sqrLength = diff.SquaredLength();
				float gGauss = 1.0f - gParam*sqrLength;
				if (gGauss < 0.0f)
				{
					gGauss = 0.0f;
				}

				diff = point - bCenter;
				sqrLength = diff.SquaredLength();
				float bGauss = 1.0f - bParam*sqrLength;
				if (bGauss < 0.0f)
				{
					bGauss = 0.0f;
				}

				*data++ = (unsigned char)(255.0f*bGauss);
				*data++ = (unsigned char)(255.0f*gGauss);
				*data++ = (unsigned char)(255.0f*rGauss);
				*data++ = commonAlpha;
			}
		}
	}

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


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