简体   繁体   English

正确定向3D网格以指向其前进方向

[英]Properly orienting a 3D mesh to point in the direction it's heading

I'm trying to get a mesh to traverse a circuit across a sphere. 我正试图获得一个网格来遍历一个球体上的电路。 I took the image that is wrapped around the sphere, and coloured the path that I want the mesh to follow. 我拍摄了包裹在球体上的图像,并对希望网格物体遵循的路径进行了着色。 Then I computed all of the (u, v) points of the path. 然后,我计算了路径的所有(u,v)点。 Using the (u, v) points, I convert to spherical coordinates to get the mesh onto the sphere, and set the rotations around the X and Y axes rot.x and rot.y , so that the mesh is tangent to the sphere and faces the north pole of the sphere. 使用(u,v)点,我将转换为球面坐标以将网格放置到球体上,并设置绕X和Y轴的旋转rot.xrot.y ,以便网格与球体相切,并且面对球体的北极。 My problem is getting the mesh to face the direction it's heading in. The third rotation variable, rot.z , is used to set the heading of the mesh. 我的问题是使网格面向其前进方向。第三个旋转变量rot.z用于设置网格的前进方向。 Currently, I get the (u, v) points from the 5th to 14th points to come, and take the average of the angles of elevation of the line segment of the current point and each of the 10 future points. 目前,我得到了从第5点到第14点的(u,v)点,并取当前点和10个未来点的线段的仰角的平均值。 This works, but the two drawbacks are that the heading vibrates very frequently, and also the heading has a tendency to be inaccurate when turning somewhat sharply. 这是可行的,但是两个缺点是航向非常频繁地振动,并且在稍微急转弯时航向也有不精确的趋势。 What is a good method for calculating the heading of the mesh? 什么是计算网格方向的好方法?

An easy approach is to build a rotation matrix. 一种简单的方法是构建旋转矩阵。 With that you don't have to think about angles, because if you know the direction and either the up or right vector all entries can be calculated. 这样,您就不必考虑角度了,因为如果您知道方向以及上矢量或右矢量,则可以计算所有条目。 In your case the direction is the tangent on the sphere and the up vector the normal at that point. 在您的情况下,方向是球体上的切线,而向上矢量是该点处的法线。

vec3 direction = tangent;
vec3 up = normal;
vec3 right = cross(direction,up);

mat3 m;
m[0] = right;
m[1] = up;
m[2] = direction;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM