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


C++ Quaternion::Difference方法代码示例

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


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

示例1: buildSegment

void TreeStem::buildSegment(TreeGeneralParams generalParams, TreeSegment* prevSeg, int segIndex, 
							float splitAngle, float divergeAngle, float rotateYAngle, LevelContext& context)
{
	_Assert(segIndex < mLevelParams.curveRes);

	static int dbNumSegs[4];
	dbNumSegs[mLevelParams.level]++;
	ConsolePrint(L"current numSegs: (0-%d),(1-%d),(2-%d),(3-%d)\n", dbNumSegs[0], dbNumSegs[1], dbNumSegs[2], dbNumSegs[3]);

	int numSegs = mLevelParams.curveRes;
	float segLength = mLength / numSegs;

	TreeSegment* seg = New TreeSegment;

	float curveDelta = 0;
	if(segIndex != 0)
	{
		if(mLevelParams.curveBack == 0)
		{
			curveDelta = mLevelParams.curve / mLevelParams.curveRes;
		}
		else
		{
			if(segIndex < (mLevelParams.curveRes + 1) / 2)
				curveDelta = 2 * mLevelParams.curve / mLevelParams.curveRes;
			else
				curveDelta = -2 * mLevelParams.curveBack / mLevelParams.curveRes;
		}

		curveDelta += RandomVariation(0, mLevelParams.curveV) / mLevelParams.curveRes;
	}

	Vector3 basePos;
	if(prevSeg == NULL)
		basePos = Vector3::Zero;
	else
		basePos = Vector3(0, segLength, 0);

	seg->mPos = basePos;
	seg->mOrient = Quaternion(0, DEGREE_TO_RAD(divergeAngle), DEGREE_TO_RAD(curveDelta + splitAngle));
	seg->mSegIndex = segIndex;
	seg->mParent = prevSeg;
	seg->mStem = this;

	Quaternion parentOrientWorld;
	if(prevSeg)
	{
		prevSeg->mChildren.push_back(seg);
		parentOrientWorld = prevSeg->mOrientWorld;
	}
	else
	{
		mFirstSeg = seg;
		parentOrientWorld = mOrient;
	}

	// divergeAngle是绕世界的y轴旋转
	seg->mOrientWorld = Quaternion(0, DEGREE_TO_RAD(rotateYAngle), 0) * (parentOrientWorld * seg->mOrient);
	seg->mOrient = WorldRotationToLocal(parentOrientWorld.Difference(seg->mOrientWorld), parentOrientWorld);

	// create seg vb ...
	std::vector<float> segRadius;
	{
		float offset = (float)segIndex / numSegs;
		float offsetDelta = 1.0f / numSegs / mLevelParams.segSegsH;
		for(int i = 0; i <= mLevelParams.segSegsH; ++i)
		{
			segRadius.push_back(GetStemRadius(offset));
			offset += offsetDelta;
		}
	}

	bool closeTop = true;
	bool closeBottom = true;
	//if(segIndex == 0)
	//	closeBottom = true;
	//if(segIndex == numSegs - 1)
	//	closeTop = true;

	seg->mGeo = New TreeSegGeo(segLength, mLevelParams.segSegsW, mLevelParams.segSegsH, segRadius, 
 		Quaternion(0, 0, DEGREE_TO_RAD(curveDelta + splitAngle)), closeTop, closeBottom);
	seg->mGeo->CalculateNormals();
	seg->mGeo->BuildGeometry(XYZ_N);

	// branches
	if(seg->mStem->GetNumBranches() != 0 && mLevelParams.level < generalParams.levels - 1)
	{
		float baseOffset = 0;
		if(mLevelParams.level == 0)
		{
			float baseLength = generalParams.baseSize * mLength;
			baseOffset = baseLength - segIndex * segLength;
		}

		float offset = 0;
		if(baseOffset <= 0)
		{
			offset = mBranchInterval - context.branchDistError;
		}
		else if(baseOffset < segLength)
//.........这里部分代码省略.........
开发者ID:SinYocto,项目名称:Zee,代码行数:101,代码来源:Tree.cpp


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