Compare commits
7 Commits
pedro-klei
...
alan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d3f8f71b2 | ||
|
|
5f392792c5 | ||
|
|
a131ff6da1 | ||
|
|
27d43e6bca | ||
|
|
994bd3987c | ||
|
|
af2c2afa1d | ||
|
|
7333f3933c |
8
Makefile
8
Makefile
@@ -1,6 +1,7 @@
|
|||||||
BIN = manigraph
|
BIN = manigraph
|
||||||
|
|
||||||
OBJ = \
|
OBJ = \
|
||||||
|
src/surface.o \
|
||||||
src/context.o \
|
src/context.o \
|
||||||
src/texture.o \
|
src/texture.o \
|
||||||
src/window.o \
|
src/window.o \
|
||||||
@@ -8,7 +9,6 @@ OBJ = \
|
|||||||
src/shader.o \
|
src/shader.o \
|
||||||
src/input.o \
|
src/input.o \
|
||||||
src/mesh.o \
|
src/mesh.o \
|
||||||
src/alan.o \
|
|
||||||
src/main.o
|
src/main.o
|
||||||
|
|
||||||
CFLAGS = \
|
CFLAGS = \
|
||||||
@@ -35,14 +35,16 @@ windows: $(OBJ) glfw.dll
|
|||||||
glfw.dll:
|
glfw.dll:
|
||||||
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32
|
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32
|
||||||
|
|
||||||
|
src/main.o: src/data/shaders.h src/data/cube.h src/data/axis.h
|
||||||
|
|
||||||
# LINUX
|
# LINUX
|
||||||
linux-x11: $(OBJ)
|
linux-x11: $(OBJ)
|
||||||
$(MAKE) BKN=_GLFW_X11 libglfw.so
|
$(MAKE) BKN=_GLFW_X11 libglfw.so
|
||||||
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw -lm
|
||||||
|
|
||||||
linux-wayland: $(OBJ)
|
linux-wayland: $(OBJ)
|
||||||
$(MAKE) BKN=_GLFW_WAYLAND libglfw.so
|
$(MAKE) BKN=_GLFW_WAYLAND libglfw.so
|
||||||
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
$(CC) -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw -lm
|
||||||
|
|
||||||
run-linux:
|
run-linux:
|
||||||
LD_LIBRARY_PATH=. ./$(BIN)
|
LD_LIBRARY_PATH=. ./$(BIN)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const float Z = 0.05;
|
|||||||
#define G X, Y,-Z,
|
#define G X, Y,-Z,
|
||||||
#define H X, Y, Z,
|
#define H X, Y, Z,
|
||||||
|
|
||||||
narray_float_t d_axis =
|
float d_axis[] =
|
||||||
{
|
{
|
||||||
3*3*2*6,
|
3*3*2*6,
|
||||||
|
|
||||||
|
|||||||
13
src/main.c
13
src/main.c
@@ -1,8 +1,9 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "data/cube.h"
|
|
||||||
#include "data/axis.h"
|
#include "data/axis.h"
|
||||||
#include "data/shaders.h"
|
#include "data/shaders.h"
|
||||||
|
#include <stdlib.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
@@ -17,9 +18,11 @@ unsigned char palette[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char * wname = "manigraph: manifold grapher";
|
const char * wname = "manigraph: manifold grapher";
|
||||||
|
float * generate_surface();
|
||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
@@ -32,6 +35,8 @@ int main( void )
|
|||||||
|
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
|
points = generate_surface(16);
|
||||||
|
|
||||||
if( !( shader = create_shader() ) )
|
if( !( shader = create_shader() ) )
|
||||||
goto error_shader;
|
goto error_shader;
|
||||||
|
|
||||||
@@ -41,9 +46,11 @@ 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(points);
|
||||||
|
|
||||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
if( !( m_axis = create_mesh( d_axis ) ) )
|
||||||
goto error_mesh_axis;
|
goto error_mesh_axis;
|
||||||
|
|
||||||
@@ -66,8 +73,10 @@ int main( void )
|
|||||||
load_mdl_matrix( shader, 2, 2 );
|
load_mdl_matrix( shader, 2, 2 );
|
||||||
draw_mesh( m_axis );
|
draw_mesh( m_axis );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
load_mdl_matrix( shader, 0, 3 );
|
load_mdl_matrix( shader, 0, 3 );
|
||||||
draw_mesh( m_cube );
|
draw_mesh( m_cube );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_texture( texture );
|
destroy_texture( texture );
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int is_open_window(window_t window);
|
|||||||
|
|
||||||
void close_window(window_t window);
|
void close_window(window_t window);
|
||||||
|
|
||||||
mesh_t create_mesh(narray_float_t mesh);
|
mesh_t create_mesh( float * mesh);
|
||||||
|
|
||||||
void destroy_mesh(mesh_t p);
|
void destroy_mesh(mesh_t p);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ struct obj
|
|||||||
unsigned int vertex, vao, vbo;
|
unsigned int vertex, vao, vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh_t create_mesh( narray_float_t mesh )
|
mesh_t create_mesh( float * mesh )
|
||||||
{
|
{
|
||||||
struct obj * p;
|
struct obj * p;
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ mesh_t create_mesh( narray_float_t mesh )
|
|||||||
|
|
||||||
glBindVertexArray( p->vao );
|
glBindVertexArray( p->vao );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, p->vbo );
|
glBindBuffer( GL_ARRAY_BUFFER, p->vbo );
|
||||||
glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(int), mesh+1,
|
glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(float), mesh+1,
|
||||||
GL_STATIC_DRAW );
|
GL_STATIC_DRAW );
|
||||||
|
|
||||||
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(int), NULL );
|
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL );
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
76
src/surface.c
Normal file
76
src/surface.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void(*function_t)(float*,int, int, int);
|
||||||
|
|
||||||
|
void mobius(float *d_surface, int i, int j, int grid_size)
|
||||||
|
{
|
||||||
|
const float width = 0.5;
|
||||||
|
float u = (2*M_PI) * ((float)i/grid_size );
|
||||||
|
float v = (2*width) * ((float)j/grid_size ) - width;
|
||||||
|
|
||||||
|
d_surface[0] = cos(u) + v * cos(u / 2) * cos(u);
|
||||||
|
d_surface[1] = sin(u) + v * cos(u / 2) * sin(u);
|
||||||
|
d_surface[2] = v * sin(u / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toro(float *d_surface, int i, int j, int grid_size)
|
||||||
|
{
|
||||||
|
float u = (2*M_PI) * ((float)i/grid_size );
|
||||||
|
float v = (2*M_PI) * ((float)j/grid_size );
|
||||||
|
|
||||||
|
d_surface[0] = (1 + 0.5*cos(v))*cos(u);
|
||||||
|
d_surface[1] = (1 + 0.5*cos(v))*sin(u);
|
||||||
|
d_surface[2] = 0.5*sin(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void klein(float *d_surface, int i, int j, int grid_size)
|
||||||
|
{
|
||||||
|
float u = (2*M_PI) * ((float)i/grid_size );
|
||||||
|
float v = (2*M_PI) * ((float)j/grid_size );
|
||||||
|
|
||||||
|
d_surface[0] = (0.5*cos(v) + 0.5) * cos(u);
|
||||||
|
d_surface[1] = (0.5*cos(v) + 0.5) * sin(u);
|
||||||
|
d_surface[2] = sin(v) * cos(u/2);
|
||||||
|
//d_surface[2] = sin(v)*sin(u/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
float * generate_surface(int grid_size)
|
||||||
|
{
|
||||||
|
long size = grid_size*grid_size*2*3*3;
|
||||||
|
function_t f = klein;
|
||||||
|
float * d_surface;
|
||||||
|
int k=0;
|
||||||
|
|
||||||
|
d_surface = malloc((size+1)*sizeof(float));
|
||||||
|
d_surface[0] = size;
|
||||||
|
|
||||||
|
for (int i = 0; i < grid_size; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < grid_size; j++)
|
||||||
|
{
|
||||||
|
// Triángulo 1
|
||||||
|
f(&d_surface[k + 1], i, j, grid_size);
|
||||||
|
k+=3;
|
||||||
|
f(&d_surface[k + 1], i + 1, j, grid_size);
|
||||||
|
k+=3;
|
||||||
|
f(&d_surface[k + 1], i + 1, j + 1, grid_size);
|
||||||
|
k+=3;
|
||||||
|
|
||||||
|
// Triángulo 2
|
||||||
|
f(&d_surface[k + 1], i, j, grid_size);
|
||||||
|
k+=3;
|
||||||
|
f(&d_surface[k + 1], i, j + 1, grid_size);
|
||||||
|
k+=3;
|
||||||
|
f(&d_surface[k + 1], i + 1, j + 1, grid_size);
|
||||||
|
k+=3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return d_surface;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user