我正在编写xna的基本游戏。我开始在玩家的右臂上放置一个物体(例如武器)。当我将角色向左或向右移动时。但是当我旋转我的设备没有正确定位。 我完全理解,有必要重新计算基于旋转完成的新位置,但我不知道如何。 这里是我的代码和图片 一千谢谢如何计算旋转[XNA]后附加模型的位置?
//Function that will draw the current item selection in the player's hand
private void draw_itemActionInUse(Model modelInUse)
{
int handIndex = skinningData.BoneIndices["Hand_Right"];
Matrix[] worldTransforms = animationPlayer.GetWorldTransforms();
Matrix rotationMatrixCalcul = Matrix.CreateRotationY(player.Rotation.Y);
//Here I calculate the new position of the item, but it does not work
Vector3 newPosition= Vector3.Transform(new Vector3(player.Position.X, player.Position.Y + 4, player.Position.Z), rotationMatrixCalcul);
foreach (ModelMesh mesh in modelInUse.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World =
worldTransforms[handIndex]
*
Matrix.CreateScale(2)
*
Matrix.CreateRotationY(player.Rotation.Y)
*
Matrix.CreateTranslation(newPosition);
effect.View = View_;
effect.Projection = Projection_;
effect.EnableDefaultLighting();
}
mesh.Draw();
}
}
图A: 位置:X:0,Y:0; Z:0 角度:90 图B: 位置:x:2; y:4; z:0 角度:90 图A: 位置:X:1; Y:0; Z:1 角:35 图B: 位置:如何演算该位置? 角:35
你见过这个吗? http://stackoverflow.com/questions/13890820/rotating-objects-attached-to-other-objects/13893855#13893855 – neeKo
谢谢!你可以写这个答案吗? –