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


C++ Mat4::setRows方法代码示例

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


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

示例1: update

//==============================================================================
void FollowPathEvent::update(F32 prevUpdateTime, F32 crntTime)
{
	MoveComponent& move = movableSceneNode->getComponent<MoveComponent>();

	I pointA = 0;
	I pointB = 0;

	// Calculate the current distance. Clamp it to max distance
	F32 crntDistance = distPerTime * (crntTime - getStartTime());
	ANKI_ASSERT(crntDistance >= 0.0);
	crntDistance = std::min(crntDistance, path->getDistance());

	const I pointsCount = path->getPoints().size();
	ANKI_ASSERT(pointsCount > 1);

	// Find the points that we lie between
	for(I i = 1; i < pointsCount; i++)
	{
		const PathPoint& ppa = path->getPoints()[i - 1];
		const PathPoint& ppb = path->getPoints()[i];

		if(crntDistance > ppa.getDistanceFromFirst() 
			&& crntDistance <= ppb.getDistanceFromFirst())
		{
			pointA = i - 1;
			pointB = i;
			break;
		}
	}

	ANKI_ASSERT(pointA < pointsCount && pointB < pointsCount);

	I preA = std::max((I)0, pointA - 1);
	I postB = std::min(pointsCount - 1, pointB + 1);
	/*I pminus2 = std::max((I)0, pointA - 2);
	I pminus1 = std::max((I)0, pointA - 1);*/

	// Calculate the u [0.0, 1.0]
	F32 u = path->getPoints()[pointB].getDistance() + getEpsilon<F32>();
	ANKI_ASSERT(u != 0.0);

	const F32 c = crntDistance 
		- path->getPoints()[pointA].getDistanceFromFirst();

	u = c / u;

	// Calculate and set new position and rotation for the movable
	/*Vec3 newPos = cubicInterpolate(
		path->getPoints()[preA].getPosition(),
		path->getPoints()[pointA].getPosition(),
		path->getPoints()[pointB].getPosition(),
		path->getPoints()[postB].getPosition(),
		u);*/
	Vec3 newPos = interpolate(
		path->getPoints()[pointA].getPosition(),
		path->getPoints()[pointB].getPosition(),
		u);

	{
		F32 u2 = u * u;
		Vec4 us(1, u, u2, u2 * u);
		F32 t = 0.7;
		
		Mat4 tentionMat(
			0.0, 1.0, 0.0, 0.0,
			-t, 0.0, t, 0.0,
			2.0 * t, t - 3.0, 3.0 - 2.0 * t, -t,
			-t, 2.0 - t, t - 2.0, t);

		Vec4 tmp = us * tentionMat;

		Mat4 posMat;
		posMat.setRows(
			Vec4(path->getPoints()[preA].getPosition(), 1.0),
			Vec4(path->getPoints()[pointA].getPosition(), 1.0),
			Vec4(path->getPoints()[pointB].getPosition(), 1.0),
			Vec4(path->getPoints()[postB].getPosition(), 1.0));

		Vec4 finalPos = tmp * posMat;

		newPos = finalPos.xyz();
	}

	Quat newRot = path->getPoints()[pointA].getRotation().slerp(
			path->getPoints()[pointB].getRotation(),
			u);

	F32 scale = move.getLocalTransform().getScale();
	Transform trf;
	trf.setOrigin(newPos);
	trf.setRotation(Mat3(newRot));
	trf.setScale(scale);
	move.setLocalTransform(trf);
}
开发者ID:zhouxh1023,项目名称:anki-3d-engine,代码行数:95,代码来源:FollowPathEvent.cpp


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