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


C++ Vector3d::getDistanceTo方法代码示例

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


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

示例1: nextCommandIf

Command *Command::opIsItemNearPlace(const ResourceReference &itemRef, const ResourceReference &positionRef, int32 testDistance) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();

	Math::Vector3d itemPostion = item->getPosition3D();
	Math::Vector3d testPosition = getObjectPosition(positionRef);

	return nextCommandIf(itemPostion.getDistanceTo(testPosition) < testDistance);
}
开发者ID:DouglasLiuGamer,项目名称:residualvm,代码行数:8,代码来源:command.cpp

示例2:

Math::Vector3d StringPullingPath::computeWalkTarget(const Math::Vector3d &fromPosition) {
	Current *current = StarkGlobal->getCurrent();
	Resources::Floor *floor = current->getFloor();

	// HACK: Sometimes the character gets stuck because of rounding errors
	// If we detect the character is stuck on a step, just make it go to the next one.
	// TODO: Improve the string pulling code so that the targets can also be points between two steps.
	if (fromPosition.getDistanceTo(_steps[_targetStep]) < 1.0 && _targetStep < _steps.size() - 1) {
		_targetStep++;
	}

	for (uint i = _targetStep + 1; i < _steps.size(); i++) {
		Math::Line3d testSegment = Math::Line3d(fromPosition, _steps[i]);
		if (!floor->isSegmentInside(testSegment)) {
			break;
		}

		_targetStep = i;
	}

	return _steps[_targetStep];
}
开发者ID:Botje,项目名称:residualvm,代码行数:22,代码来源:stringpullingpath.cpp

示例3: getEdgeLength

float Path::getEdgeLength(uint edgeIndex) const {
	Math::Vector3d edgeStart = getVertexPosition(edgeIndex);
	Math::Vector3d edgeEnd = getVertexPosition(edgeIndex + 1);

	return edgeStart.getDistanceTo(edgeEnd);
}
开发者ID:Botje,项目名称:residualvm,代码行数:6,代码来源:path.cpp

示例4: onGameLoop

void Walk::onGameLoop() {
	if (!_path->hasSteps()) {
		// There is no path to the destination
		stop();
		return;
	}

	Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();

	// Get the target to walk to
	Math::Vector3d currentPosition = _item3D->getPosition3D();
	Math::Vector3d target = _path->computeWalkTarget(currentPosition);

	// Compute the direction to walk into
	Math::Vector3d direction = target - currentPosition;
	direction.z() = 0;
	direction.normalize();

	// Compute the angle with the current character direction
	Math::Vector3d currentDirection = _item3D->getDirectionVector();
	float directionDeltaAngle = computeAngleBetweenVectorsXYPlane(currentDirection, direction);

	// If the angle between the current direction and the new one is too high,
	// make the character turn on itself until the angle is low enough
	if (ABS(directionDeltaAngle) > getAngularSpeed() + 0.1f) {
		_turnDirection = directionDeltaAngle < 0 ? kTurnLeft : kTurnRight;
	} else {
		_turnDirection = kTurnNone;
	}

	float distancePerGameloop = computeDistancePerGameLoop();

	Math::Vector3d newPosition;
	if (_turnDirection == kTurnNone) {
		// Compute the new position using the distance per gameloop
		if (currentPosition.getDistanceTo(target) > distancePerGameloop) {
			newPosition = currentPosition + direction * distancePerGameloop;
		} else {
			newPosition = target;
		}
	} else {
		// The character does not change position when it is turning
		newPosition = currentPosition;
		direction = currentDirection;

		Math::Matrix3 rot;
		rot.buildAroundZ(_turnDirection == kTurnLeft ? -getAngularSpeed() : getAngularSpeed());
		rot.transformVector(&direction);
	}

	// Some scripts expect the character position to be the exact destination
	if (newPosition == _destination) {
		_reachedDestination = true;
		stop();
	}

	// Update the new position's height according to the floor
	int32 newFloorFaceIndex = floor->findFaceContainingPoint(newPosition);
	if (newFloorFaceIndex >= 0) {
		floor->computePointHeightInFace(newPosition, newFloorFaceIndex);
	} else {
		warning("Item %s is walking off the floor", _item->getName().c_str());
	}

	// Update the item's properties
	_item3D->setPosition3D(newPosition);
	if (direction.getMagnitude() != 0.0) {
		_item3D->setDirection(computeAngleBetweenVectorsXYPlane(direction, Math::Vector3d(1.0, 0.0, 0.0)));
	}
	if (newFloorFaceIndex >= 0) {
		// When unable to find the face containing the new position, keep the previous one
		// to prevent draw order glitches.
		_item3D->setFloorFaceIndex(newFloorFaceIndex);
	}

	changeItemAnim();
}
开发者ID:Botje,项目名称:residualvm,代码行数:77,代码来源:walk.cpp


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