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


C++ VMArray::Allocate方法代码示例

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


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

示例1: FindCloseActor

	// 一定距離内に居るアクターをすべて返す
	VMArray<Actor*> FindCloseActor(float distance, UInt32 sortOrder)
	{
		enum Order {
			kSortOrder_distance		= 0,		// 距離が近い順
			kSortOrder_crosshair	= 1,		// クロスヘアに近い順
			kSortOrder_zaxis_clock	= 2,		// Z軸時計回り
			kSortOrder_zaxis_rclock	= 3,		// Z軸逆時計回り
			kSortOrder_invalid      = 4
		};

		double fovThreshold = (double)PlayerCamera::GetSingleton()->worldFOV / 180.0 * M_PI /2;

		VMArray<Actor*> result;
		result.arr = NULL;

		tArray<UInt32>* actorHandles = &(*s_cellInfo)->actorHandles;
		if (actorHandles->count == 0)
			return result;

		std::vector<std::pair<double, Actor*>> vec;
		vec.reserve(actorHandles->count);

		PlayerCharacter* player = *g_thePlayer;
		NiPoint3 camPos;
		GetCameraPos(&camPos);

		UInt32 handle;
		size_t i = 0;
		while (actorHandles->GetNthItem(i++, handle))
		{
			TESObjectREFR* ref = NULL;
			if (handle != *g_invalidRefHandle)
				LookupREFRByHandle(&handle, &ref);

			if (ref && ref->formType == kFormType_Character)
			{
				Actor* actor = (Actor*)ref;
				NiPoint3 pos;
				GetTargetPos(actor, &pos);
				double dx = pos.x - camPos.x;
				double dy = pos.y - camPos.y;
				double dz = pos.z - camPos.z;
				double dd = sqrt(dx*dx + dy*dy + dz*dz);

				if (distance <= 0 || dd <= distance)
				{
					double point;
					NiPoint3 cameraAngle;
					GetCameraAngle(&cameraAngle);
					double angleZ = NormalRelativeAngle(atan2(dx, dy) - cameraAngle.z);
					double angleX = NormalRelativeAngle(atan2(-dz, sqrt(dx*dx + dy*dy)) - cameraAngle.x);
					
					if (abs(angleZ) < fovThreshold)
					{
						switch (sortOrder)
						{
						case kSortOrder_distance:
							point = dd;
							break;
						case kSortOrder_crosshair:
							point = sqrt(angleZ*angleZ + angleX*angleX);
							break;
						case kSortOrder_zaxis_clock:
							point = NormalAbsoluteAngle(atan2(dx, dy) - cameraAngle.z);
							break;
						case kSortOrder_zaxis_rclock:
							point = 2*M_PI - NormalAbsoluteAngle(atan2(dx, dy) - cameraAngle.z);
							break;
						default:
							point = 0;
							break;
						}

						if (point >= 0)
						{
							vec.push_back(std::make_pair(point, actor));
						}
					}
				}
			}
		}

		if (vec.size() == 0)
			return result;

		if (sortOrder < kSortOrder_invalid)
			std::sort(vec.begin(), vec.end());

		// Papyrusに返す配列を確保
		if (result.Allocate(vec.size()))
		{
			for (i = 0; i < vec.size(); i++)
			{
				result.Set(&vec[i].second, i);
			}
		}

		return result;
	}
开发者ID:himika,项目名称:LockOn,代码行数:100,代码来源:Papyrus.cpp


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