Esempio n. 1
0
Pte *
walkpgmap(Pml4e *pgmap, void *va, int alloc)
{
    Pdpe *pdirpt;
    Pde *pgdir;
    Pte *pgtab;

    pdirpt = pgmapget(pgmap, pmx(va), alloc);

    if (pdirpt == nil)
        return nil;

    pgdir = pgmapget(pdirpt, pdpx(va), alloc);

    if (pgdir == nil)
        return nil;

    pgtab = pgmapget(pgdir, pdx(va), alloc);

    if (pgtab == nil)
        return nil;

    return &pgtab[ptx(va)];
}
Esempio n. 2
0
void manifold(Mesh<Vertex3d> &mesh)
{
    const int N = 11;
    const int M = N - 1;
    const double L = ((double)N) / 2.0;

    Vertex3d vertices[N * N];
    int indices[M * M * 6];

    int index = 0;

    for (int ix = 0; ix < N; ++ix)
    {
        for (int iy = 0; iy < N; ++iy)
        {
            double x = (1.0 * ix - L + 0.5) / L;
            double y = (1.0 * iy - L + 0.5) / L;
            double z = manifoldFunction(x,y);


            double xdx = x + 0.01;
            double ydy = y + 0.01;
            double zdx = manifoldFunction(xdx, y);
            double zdy = manifoldFunction(x, ydy);

            GAL::P3d p0(x,y,z);
            GAL::P3d pdx(xdx, y, zdx);
            GAL::P3d pdy(x, ydy, zdy);

            GAL::P3d nor = GAL::Cross(pdx - p0, pdy - p0);

            vertices[index].position = p0;
            vertices[index].normal = nor / GAL::Len(nor);
            ++index;
        }
    }

    index = 0;

    for (int n = 0; n < M; ++n)
    {
        for (int m = 0; m < M; ++m)
        {
            int i0 = n * N + m;
            int i1 = i0 + 1;
            int i2 = i0 + N;
            int i3 = i0 + N + 1;

            indices[index++] = i0;
            indices[index++] = i2;
            indices[index++] = i1;

            indices[index++] = i1;
            indices[index++] = i2;
            indices[index++] = i3;
        }
    }

    mesh.addVertices(vertices, sizeof(vertices) / sizeof(GAL::P3d));
    mesh.addIndices(indices, sizeof(indices) / sizeof(int));
}