Je suis en train de programmer un jeu de base sur xna. J'ai commencé à placer un objet (par exemple une arme) attaché au bras droit de mon joueur. Quand je déplace mon personnage vers l'avant derrière la gauche ou la droite, tout va bien. Mais quand je tourne, mon équipement n'est pas positionné correctement. Je comprends parfaitement qu'il est nécessaire de recalculer la nouvelle position en fonction de la rotation effectuée mais je ne vois pas comment. Voici mon code et les images Mille merciComment calculer la position d'un modèle attaché après rotation [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();
}
}
Figure A: Position: x: 0; y: 0; z: 0 Angle : 90 Figure B: Position: x: 2; y: 4; z: 0 angle : 90 Figure A: Position: x: 1; y: 0; z: 1 angle: 35 Figure B: Position: Comment cette position calcul? angle: 35
Avez-vous vu cela? http://stackoverflow.com/questions/13890820/rotating-objects-attached-to-other-objects/13893855#13893855 – neeKo
Merci! Pouvez-vous écrire ceci pour une réponse? –