Toro agregado
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
|||||||
BIN = manigraph
|
BIN = manigraph
|
||||||
|
|
||||||
OBJ = \
|
OBJ = \
|
||||||
src/banda_mob.o \
|
src/surface.o \
|
||||||
src/context.o \
|
src/context.o \
|
||||||
src/texture.o \
|
src/texture.o \
|
||||||
src/window.o \
|
src/window.o \
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "main.h"
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GRID_SIZE 16
|
|
||||||
#define WIDTH 0.5
|
|
||||||
|
|
||||||
typedef void(*function_t)(float*,int,int);
|
|
||||||
|
|
||||||
void mobius(float *p, int i, int j)
|
|
||||||
{
|
|
||||||
float u = (2*M_PI) * ((float)i/(GRID_SIZE) );
|
|
||||||
float v = (2*WIDTH) * ((float)j/(GRID_SIZE) ) - WIDTH;
|
|
||||||
|
|
||||||
p[0] = cos(u) + v * cos(u / 2) * cos(u);
|
|
||||||
p[1] = sin(u) + v * cos(u / 2) * sin(u);
|
|
||||||
p[2] = v * sin(u / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
float * acabron(){
|
|
||||||
long size = GRID_SIZE*GRID_SIZE*2*3*3;
|
|
||||||
function_t f = mobius;
|
|
||||||
float * d_cube;
|
|
||||||
int k=0;
|
|
||||||
|
|
||||||
d_cube = malloc((size+1)*sizeof(float));
|
|
||||||
d_cube[0] = size;
|
|
||||||
|
|
||||||
for (int i = 0; i < GRID_SIZE; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < GRID_SIZE; j++)
|
|
||||||
{
|
|
||||||
// Triángulo 1
|
|
||||||
f(&d_cube[k + 1], i, j);
|
|
||||||
k+=3;
|
|
||||||
f(&d_cube[k + 1], i + 1, j);
|
|
||||||
k+=3;
|
|
||||||
f(&d_cube[k + 1], i + 1, j + 1);
|
|
||||||
k+=3;
|
|
||||||
|
|
||||||
// Triángulo 2
|
|
||||||
f(&d_cube[k + 1], i, j);
|
|
||||||
k+=3;
|
|
||||||
f(&d_cube[k + 1], i, j + 1);
|
|
||||||
k+=3;
|
|
||||||
f(&d_cube[k + 1], i + 1, j + 1);
|
|
||||||
k+=3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return d_cube;
|
|
||||||
}
|
|
||||||
10
src/main.c
10
src/main.c
@@ -18,11 +18,11 @@ unsigned char palette[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char * wname = "manigraph: manifold grapher";
|
const char * wname = "manigraph: manifold grapher";
|
||||||
float * acabron(void);
|
float * gen_surface();
|
||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
float * d_cube;
|
float * points;
|
||||||
id_t shader, texture;
|
id_t shader, texture;
|
||||||
mesh_t m_cube, m_axis;
|
mesh_t m_cube, m_axis;
|
||||||
window_t window;
|
window_t window;
|
||||||
@@ -35,7 +35,7 @@ int main( void )
|
|||||||
|
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
d_cube = acabron();
|
points = gen_surface(256);
|
||||||
|
|
||||||
if( !( shader = create_shader() ) )
|
if( !( shader = create_shader() ) )
|
||||||
goto error_shader;
|
goto error_shader;
|
||||||
@@ -46,10 +46,10 @@ int main( void )
|
|||||||
|
|
||||||
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
||||||
|
|
||||||
if( !( m_cube = create_mesh( d_cube ) ) )
|
if( !( m_cube = create_mesh( points ) ) )
|
||||||
goto error_mesh_cube;
|
goto error_mesh_cube;
|
||||||
|
|
||||||
free(d_cube);
|
free(points);
|
||||||
|
|
||||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
if( !( m_axis = create_mesh( d_axis ) ) )
|
||||||
goto error_mesh_axis;
|
goto error_mesh_axis;
|
||||||
|
|||||||
66
src/surface.c
Normal file
66
src/surface.c
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WIDTH 0.5
|
||||||
|
|
||||||
|
typedef void(*function_t)(float*,int, int, int);
|
||||||
|
|
||||||
|
void mobius(float *p, int i, int j, int GRID_SIZE)
|
||||||
|
{
|
||||||
|
float u = (2*M_PI) * ((float)i/(GRID_SIZE) );
|
||||||
|
float v = (2*WIDTH) * ((float)j/(GRID_SIZE) ) - WIDTH;
|
||||||
|
|
||||||
|
p[0] = cos(u) + v * cos(u / 2) * cos(u);
|
||||||
|
p[1] = sin(u) + v * cos(u / 2) * sin(u);
|
||||||
|
p[2] = v * sin(u / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toro(float *p, int i, int j, int GRID_SIZE)
|
||||||
|
{
|
||||||
|
float u = (2*M_PI) * ((float)i/(GRID_SIZE) );
|
||||||
|
float v = (2*WIDTH) * ((float)j );
|
||||||
|
|
||||||
|
p[0] = (1 + 0.5*cos(v))*cos(u);
|
||||||
|
p[1] = (1 + 0.5*cos(v)) * sin(u);
|
||||||
|
p[2] = 0.5*sin(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
float * gen_surface(int GRID_SIZE)
|
||||||
|
{
|
||||||
|
long size = GRID_SIZE*GRID_SIZE*2*3*3;
|
||||||
|
function_t f = mobius;
|
||||||
|
float * points;
|
||||||
|
int k=0;
|
||||||
|
|
||||||
|
points = malloc((size+1)*sizeof(float));
|
||||||
|
points[0] = size;
|
||||||
|
|
||||||
|
for (int i = 0; i < GRID_SIZE; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < GRID_SIZE; j++)
|
||||||
|
{
|
||||||
|
// Triángulo 1
|
||||||
|
f(&points[k + 1], i, j, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
f(&points[k + 1], i + 1, j, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
f(&points[k + 1], i + 1, j + 1, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
|
||||||
|
// Triángulo 2
|
||||||
|
f(&points[k + 1], i, j, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
f(&points[k + 1], i, j + 1, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
f(&points[k + 1], i + 1, j + 1, GRID_SIZE);
|
||||||
|
k+=3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user