Merge branch 'alan2' into experimental
This commit is contained in:
101
src/surface.c
101
src/surface.c
@@ -29,6 +29,14 @@ void riemman(float *d_surface, int * coords, int grid_size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cube( float *d_surface, int * coord, int grid_size )
|
||||||
|
{
|
||||||
|
unsigned char i;
|
||||||
|
|
||||||
|
for(int i=0; i<4; i++ )
|
||||||
|
d_surface[i]=(float)coord[i]/grid_size;
|
||||||
|
}
|
||||||
|
|
||||||
void mobius(float *d_surface, int * coord, int grid_size)
|
void mobius(float *d_surface, int * coord, int grid_size)
|
||||||
{
|
{
|
||||||
const float width = 0.5;
|
const float width = 0.5;
|
||||||
@@ -50,20 +58,6 @@ void torus(float *d_surface, int * coord, int grid_size)
|
|||||||
d_surface[2] = 0.5 * sin(v);
|
d_surface[2] = 0.5 * sin(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torus_5d(float *d_surface, int * coord, int grid_size)
|
|
||||||
{
|
|
||||||
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
|
||||||
float v = (2 * M_PI) * ((float)coord[1] / grid_size);
|
|
||||||
float r1 = (float)coord[2] / grid_size;
|
|
||||||
float r2 = (float)coord[3] / grid_size;
|
|
||||||
|
|
||||||
d_surface[0] = (r1 + r2 * cos(v)) * cos(u);
|
|
||||||
d_surface[1] = (r1 + r2 * cos(v)) * sin(u);
|
|
||||||
d_surface[2] = r2 * sin(v);
|
|
||||||
d_surface[3] = r1;
|
|
||||||
d_surface[4] = r2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void klein(float *d_surface, int * coord, int grid_size)
|
void klein(float *d_surface, int * coord, int grid_size)
|
||||||
{
|
{
|
||||||
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
|
||||||
@@ -77,45 +71,84 @@ void klein(float *d_surface, int * coord, int grid_size)
|
|||||||
|
|
||||||
typedef void (*function_t)(float *, int *, int);
|
typedef void (*function_t)(float *, int *, int);
|
||||||
|
|
||||||
float *generate_data_surface(int grid_size, unsigned char *m)
|
float *generate_data_surface(int grid_size, unsigned char *s)
|
||||||
{
|
{
|
||||||
unsigned int i, j, k = 0;
|
unsigned int i, j, k, o, p, l, n, m;
|
||||||
long size;
|
long size, q=0;
|
||||||
function_t f;
|
function_t f;
|
||||||
float *d_surface;
|
float *d_surface;
|
||||||
|
|
||||||
f = klein;
|
const int dim =2;
|
||||||
*m = 4;
|
int cara[dim];
|
||||||
|
char bits[dim+1];
|
||||||
|
bits[dim]=0;
|
||||||
|
|
||||||
size = grid_size * grid_size * 6 * (*m);
|
f =klein ;
|
||||||
|
*s = 4;
|
||||||
|
|
||||||
|
size = grid_size * grid_size * 6 * (*s) * 24;
|
||||||
d_surface = malloc((size + 1) * sizeof(float));
|
d_surface = malloc((size + 1) * sizeof(float));
|
||||||
d_surface[0] = size;
|
d_surface[0] = size;
|
||||||
|
|
||||||
|
for(o = 0; o < dim; o ++)
|
||||||
|
{
|
||||||
|
for (p = 0; p < o; p++)
|
||||||
|
{
|
||||||
|
for (k = 0; k < (1 << (dim-2)); k++)
|
||||||
|
{
|
||||||
|
unsigned char skip=0;
|
||||||
|
for(n = 0; n < dim-2; n++)
|
||||||
|
{
|
||||||
|
if( n==(o-1) || n==p )
|
||||||
|
skip++;
|
||||||
|
|
||||||
|
cara[n+skip] = (k & (1<<n))?grid_size:0;
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < grid_size; i++)
|
for(i = 0; i < grid_size; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < grid_size; j++)
|
for (j = 0; j < grid_size; j++)
|
||||||
{
|
{
|
||||||
// triangle 1, Front
|
cara[o] = i;
|
||||||
f(&d_surface[k + 1], (int[2]){i, j}, grid_size);
|
cara[p] = j;
|
||||||
k += *m;
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
f(&d_surface[k + 1], (int[2]){i + 1, j}, grid_size);
|
q += *s;
|
||||||
k += *m;
|
|
||||||
f(&d_surface[k + 1], (int[2]){i + 1, j + 1}, grid_size);
|
|
||||||
k += *m;
|
|
||||||
|
|
||||||
// triangle 2, Back
|
cara[o] = i + 1;
|
||||||
f(&d_surface[k + 1], (int[2]){i, j}, grid_size);
|
cara[p] = j;
|
||||||
k += *m;
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
f(&d_surface[k + 1], (int[2]){i, j + 1}, grid_size);
|
q += *s;
|
||||||
k += *m;
|
|
||||||
f(&d_surface[k + 1], (int[2]){i + 1, j + 1}, grid_size);
|
cara[o] = i + 1;
|
||||||
k += *m;
|
cara [p] = j + 1;
|
||||||
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
|
q += *s;
|
||||||
|
|
||||||
|
cara[o] = i;
|
||||||
|
cara [p] = j;
|
||||||
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
|
q += *s;
|
||||||
|
|
||||||
|
cara[o] = i;
|
||||||
|
cara [p] = j + 1;
|
||||||
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
|
q += *s;
|
||||||
|
|
||||||
|
cara[o] = i + 1;
|
||||||
|
cara [p] = j + 1;
|
||||||
|
f(&d_surface[q + 1], cara, grid_size);
|
||||||
|
q += *s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return d_surface;
|
return d_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void __calculate_normal(
|
static void __calculate_normal(
|
||||||
float *p1, float *p2, float *p3, float *normal, unsigned char n)
|
float *p1, float *p2, float *p3, float *normal, unsigned char n)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user