OpenGL查找到点的距离
我有一个虚拟景观,能够以第一人称方式四处走动。我希望能够走上任何 45 度或更小的斜坡。据我所知,这涉及将您当前的位置平移 x 个单位,然后找到平移点与地面之间的距离。如果该距离是 x 个单位或更多,则用户可以步行到那里。如果没有,用户就不能。我不知道如何找到一个点和负 y 方向上最近的点之间的距离。我已经在 Java3D 中对此进行了编程,但我不知道如何在 OpenGL 中对其进行编程。
I have a virtual landscape with the ability to walk around in first-person. I want to be able to walk up any slope if it is 45 degrees or less. As far as I know, this involves translating your current position out x units then finding the distance between the translated point and the ground. If that distance is x units or more, the user can walk there. If not, the user cannot. I have no idea how to find the distance between one point and the nearest point in the negative y direction. I have programmed this in Java3D, but I do not know how to program this in OpenGL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 OpenGL 上抱怨这个问题是找错了方向:OpenGL 的唯一目的是在屏幕上绘制漂亮的图片。这不是数学图书馆!
根据您的需求,有多种解决方案。这就是我解决这个问题的方法:为正确的阴影计算的法线给出了每个点的斜率。假设您的高度图(=地形)位于 XY 平面,且重力矢量
g = -Z
,则法向力为terrain_normal(x,y) · g
。法向力是将脚“推”到地面的力。如果没有足够的法向力,就没有足够的摩擦力来将肌肉力量转化为垂直于地面的运动。如果您查看法向力公式,您会发现g
和terrain_normal(x,y)
之间的角度偏差越大,法向力就越小。因此,在您的程序中,您可以简单地测试法向力是否超过某个阈值;正确的是,您可以将施加的摩擦力投射到地形上,并将其用作加速度矢量。
Barking this problem at OpenGL is barking up the wrong tree: OpenGL's sole purpose is drawing nice pictures to the screen. It's not a math library!
Depending you your demands there are several solutions. This is how I'd tackle this problem: The normals you calculate for proper shading give you the slope of each point. Say your heightmap (=terrain) is in the XY plane and your gravity vector
g = -Z
, then the normal force isterrain_normal(x,y) · g
. The normal force is, what "pushes" your feet against the ground. Without sufficient normal force, there's not enough friction to convey your muscles force into a movement perpendicular to the ground. If you look at the normal force formula you can see that the more the angle betweeng
andterrain_normal(x,y)
deviates, the smaller the normal force.So in your program you could simply test if the normal force exceeds some threshold; correctly you'd project the excerted friction force onto the terrain, and use that as acceleration vector.
如果您只有常规三角形高程图,则可以使用 重心坐标 来插值 Z 值从给定的 (X,Y) 位置。
If you just have a regular triangular hightmap you can use barycentric coordinates to interpolate Z values from a given (X,Y) position.