我尝试从它的中心而不是边缘旋转一个 3D 立方体。这是我使用的代码。
public rotatemyCube()
{
...
Matrix newTransform = Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation);
my3Dcube.Transform = newTransform;
....
public void updateRotateCube()
{
rotationLoot += 0.01f;
}
我的立方体旋转得很好,但不是从中心旋转。这是解释我的问题的示意图。
我需要这个:
我的完整代码
private void updateMatriceCubeToRotate()
{
foreach (List<instancedModel> ListInstance in listStructureInstance)
{
foreach (instancedModel instanceLoot in ListInstance)
{
if (my3Dcube.IsAloot)
{
Vector3 scale;
Quaternion rotation;
Vector3 translation;
//I get the position, rotation, scale of my cube
my3Dcube.Transform.Decompose(out scale,out rotation,out translation);
var rotationCenter = new Vector3(0.1f, 0.1f, 0.1f);
//Create new transformation with new rotation
Matrix transformation =
Matrix.CreateTranslation(- rotationCenter)
* Matrix.CreateScale(scale)
* Matrix.CreateRotationY(rotationLoot)
* Matrix.CreateTranslation( translation);
my3Dcube.Transform = transformation;
}
}
}
//Incremente rotation
rotationLoot += 0.05f;
}