如何在 XNA 中隐藏立方体模型的某些面以供体素引擎优化?

发布于 2024-12-29 13:42:27 字数 1181 浏览 0 评论 0原文

你好,我正在尝试制作一个类似于 Minecraft 的地形引擎。

我能够加载一个块。它非常滞后,当一次加载多个块时,它会变得无法播放。

这是我的渲染代码:

public static void renderNormalBlock(GraphicsDevice g, Chunk chunk,Texture2D texture, int x, int y, int z)
    {
        float tileSize = 0.5F;
        Vector3 blockPosition = new Vector3(x / tileSize, y / tileSize, z / tileSize);
        Model blockModel = Main.defaultBlockModel;
        ModelMesh mesh = blockModel.Meshes[0];
        g.SamplerStates[0] = SamplerState.PointWrap;
        BasicEffect effect = (BasicEffect)mesh.Effects[0];
        effect.TextureEnabled = true;
        effect.Texture = texture;
        effect.View = Main.camera;
        effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), g.DisplayMode.AspectRatio, 1, 128);
        effect.World = Matrix.CreateWorld(blockPosition, Vector3.Forward, Vector3.Up);
        mesh.Draw();
    }

如您所见,我没有使用 for-each 或 for 循环,因为它只是一个立方体;这不是必需的。

我做了一些研究,发现最好的答案是我需要隐藏立方体不可见的面。所以说,如果有 2 个立方体彼此相邻,我不想渲染面之间的内容。

这就是我陷入困境的地方,大多数人都使用在 XNA 中绘制的立方体,而我使用的是模型。

我是 XNA 的新手,由于我目前是 9 年级,所以我不太了解手动绘制立方体所涉及的数学知识,所以我使用了一个模型。

那么我该如何只渲染可见的面呢?

Hello I'm trying to make a terrain engine similar to that of Minecraft.

I was able to get a chunk loaded. It is very laggy and when there is more than one chunk loaded at once it becomes unplayable.

This is my render code:

public static void renderNormalBlock(GraphicsDevice g, Chunk chunk,Texture2D texture, int x, int y, int z)
    {
        float tileSize = 0.5F;
        Vector3 blockPosition = new Vector3(x / tileSize, y / tileSize, z / tileSize);
        Model blockModel = Main.defaultBlockModel;
        ModelMesh mesh = blockModel.Meshes[0];
        g.SamplerStates[0] = SamplerState.PointWrap;
        BasicEffect effect = (BasicEffect)mesh.Effects[0];
        effect.TextureEnabled = true;
        effect.Texture = texture;
        effect.View = Main.camera;
        effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), g.DisplayMode.AspectRatio, 1, 128);
        effect.World = Matrix.CreateWorld(blockPosition, Vector3.Forward, Vector3.Up);
        mesh.Draw();
    }

As You can see I am not using for-each or for loops because as it's only a cube; It is not required.

I did some research and the best answer I found was that I need to hide the cube's faces that are not visible. So say if there's 2 cubes next to each other, I don't want to render the in between faces.

This is where I get stuck, Most people are using cubes that were drawn in XNA, and I'm using a model.

I'm new to XNA and I don't understand too much of the Math involved in manually drawing a cube since I'm currently in grade 9, so I used a model.

So how would I go about rendering only the faces that are visible?

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

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

发布评论

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

评论(1

夏了南城 2025-01-05 13:42:27

在学习基础知识之前就开始开发游戏。这样你不会走得太远。首先找一本关于 XNA 开发的书并仔细阅读。这是一个基本主题,将在那里讨论。另外,访问 techCraft http://techcraft.codeplex.com/ 并下载他们的实现,其中包含所有内容代码。仅此一点你就会学到很多东西。

your starting to develop a game before learning the basics. you wont get too far this way. First grab a book about XNA development and go through it. This is a basic subject that will be covered there. In addition, go visit techCraft http://techcraft.codeplex.com/ and download their implementation which comes with all the code. you will learn alot from that alone.

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