【问题标题】:How to adjust the position of a mesh model before drawing如何在绘制前调整网格模型的位置
【发布时间】:2012-11-13 03:03:44
【问题描述】:

我开始在 XNA 中编程。我开发了一个简单的项目,将加载从搅拌机导出的“fbx”网格模型。一切都很完美。 但现在我想多次复制/复制我的模型来创建地板! 10 X 10 模型的矩阵。 我试了几个代码都不行。这是我的示例代码。

我不明白为什么我不能复制我的模型。

非常感谢。

//Function draw models mesh
    private void draw_groundLand1()
    {
        //Draw 10 times model texture to make small ground
        for (int a = 0; a < 10; a++)
        {     
            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[model_ground_land1.Bones.Count];
            model_ground_land1.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in model_ground_land1.Meshes)
            {
                // This is where the mesh orientation is set, as well 
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] *
                Matrix.CreateRotationY(cubeGroundLand1_modelRotation) * Matrix.CreateTranslation(cubeGroundLand1_position);
                    effect.View = View;
                    //effect.Texture = text_ground_lan1;
                    effect.Projection = Projection;
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

            //Move position for the next mesh modal to draw
            cubeGroundLand1_position.X += (float)1.0;
        }
    }

【问题讨论】:

    标签: c# windows model xna fbx


    【解决方案1】:

    我找到了我的解决方案 -> 只需移动此代码 ligne "cubeGroundLand1_position.X += (float)1.0;"

    喜欢:

    private void draw_groundLand1()
        {
    
            for (int a = 0; a < 10; a++)
            {
                // Copy any parent transforms.
                Matrix[] transforms = new Matrix[model_ground_land1.Bones.Count];
                model_ground_land1.CopyAbsoluteBoneTransformsTo(transforms);
    
                // Draw the model. A model can have multiple meshes, so loop.
                foreach (ModelMesh mesh in model_ground_land1.Meshes)
                {
    
                    // This is where the mesh orientation is set, as well 
                    // as our camera and projection.
                    foreach (BasicEffect effect in mesh.Effects)
                    {
    
                        effect.EnableDefaultLighting();
                        effect.World = transforms[mesh.ParentBone.Index] *
                    Matrix.CreateRotationY(cubeGroundLand1_modelRotation) * Matrix.CreateTranslation(cubeGroundLand1_position);
                        effect.View = View;
                        //effect.Texture = text_ground_lan1;
                        effect.Projection = Projection;
    
                        cubeGroundLand1_position.X = (float)a+1;
                    }
                    // Draw the mesh, using the effects set above.
                    mesh.Draw();
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 2019-03-25
      • 2013-08-28
      • 1970-01-01
      • 2017-11-09
      • 2020-02-10
      • 1970-01-01
      相关资源
      最近更新 更多