我怎么做两点之间的碰撞检查呢?(c++)
How could I do a collision check between two points? (C++)
基本上,我正在制作的程序将允许用户导入3d模型(作为fbx或obj)。然后它将在窗口中使用openGL进行渲染,然后用户将能够在模型上放置点。
我的问题是,如何在这两个点之间做碰撞检查。所以如果当一条直线从一个点画到另一个点,如果它碰到3d模型,它可以返回" true "如果它根本没有通过模型,它将返回'false'。
下面的图片显示了我将如何应用它。(在下图中,线迹在与模型碰撞后变成绿色,我只是在blender中制作了这张照片,以帮助描述我的意思。)使用
伪代码:
function rayhitsmodel(model, pointA, pointB):
max-distance <- distance-between(pointA, pointB)
ray-source <- pointA
ray-direction <- normalize-vector(pointB - pointA)
for each triangle-index in model.triangle-indices:
p1 <- model.points[triangle-index.point1]
... similarly for p2, p3
triangle <- p1, p2, p3
intersection <- intersect-with-triangle(ray-source, ray-direction, triangle)
if intersection is not nothing
and distance-between(intersection.point, ray-source) <= max-distance
return true
return false
射线与三角形相交:https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm.
可以大量优化,例如,通过将模型拆分为八叉树。交点变成O(log n)而不是O(n)关于射线-八叉树相交,请参阅:射线-八叉树相交算法。
相关文章:
- valgrind-hellgrind与泄漏检查的结果不同
- C++模板来检查友元函数的存在
- 检查输入是否不是整数或数字
- 试图让变量检查数组中的某些内容
- 检查值是否在集合p1和p2中,但不在p3中
- C++概念:如何使用'concept'检查模板化结构的属性?
- 概念TS检查忽略私有访问修饰符
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- 如何在C++中检查2D数组中负值的输入验证
- C++:正在检查LinkedList中的回文-递归方法-错误
- (UE4)检查一个点是否位于碰撞圆圈中
- DontSpawnIf碰撞不会检查由 SpawnActor 函数生成的 actor
- 框 2D 同时检查多个碰撞
- 找到一种正确"(快速而准确)的方式来查找检查 2D 游戏碰撞的内容。C++
- 碰撞检测和时间复杂性:如何使检查碰撞更容易
- 如何在游戏中优化对象碰撞检查
- 用贴图检查2D平台游戏中的碰撞
- C++碰撞检测在上次检查时不起作用?
- 我怎么做两点之间的碰撞检查呢?(c++)