简体   繁体   English

OpenGL-绕特定轴旋转平面吗?

[英]OpenGL - Rotating a plane around a specific axis?

I am rotating a plane composite of these vertices, 我正在旋转这些顶点的平面合成,

Vector3[] VertexPositionData = new Vector3[]{
    new Vector3(  0f,  0f,  1f),
    new Vector3(  1f,  0f,  1f),
    new Vector3(  1f,  1f,  1f),
    new Vector3(  0f,  1f,  1f)
};

on it's y-axis with: 在y轴上具有:

Rotation.Y += (float)Math.PI / 4;

在此处输入图片说明

The effect is shown above. 效果如上所示。 But I'd rather the plane rotated around it's left edge, so that the yellow remains fixed to the red. 但是我宁愿飞机绕其左边缘旋转,以便黄色保持固定为红色。

The model matrix is calculated as per usual with, 按照通常的方式计算模型矩阵,

public Matrix4 GetModelMatrix()
{
    return Matrix4.Scale(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);
}

Besides modifying the X and Z positions, how can I achieve this? 除了修改X和Z位置,我该如何实现?

The plane is rotating around it's local Y axis, if you want the plane to rotate around it's left edge, you need to align it with the Y axis. 平面绕其本地Y轴旋转,如果要使平面绕其左边缘旋转,则需要将其与Y轴对齐。 In your case, the plane is 1 unit far from the origin on the Z axis. 在您的情况下,平面与Z轴上的原点相距1个单位。

You can either modify it's vertices like so: 您可以像这样修改其顶点:

Vector3[] VertexPositionData = new Vector3[]{
    new Vector3(  0f,  0f,  0f),
    new Vector3(  1f,  0f,  0f),
    new Vector3(  1f,  1f,  0f),
    new Vector3(  0f,  1f,  0f)
};

Or, you can translate it 1 unit on the Z axis so it would be aligned on the origin (0, 0, 0) like so: 或者,您可以将其在Z轴上平移1个单位,以使其在原点(0,0,0)上对齐,如下所示:

Matrix4 result = Matrix4.Scale(Scale) * Matrix4.CreateTranslation(new Vector3(0, 0, -1)) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);

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

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