Showing posts with label maze. Show all posts
Showing posts with label maze. Show all posts

Monday, September 14, 2009

Spatial Labyrinths

English    Spanish

Today I'm going to show a set of renders that I did some time ago. The general idea is to make a spatial maze.

That is, one that allows movements upwards and downwards as well as forward, backward, right and left. The movements that a player can do are in any spatial axis. In this case, Theseus has to know how to climb well.

One simple is this one:



In this one we see a tridimensional labyrinth bounded by the surface of a cube.

The procedure to accomplish this renders is not complex.
  • We start from a tridimensional shape. Then it's discretized in voxels marking as active the ones that are partially or totally included in the volume defined by the surface of the figure.
  • Now we are going to discard the non active voxels and we work with the ones that intersect or are included inside the volume.
  • We start from a random voxel and we move in a random direction, marking as visited the currant voxel.
  • As we move through the voxels we can find a visited voxel in the chosen direction. In this case we chose another direction.
  • In the case that there are not any available directions we move backwards and we chose another direction.
  • The algorithm ends when all the nodes (voxels) have been visited.
This algorithm allows a unique path from one point of the labyrinth to another. Obviously if we set two poins, one as starting and another one as ending, there will be a unique path between both, and then any other bifurcation that moves away from the path will bring us to a dead end.

Other views of the cube:











It's possible to use other figures as a "mould" of the labyrinth.

Here we can see a sphere:





And with a spherical camera:





The Utah teapot:



and a some renderings of a lying woman:




















Sunday, August 2, 2009

Spherical Renders of Labyrinths

English    Spanish

Recently I was thinking about how one of the mazes that I programmed would it seen using a spherical lens. Spherical lens deform parts of the images that are away from center, so the things that are far away looks like further away indeed. So more things "fits" inside the image.
When the deformation is low the result is similar to a wide angle lens. When the deformation is high we get images more dificult to achieve in reality. When the deformation is very high the images are imposible to obtain in reality.
The code that generates a particular ray for a pixel can be coded like this:


Ray RayGenerator::GenerateRay(int pixel_x, int pixel_y)
{
Ray ray;
double u,v;

ConvertPixel_to_Unit(pixel_x,pixel_y,u,v);

ray.orig=From;
ray.dir=-Normalize3d(-i + u*tanFov*aspect*j + v*tanFov*k);

return ray;
}

This code generates rays that advance in the negative direction of the X axis

Slightly modifying the code we can obtain our new spherical camera:

Ray SphericalRayGenerator::GenerateRay(int pixel_x, int pixel_y)
{
Ray ray;
double u,v;

ConvertPixel_to_Unit(pixel_x,pixel_y,u,v);

u*=fishEyeFactor*aspect;
v*=fishEyeFactor;

Vector V;
double r=sqrt(u*u+v*v);

double a=atan2(v,u);
V.y=sin(a)*(1-cos(r));
V.z=-cos(a)*(1-cos(r));
V.x=sin(r);
V=Normalize3d(V);

Matrix matrix=Construct4d(i,j,k,VECTOR3D(0,0,0));
V=TransformVector3d(V,matrix);

ray.orig=From;
ray.dir=Normalize3d(V);

return ray;
}

This type of projection generates a pole (or singularity) in the positive direction of the X axis. This generates images wery similar to the ones that Escher made in Circle Limit. As we aproach to the horizon we go to infinity.
With the value 'fishEyeFactor' we replicate the plane several times over the sphere reaching infinity as concentrical circular shapes.

This image is a normal render of an infinite labyrinth:


As we increase the spherical factor we slightly deform the image:


If we increase too much the factor we reach infinity several times:


We can make a render looking "down" obtaining an image that remainds quite well to the ones of M.C.Escher:


Likewise it's possible to increase the spherical factor: