【问题标题】:Retrieving model position after applying modeltransforms in XNA在 XNA 中应用模型变换后检索模型位置
【发布时间】:2012-06-02 20:31:21
【问题描述】:

对于 goingBeyond XNA 教程提供的这种方法,位于 here,如果我可以在对网格应用所有变换后检索模型正在绘制的新位置,那将非常方便。我已经根据需要对方法进行了一些编辑。有谁知道我可以这样做吗?

    public void DrawModel( Camera camera )
    {
        Matrix scaleY = Matrix.CreateScale(new Vector3(1, 2, 1));
        Matrix temp = Matrix.CreateScale(100f) * scaleY * rotationMatrix * translationMatrix * Matrix.CreateRotationY(MathHelper.Pi / 6) * translationMatrix2;
        Matrix[] modelTransforms = new Matrix[model.Bones.Count];
        model.CopyAbsoluteBoneTransformsTo(modelTransforms);
        if (camera.getDistanceFromPlayer(position+position1) > 3000) return;
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.World = modelTransforms[mesh.ParentBone.Index] * temp *  worldMatrix;
                effect.View = camera.viewMatrix;
                effect.Projection = camera.projectionMatrix;
            }
            mesh.Draw();
        }
    }

【问题讨论】:

标签: c# model matrix xna position


【解决方案1】:

使用Vector3.Transform 方法将矩阵应用于您的位置向量。

【讨论】:

  • 你读过这个问题吗?这个答案完全没用,我证明了你在源代码中确切告诉我的内容。如果您阅读该问题,您会看到我需要在转换后检索新向量,而不是应用转换。
  • 不同之处在于接收更新的位置,而不是设置新的位置。设置位置需要简单的矩阵应用程序,但接收新位置有点困难
猜你喜欢
  • 2013-01-30
  • 1970-01-01
  • 1970-01-01
  • 2021-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-02
  • 1970-01-01
相关资源
最近更新 更多