更改Directx网格中心

时间:2012-05-05 10:08:56

标签: directx rotation scale mesh cube

我在用VB.NET编写的DirectX中创建了一个网格框。当我旋转并缩放网格时,它是从中心进行的。

如何更改网格中心,类似于下图:

Mesh Center

1 个答案:

答案 0 :(得分:1)

将网格矩阵转换为旋转/缩放中心,应用旋转/缩放,然后将矩阵转换回来。 e.g:

matWorld = Matrix.Identity

' Translate to rotation/scaling center
matWorld = matWorld * Matrix.Translate(0.1, 0.2, 0.3)

' Apply your rotation/scaling
matWorld = matWorld * Matrix.RotationZ(0.01)

' Translate from rotation/scaling center
matWorld = matWorld * Matrix.Translate(-0.1, -0.2, -0.3)

' Assign matWorld as world transformation matrix
device.Transform.World = matWorld

注意:我没有对上述内容进行测试,因此可能存在语法问题。