寻找 SLAB6 实施

发布于 2024-11-19 12:51:44 字数 203 浏览 4 评论 0原文

我希望将 SLAB6 实现到我的光线投射器中,特别是对体素模型的 kv6 支持。然而 Ken Silverman 的 SLAB6 源代码完全不可读(主要是 ASM),所以我希望有人能给我指出一个合适的 C/Java 源代码来加载 kv6 模型,或者最好用一些伪代码向我解释工作原理(因为我想知道如何支持kv6,我知道它是如何工作的)。谢谢,Kaj

编辑:将用 Java 实现。

I'm looking to implement SLAB6 into my raycaster, especially the kv6 support for voxelmodels. However the SLAB6 source by Ken Silverman is totally unreadably (mostly ASM) so I was hoping someone could point me to a proper C / Java source to load kv6 models or maybe to explain me the workings in some pseudocode preferably (since I want to know how to support the kv6, I know how it works). Thanks, Kaj

EDIT: the implementation would be in Java.

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

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

发布评论

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

评论(1

陌路终见情 2024-11-26 12:51:44

我在一个名为 VoxelGL 的应用程序中找到了一些代码(源代码中未提及作者):

void CVoxelWorld::generateSlabFromData(unsigned char *data, VoxelData *vdata, Slab *slab)
{
    int currentpattern = 1;
    int i = 0;
    int n, totalcount, v, count;
    n = 0;
    v = 0;
    while (1)
    {
        while (data[i] == currentpattern)
        {
            if (currentpattern == 1)
                v++;
            i++;
            if (i == 256)
                break;
        }
        n++;
        if (i == 256)
        {
            if (currentpattern == 0)
                n--;
            break;
        }
        currentpattern ^= 1;
    }
    slab->nentries = n;
    if (slab->description != 0)delete [] slab->description;
    if (slab->data != 0)delete [] slab->data;
    slab->description = new int[n];
    slab->data = new VoxelData[v];

    totalcount = 0;
    v = 0;
    currentpattern = 1;

    for (i = 0; i < n; i++)
    {
        count = 0;
        while (data[totalcount] == currentpattern)
        {
            count++;
            totalcount++;
            if (totalcount == 256)
                break;
        }
        slab->description[i] = count-1;
        if (i % 2 == 0)
        {
            memcpy(slab->data + v, vdata + totalcount - count, 3 * count);
            v += count;
        }
        currentpattern ^= 1;
    }
}

和:

#define clustersize 8
Slab *CVoxelWorld::getSlab(int x, int z)
{
    int xgrid = x / clustersize;
    int ygrid = z / clustersize;
    int clusteroffset = xgrid * 1024 * clustersize + ygrid * clustersize * clustersize;

    return &m_data[clusteroffset + (x & (clustersize - 1)) + (z & (clustersize - 1)) * clustersize];
}

和:

int CVoxelWorld::isSolid(int x, int y, int z)
{
    Slab *slab;

    if (y < 0 || y > 256)
        return 0;

    slab = getSlab(x, z);
    int counter = 0;
    for (int i = 0; i < slab->nentries; i++)
    {
        int height = slab->description[i] + 1;
        if (i % 2 == 0)
        {
            if (y >= counter && y < counter + height)
                return 1;
        }
        counter += height;
    }
    return 0;
}

I found some code in an application called VoxelGL (author not mentioned in sourcecode):

void CVoxelWorld::generateSlabFromData(unsigned char *data, VoxelData *vdata, Slab *slab)
{
    int currentpattern = 1;
    int i = 0;
    int n, totalcount, v, count;
    n = 0;
    v = 0;
    while (1)
    {
        while (data[i] == currentpattern)
        {
            if (currentpattern == 1)
                v++;
            i++;
            if (i == 256)
                break;
        }
        n++;
        if (i == 256)
        {
            if (currentpattern == 0)
                n--;
            break;
        }
        currentpattern ^= 1;
    }
    slab->nentries = n;
    if (slab->description != 0)delete [] slab->description;
    if (slab->data != 0)delete [] slab->data;
    slab->description = new int[n];
    slab->data = new VoxelData[v];

    totalcount = 0;
    v = 0;
    currentpattern = 1;

    for (i = 0; i < n; i++)
    {
        count = 0;
        while (data[totalcount] == currentpattern)
        {
            count++;
            totalcount++;
            if (totalcount == 256)
                break;
        }
        slab->description[i] = count-1;
        if (i % 2 == 0)
        {
            memcpy(slab->data + v, vdata + totalcount - count, 3 * count);
            v += count;
        }
        currentpattern ^= 1;
    }
}

And:

#define clustersize 8
Slab *CVoxelWorld::getSlab(int x, int z)
{
    int xgrid = x / clustersize;
    int ygrid = z / clustersize;
    int clusteroffset = xgrid * 1024 * clustersize + ygrid * clustersize * clustersize;

    return &m_data[clusteroffset + (x & (clustersize - 1)) + (z & (clustersize - 1)) * clustersize];
}

And:

int CVoxelWorld::isSolid(int x, int y, int z)
{
    Slab *slab;

    if (y < 0 || y > 256)
        return 0;

    slab = getSlab(x, z);
    int counter = 0;
    for (int i = 0; i < slab->nentries; i++)
    {
        int height = slab->description[i] + 1;
        if (i % 2 == 0)
        {
            if (y >= counter && y < counter + height)
                return 1;
        }
        counter += height;
    }
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文