火山软件开发平台

标题: 求助,如何把火山的数组传进这个嵌入函数?? [打印本页]

作者: server    时间: 2024-4-8 15:38
标题: 求助,如何把火山的数组传进这个嵌入函数??

  1. #include <vector>
  2. #include <cmath>

  3. float calculateMostFrequentYawAngle(float Rx, float Ry, const std::vector<std::pair<float, float>>& monsterPositions, float angleRange = 25.0f)
  4. {
  5.     std::map<float, int> yawCounts;

  6.     for (const auto& pos : monsterPositions)
  7.     {
  8.         float dx = pos.first - Rx;
  9.         float dy = pos.second - Ry;
  10.         float yaw = std::atan2(dy, dx) * 180.0f / M_PI;

  11.         while (yaw < 0.0f)
  12.             yaw += 360.0f;
  13.         while (yaw >= 360.0f)
  14.             yaw -= 360.0f;

  15.         for (float yawInRange = yaw - angleRange; yawInRange <= yaw + angleRange; yawInRange++)
  16.         {
  17.             if (yawInRange < 0.0f)
  18.                 yawInRange += 360.0f;
  19.             else if (yawInRange >= 360.0f)
  20.                 yawInRange -= 360.0f;

  21.             yawCounts[yawInRange]++;
  22.         }
  23.     }

  24.     float mostFrequentYaw = 0.0f;
  25.     int maxCount = 0;
  26.     for (const auto& entry : yawCounts)
  27.     {
  28.         if (entry.second > maxCount)
  29.         {
  30.             mostFrequentYaw = entry.first;
  31.             maxCount = entry.second;
  32.         }
  33.     }

  34.     return mostFrequentYaw;
  35. }
复制代码




作者: Xelloss0618    时间: 2024-4-8 15:51
用别名就行,以下代码基于PIV模块


<火山程序 类型 = "通常" 版本 = 1 />

类 monsterPosition <公开 基础类 = 标准键值对模板 @模板实现类 = "单精度小数, 单精度小数">

类 monsterPositions <公开 基础类 = PIV数值模板 @模板实现类 = "monsterPosition">
{

    #
}





欢迎光临 火山软件开发平台 (https://bbs.voldp.com/) Powered by Discuz! X3.4