XNA模型重复

发布于 2024-10-20 15:05:44 字数 186 浏览 1 评论 0原文

我想知道在 XNA 中是否可以无限次重复地面模型。例如,在此示例中 http://create.msdn.com/en-美国/教育/目录/样本/chasecamera

I'm wondering is there anyway of repeating the ground model infinite times in XNA. For example in this sample http://create.msdn.com/en-US/education/catalog/sample/chasecamera ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丿*梦醉红颜 2024-10-27 15:05:44

简单的答案是否定的。如果您尝试绘制无限数量的多边形,不仅会耗尽内存并导致程序崩溃,而且硬件将花费无限的时间来渲染场景。

为了解决这个问题,游戏开发者使用天空盒和无法到达的地形等技巧来让玩家认为世界是无限的。因此,如果您想要一个具有重复地面纹理的有限世界,只需在网格中多次绘制地面纹理,然后放置一个覆盖地面外边缘的天空盒即可。

如果你真的想要一个无限的世界,你可以做一个让天空盒和地面跟着你移动的技巧。因此,只需将地面和天空盒的速度设置为正在移动的精灵的速度即可。

The simple answer is no. If you try to draw an infinite number of polygons not only will your memory run out and your program crash, but the hardware would take an infinite amount of time to render the scene.

To get around this, game developers use tricks like skyboxes and unreachable terrain to make the player think the world is infinite. So if you want a finite world with a repeating ground texture, just draw the ground texture a bunch of times in a grid and put a skybox that covers the outer edges of the ground.

If you REALLY want an infinite looking world, you can do a trick where the skybox and ground move with you. So just set the velocities of the ground and the skybox to be the velocity of the sprite that is moving.

遗弃M 2024-10-27 15:05:44

就这样!这是我的定制样品。您可以从具有不同纹理的矩阵索引重复模型

//Draw a ground land
    private void draw_groundLand1(int[,,] MatriceWorldCube,Vector3 position_model_origin)
    {

        int hauteur = MatriceWorldCube.GetLength(0);
        int largeur = MatriceWorldCube.GetLength(1);
        int longueur = MatriceWorldCube.GetLength(2);

        Vector3 pos_reference = position_model_origin;

        for (int epaisseur = 0; epaisseur < hauteur; epaisseur++)
        {

            for (int collone = 0; collone < largeur; collone++)
            {

                for (int ligne = 0; ligne < longueur ; ligne++)
                {

                    //Vérifie si l'index de la matrice comporte bien un matériaux a placer
                    if (MatriceWorldCube[epaisseur, collone, ligne] != 0)
                    {
                        // 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(position_model_origin);
                                effect.View = View;
                                effect.Projection = Projection;

                                //Applique la texture en fonction du type de matière définit dans l'indice de la matrice
                                switch (MatriceWorldCube[epaisseur, collone, ligne])
                                {
                                    case 1:
                                        effect.Texture = text_ground_land1;
                                        break;

                                    case 2:
                                        effect.Texture = text_ground_land2;
                                        break;

                                    default:
                                        break;
                                }
                            }

                            // Draw the mesh, using the effects set above.
                            mesh.Draw();
                        }

                    }

                    position_model_origin.X = (float)(ligne+1);
                }
                position_model_origin.X = pos_reference.X;
                position_model_origin.Z = (float)(collone+1);

            }
            position_model_origin.Z = pos_reference.Z;
            position_model_origin.Y = (float)(epaisseur+1);

        }
        position_model_origin.Y = pos_reference.Y;
        position_model_origin = pos_reference;
    }

Like that ! It's my custom sample. You can repeat a model from a matrix index with different texture

//Draw a ground land
    private void draw_groundLand1(int[,,] MatriceWorldCube,Vector3 position_model_origin)
    {

        int hauteur = MatriceWorldCube.GetLength(0);
        int largeur = MatriceWorldCube.GetLength(1);
        int longueur = MatriceWorldCube.GetLength(2);

        Vector3 pos_reference = position_model_origin;

        for (int epaisseur = 0; epaisseur < hauteur; epaisseur++)
        {

            for (int collone = 0; collone < largeur; collone++)
            {

                for (int ligne = 0; ligne < longueur ; ligne++)
                {

                    //Vérifie si l'index de la matrice comporte bien un matériaux a placer
                    if (MatriceWorldCube[epaisseur, collone, ligne] != 0)
                    {
                        // 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(position_model_origin);
                                effect.View = View;
                                effect.Projection = Projection;

                                //Applique la texture en fonction du type de matière définit dans l'indice de la matrice
                                switch (MatriceWorldCube[epaisseur, collone, ligne])
                                {
                                    case 1:
                                        effect.Texture = text_ground_land1;
                                        break;

                                    case 2:
                                        effect.Texture = text_ground_land2;
                                        break;

                                    default:
                                        break;
                                }
                            }

                            // Draw the mesh, using the effects set above.
                            mesh.Draw();
                        }

                    }

                    position_model_origin.X = (float)(ligne+1);
                }
                position_model_origin.X = pos_reference.X;
                position_model_origin.Z = (float)(collone+1);

            }
            position_model_origin.Z = pos_reference.Z;
            position_model_origin.Y = (float)(epaisseur+1);

        }
        position_model_origin.Y = pos_reference.Y;
        position_model_origin = pos_reference;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文