Merge: alan -> main

This commit is contained in:
PedroEdiaz
2024-10-18 17:06:19 -06:00
parent 0552616bf9
commit 6e54aa9fea
4 changed files with 105 additions and 3 deletions

View File

@@ -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 \
@@ -47,10 +48,12 @@ 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 -lm $(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

View File

@@ -6,6 +6,7 @@
#undef F #undef F
#undef G #undef G
#undef H #undef H
#define A -2.0,-0.05,-0.05, #define A -2.0,-0.05,-0.05,
#define B -2.0,-0.05, 0.05, #define B -2.0,-0.05, 0.05,
#define C -2.0, 0.05,-0.05, #define C -2.0, 0.05,-0.05,

View File

@@ -1,9 +1,10 @@
#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> #include <stdlib.h>
#include <cglm/vec3.h> #include <cglm/vec3.h>
#define WIDTH 512 #define WIDTH 512
@@ -49,6 +50,7 @@ float * fill_normal( float * d )
} }
const char * wname = "manigraph: manifold grapher"; const char * wname = "manigraph: manifold grapher";
float * generate_surface();
int main( void ) int main( void )
{ {
@@ -82,11 +84,13 @@ int main( void )
/* Fill m_cube */ /* Fill m_cube */
{ {
float * n_cube; float * n_cube, *d_cube;
d_cube = generate_surface(16);
n_cube = fill_normal( d_cube ); n_cube = fill_normal( d_cube );
if( !( m_cube = create_mesh( d_cube, n_cube, coordanate ) ) ) if( !( m_cube = create_mesh( d_cube, n_cube, coordanate ) ) )
goto error_mesh_cube; goto error_mesh_cube;
free( n_cube ); free( n_cube );
free( d_cube);
} }
/* Fill m_axis */ /* Fill m_axis */
@@ -116,8 +120,10 @@ int main( void )
load_mdl_matrix( shader_plain, 2, 2 ); load_mdl_matrix( shader_plain, 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_mesh( m_axis ); destroy_mesh( m_axis );

92
src/surface.c Normal file
View File

@@ -0,0 +1,92 @@
#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*2;
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++)
{
// triangle 1, front
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;
// triangle 1, back
f(&d_surface[k + 1], i + 1, j + 1, grid_size);
k+=3;
f(&d_surface[k + 1], i + 1, j, grid_size);
k+=3;
f(&d_surface[k + 1], i, j, grid_size);
k+=3;
// triangle 2, font
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;
// triangle 2, back
f(&d_surface[k + 1], i + 1, j + 1, grid_size);
k+=3;
f(&d_surface[k + 1], i, j + 1, grid_size);
k+=3;
f(&d_surface[k + 1], i, j, grid_size);
k+=3;
}
}
return d_surface;
}