52 lines
975 B
C
52 lines
975 B
C
#include <math.h>
|
|
#include <stdio.h>
|
|
|
|
#define KLEIN_IMPLEMENT
|
|
#include <klein/klein.h>
|
|
#include <klein/norm.h>
|
|
#include <klein/parm.h>
|
|
|
|
void lightcone(float *d_surface, int *coord, unsigned char * grid)
|
|
{
|
|
|
|
const int n = 3;
|
|
float norm = 0;
|
|
float sphere[4];
|
|
|
|
for (int i = 0; i < n; i++)
|
|
sphere[i] = ((float)coord[i] / grid[i]) - 0.5;
|
|
|
|
for(int i = 0; i < n; i++)
|
|
norm += sphere[i] * sphere[i];
|
|
|
|
for (int i = 0; i < n; i++)
|
|
sphere[i] = sphere[i] / sqrt(norm);
|
|
|
|
float d = ((float)coord[3]/grid[3]) ;
|
|
d_surface[0] = d* sphere[0];
|
|
d_surface[1] = d* sphere[1];
|
|
d_surface[2] = d* sphere[2];
|
|
d_surface[3] = d;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char * file_name = "lightcone";
|
|
struct klein klein;
|
|
struct parm parametrization = {
|
|
.grid = (unsigned char[]){8, 8,8,8},
|
|
.m = 4,
|
|
.n = 4,
|
|
.f = lightcone,
|
|
};
|
|
|
|
|
|
klein_parametrize(&klein, parametrization);
|
|
klein_normalize(&klein);
|
|
klein_export_file(klein, file_name);
|
|
|
|
free(klein.vertex);
|
|
free(klein.normals);
|
|
return 0;
|
|
}
|