简体   繁体   English

贝塞尔曲线 OpenGL 根据 2d 空间移动 3d 空间

[英]Bezier Curves OpenGL Move 3d Space According to 2d space

I am trying to think about the following problem logically:我试图从逻辑上考虑以下问题:

Move an object in the 3d space in a fashion that represents a 2d user-generated bezier curve.以代表 2d 用户生成的贝塞尔曲线的方式在 3d 空间中移动对象。

As of right now, the user can create his own bezier curve (Which can be seen on the right - I render it via a shader and have access to the x,y of each control point) .截至目前,用户可以创建自己的贝塞尔曲线(可以在右侧看到 - 我通过着色器渲染它并可以访问每个控制点的 x、y)。 As of right now it has 4 control points that are moveable.截至目前,它有 4 个可移动的控制点。

在此处输入图像描述

I can't seem to think of a way to convert this 2d curve into 3d space movement.我似乎想不出将这条 2d 曲线转换为 3d 空间运动的方法。 Trying to achieve the following:试图实现以下目标:

在此处输入图像描述

From a lot of googling, I did find some resources but they all had info about how to convert the 2d point into 3d space and that is not what I want.从大量谷歌搜索中,我确实找到了一些资源,但他们都有关于如何将 2d 点转换为 3d 空间的信息,这不是我想要的。

Thanks to whoever tries to help, currently lost.感谢任何试图帮助的人,目前迷路了。 I don't need code but more of actual help in approaching such a problem.我不需要代码,但在解决此类问题时需要更多实际帮助。

Great day.愉快的一天。

In a two-dimensional plane, a point is defined by one or more combinations of its two basis vectors.在二维平面中,一个点由它的两个基向量的一个或多个组合定义。 (More combinations are possible if the two basis vectors are not orthogonal) (如果两个基向量不正交,则可能有更多组合)

To project a point onto a three-dimensional plane, you need to embed the two-dimensional vectors b1 and b2 into three-dimensional space and apply a translation t (if needed).要将点投影到三维平面上,您需要将二维向量b1b2嵌入三维空间并应用平移t (如果需要)。 In general, this matrix looks like:一般来说,这个矩阵看起来像:

[ b1x b2x tx ]
[ b1y b2y ty ]
[ b1z b2z tz ]

and you multiply (x,y, 1 ) by the matrix above.然后将 (x,y, 1 ) 乘以上面的矩阵。 If you multiply by (x,y,0) the translation is ignored which is not what you want in general.如果乘以 (x,y,0),则忽略平移,这通常不是您想要的。

Luckily, if you stick to an axis-aligned plane this is a lot simpler.幸运的是,如果你坚持使用轴对齐的平面,这会简单得多。 If we pick the z=0 plane, then the basis vectors are (1,0,0) and (0,1,0) and the translation is (0,0,0).如果我们选择 z=0 平面,那么基向量是 (1,0,0) 和 (0,1,0),平移是 (0,0,0)。 The matrix then becomes然后矩阵变为

[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 0 ]

and (x,y,1) times that matrix is just (x,y,0).并且 (x,y,1) 乘以该矩阵就是 (x,y,0)。
In other words, you can simply do:换句话说,您可以简单地执行以下操作:

vec2 bezier_2d = bezier(t);
vec3 bezier_3d = vec3(bezier_2d.x, bezier_2d.y, 0);
vec3 box_pos = original_pos + bezier_3d * scale;

where bezier(t) computes the value of the bezier function for a given timestep.其中bezier(t)计算给定时间步的贝塞尔函数值。

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

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