连续流场(flow field)。 更多...
#include <CrowdField.h>
Public 成员函数 | |
| CrowdField ()=default | |
| Crowd field. | |
| void | resize (int width, int height, float cellSize, float originX, float originY) |
| 配置网格(保留原有 cost/goals,若尺寸变化则重置)。 | |
| void | clear () |
| 清空全部数据(回到无效状态)。 | |
| bool | valid () const |
| 是否配置了有效网格。 | |
| int | getWidth () const |
| 网格尺寸访问器。 | |
| int | getHeight () const |
| Returns the height. | |
| float | getCellSize () const |
| Returns the cell size. | |
| float | getOriginX () const |
| Returns the origin x. | |
| float | getOriginY () const |
| Returns the origin y. | |
| void | setBlocked (int cx, int cy, bool blocked) |
| 设置/清除某格阻挡。 | |
| bool | isBlocked (int cx, int cy) const |
| 查询某格是否阻挡。 | |
| void | setCellCost (int cx, int cy, float cost) |
| 设置某格地形代价(进入该格的移动成本)。 | |
| float | getCellCost (int cx, int cy) const |
| 查询地形代价(越界/阻挡返回 0)。 | |
| void | setAllCellCost (float cost) |
| 把全部格子设为同一地形代价(通常 build 前重置用)。 | |
| void | setGoal (int gx, int gy) |
| 设定唯一目标格(等价 clearGoals + addGoal)。 | |
| void | addGoal (int gx, int gy) |
| 追加一个目标格(多目标支持)。 | |
| void | clearGoals () |
| 清空目标列表。 | |
| int | goalCount () const |
| 目标个数。 | |
| bool | isBuilt () const |
| 是否已 build 过(build 后或 resize 后为 true,改动地形后仍为 true)。 | |
| void | build () |
| 从目标格做 Dijkstra,生成积分场与方向场。 | |
| float | costAtCell (int cx, int cy) const |
| 查询格级积分代价(未 build 返回 kUnreachable)。 | |
| bool | isReachable (int cx, int cy) const |
| 某格是否可达(积分代价有限且非负)。 | |
| void | flowAtCell (int cx, int cy, float &dx, float &dy) const |
| 查询格级方向向量(单位长度;目标格/阻挡/不可达为 0)。 | |
| float | costAtWorld (float wx, float wy) const |
| 查询世界坐标处的积分代价(双线性插值;场外返回 kUnreachable)。 | |
| void | flowAtWorld (float wx, float wy, float &dx, float &dy) const |
| 查询世界坐标处的跟随方向(双线性插值后归一化)。 | |
| bool | resolvePenetration (float &wx, float &wy, float radius) const |
| 圆 vs 阻挡格碰撞消解:把圆心从覆盖到的阻挡格中推出来。 | |
| const std::vector< float > & | integration () const |
| 只读访问积分场(调试渲染用)。 | |
| const std::vector< float > & | flowX () const |
| 只读访问方向场 X 分量(调试渲染用)。 | |
| const std::vector< float > & | flowY () const |
| 只读访问方向场 Y 分量(调试渲染用)。 | |
静态 Public 属性 | |
| static constexpr float | kUnreachable = 3.4e38f |
| 不可达/阻挡的积分代价。 | |
详细描述
连续流场(flow field)。
build() 从所有目标格做一次 8 邻域 Dijkstra,得到到目标的积分代价 (integration cost);随后由中心差分求梯度,生成每格的单位方向向量 (沿代价下降方向)。flowAtWorld() 用双线性插值给出任意世界坐标的方向, 供单位逐帧采样跟随。
在文件 CrowdField.h 第 22 行定义.
构造及析构函数说明
◆ CrowdField()
|
default |
Crowd field.
成员函数说明
◆ addGoal()
| void eve::crowd::CrowdField::addGoal | ( | int | gx, |
| int | gy | ||
| ) |
◆ build()
| void eve::crowd::CrowdField::build | ( | ) |
从目标格做 Dijkstra,生成积分场与方向场。
在文件 CrowdField.cpp 第 91 行定义.
引用了 cx, cy, index, isBlocked(), kUnreachable, n, nx, ny , 以及 valid().
◆ clear()
| void eve::crowd::CrowdField::clear | ( | ) |
清空全部数据(回到无效状态)。
在文件 CrowdField.cpp 第 37 行定义.
◆ clearGoals()
| void eve::crowd::CrowdField::clearGoals | ( | ) |
清空目标列表。
在文件 CrowdField.cpp 第 84 行定义.
◆ costAtCell()
| float eve::crowd::CrowdField::costAtCell | ( | int | cx, |
| int | cy | ||
| ) | const |
查询格级积分代价(未 build 返回 kUnreachable)。
在文件 CrowdField.cpp 第 182 行定义.
引用了 cx, cy, index , 以及 kUnreachable.
被这些函数引用 isReachable().
◆ costAtWorld()
| float eve::crowd::CrowdField::costAtWorld | ( | float | wx, |
| float | wy | ||
| ) | const |
◆ flowAtCell()
| void eve::crowd::CrowdField::flowAtCell | ( | int | cx, |
| int | cy, | ||
| float & | dx, | ||
| float & | dy | ||
| ) | const |
◆ flowAtWorld()
| void eve::crowd::CrowdField::flowAtWorld | ( | float | wx, |
| float | wy, | ||
| float & | dx, | ||
| float & | dy | ||
| ) | const |
◆ flowX()
|
inline |
只读访问方向场 X 分量(调试渲染用)。
在文件 CrowdField.h 第 148 行定义.
◆ flowY()
|
inline |
只读访问方向场 Y 分量(调试渲染用)。
在文件 CrowdField.h 第 150 行定义.
◆ getCellCost()
| float eve::crowd::CrowdField::getCellCost | ( | int | cx, |
| int | cy | ||
| ) | const |
◆ getCellSize()
|
inline |
Returns the cell size.
在文件 CrowdField.h 第 51 行定义.
◆ getHeight()
|
inline |
Returns the height.
在文件 CrowdField.h 第 49 行定义.
◆ getOriginX()
|
inline |
Returns the origin x.
在文件 CrowdField.h 第 53 行定义.
◆ getOriginY()
|
inline |
Returns the origin y.
在文件 CrowdField.h 第 55 行定义.
◆ getWidth()
|
inline |
◆ goalCount()
|
inline |
目标个数。
在文件 CrowdField.h 第 92 行定义.
◆ integration()
|
inline |
只读访问积分场(调试渲染用)。
在文件 CrowdField.h 第 146 行定义.
◆ isBlocked()
| bool eve::crowd::CrowdField::isBlocked | ( | int | cx, |
| int | cy | ||
| ) | const |
◆ isBuilt()
|
inline |
是否已 build 过(build 后或 resize 后为 true,改动地形后仍为 true)。
在文件 CrowdField.h 第 95 行定义.
◆ isReachable()
| bool eve::crowd::CrowdField::isReachable | ( | int | cx, |
| int | cy | ||
| ) | const |
◆ resize()
| void eve::crowd::CrowdField::resize | ( | int | width, |
| int | height, | ||
| float | cellSize, | ||
| float | originX, | ||
| float | originY | ||
| ) |
配置网格(保留原有 cost/goals,若尺寸变化则重置)。
- 参数
-
width 列数(>0) height 行数(>0) cellSize 每格世界尺寸(>0) originX 世界原点 X(格 (0,0) 左下角) originY 世界原点 Y
在文件 CrowdField.cpp 第 18 行定义.
引用了 height, kUnreachable, n , 以及 width.
◆ resolvePenetration()
| bool eve::crowd::CrowdField::resolvePenetration | ( | float & | wx, |
| float & | wy, | ||
| float | radius | ||
| ) | const |
◆ setAllCellCost()
| void eve::crowd::CrowdField::setAllCellCost | ( | float | cost | ) |
◆ setBlocked()
| void eve::crowd::CrowdField::setBlocked | ( | int | cx, |
| int | cy, | ||
| bool | blocked | ||
| ) |
◆ setCellCost()
| void eve::crowd::CrowdField::setCellCost | ( | int | cx, |
| int | cy, | ||
| float | cost | ||
| ) |
◆ setGoal()
| void eve::crowd::CrowdField::setGoal | ( | int | gx, |
| int | gy | ||
| ) |
◆ valid()
|
inline |
是否配置了有效网格。
在文件 CrowdField.h 第 44 行定义.
被这些函数引用 build(), costAtWorld(), flowAtWorld(), resolvePenetration() , 以及 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().
类成员变量说明
◆ kUnreachable
|
staticconstexpr |
该类的文档由以下文件生成:
- src/modules/crowd/CrowdField.h
- src/modules/crowd/CrowdField.cpp