本文整理汇总了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;
}