[英]Rotate flat 2d object around an arbitrary Axis
So I have a flat 2d Polygon and I would like to rotate each point of the Polygon around a axis defined by two 2d Points. 所以我有一个平面的2d多边形,我想围绕由两个2d点定义的轴旋转多边形的每个点。 These rotated points are later used to generate a 3d rotations object from the flat 2d Polygon.
这些旋转点稍后用于从平面2d多边形生成3d旋转对象。 So I got this at the moment:
所以我此刻得到了这个:
But with this method I don't get any usefull results. 但是使用这种方法我没有得到任何有用的结果。
For better unterstanding: P1 & P2 are defining the axis Psrc is the polygonPoint and Pdest is the final point in 3d 为了更好地展示:P1和P2定义轴Psrc是polygonPoint而Pdest是3d中的最终点
Far easier to be done. 更容易完成。 Just modify your model matrix before drawing using
glRotatef()
: 只需在使用
glRotatef()
绘制之前修改模型矩阵:
glRotatef(angle, vx, vy, vz);
angle
is obviously the angle. angle
显然是角度。 vx
, vy
, and vz
are the vector defining your rotation axis. vx
, vy
和vz
是定义旋转轴的矢量。 Or, to use it with 2 points given: 或者,使用它给出2分:
glRotatef(p1.x - p2.x, p1.y - p2.y, p1.z - p1.z);
If your rotation axis doesn't go through your world's origin, you'll have to adjust everything so your axis goes through the origin using glTranslatef()
: 如果您的旋转轴没有通过您的世界原点,您将必须调整所有内容,以便您的轴使用
glTranslatef()
遍历原点:
glTranslatef(-p1.x, -p1.y, -p1.z); // move one point on the vector into the origin
glRotatef(p1.x - p2.x, p1.y - p2.y, p1.z - p1.z); // rotate everything
glTranslatef(p1.x, p1.y, p1.z); // move everything back into position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.