Setup for test on R4

This commit is contained in:
PedroEdiaz
2024-10-18 20:26:53 -06:00
parent b164d15927
commit fe3b99d480
10 changed files with 227 additions and 58 deletions

View File

@@ -1,14 +1,16 @@
#include "main.h"
#include "data/cube.h"
#include "data/axis.h"
#include "data/shaders.h"
#include <GL/glew.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <cglm/vec3.h>
#include <cglm/vec4.h>
#define WIDTH 512
#define HEIGHT 512
unsigned char coordanate[4] = {0,1,2,3};
unsigned char palette[] =
{
16,
@@ -20,8 +22,9 @@ unsigned char palette[] =
void calc_normal(float* v1, float* v2, float* v3,float* normal, unsigned char n)
{
float alpha;
vec4 lado1, lado2;
vec4 u1, u2;
vec4 u1, u2, proy;
switch (n)
{
@@ -35,21 +38,20 @@ void calc_normal(float* v1, float* v2, float* v3,float* normal, unsigned char n)
return;
case 4:
#if 0
glm_vec4_sub(v2, v1, lado1);
glm_vec4_sub(v3, v1, lado2);
glm_vec4_copy(lado1, u1);
float alfa = glm_vec4_dot(lado2, u1) / glm_vec4_dot(u1, u1);
vec4 proy;
glm_vec4_scale(u1, alfa, proy);
alpha = glm_vec4_dot(lado2, u1) / glm_vec4_dot(u1, u1);
glm_vec4_scale(u1, alpha, proy);
glm_vec4_sub(lado2, proy, u2);
glm_vec4_normalize(u2);
glm_vec4_copy(u2, normal);
default:
break;
#endif
return;
}
}
@@ -58,24 +60,25 @@ float * fill_normal( float * d, unsigned char m )
float * n;
n = malloc( (*d+1)*sizeof(float));
*n = *d;
for (int i = 0; i < *d; i += 9)
for (int i = 0; i < *d; i += 3*m)
{
vec3 norm_vec;
calc_normal((d+1)+i, (d+1)+i+3, (d+1)+i+6, norm_vec, m);
vec4 norm_vec;
calc_normal((d+1)+i, (d+1)+i+m, (d+1)+i+2*m, norm_vec, m);
glm_vec3_copy( norm_vec, (n+1)+i );
glm_vec3_copy( norm_vec, (n+1)+i+3 );
glm_vec3_copy( norm_vec, (n+1)+i+6 );
glm_vec3_copy( norm_vec, (n+1)+i+m );
glm_vec3_copy( norm_vec, (n+1)+i+2*m );
}
return n;
}
const char * wname = "manigraph: manifold grapher";
float * generate_surface();
int main( void )
{
float * n_cube, *n_axis;
id_t shader, texture;
id_t shader, texture, shader_plain;
mesh_t m_cube, m_axis;
window_t window;
@@ -87,63 +90,83 @@ int main( void )
glewInit();
if( !( shader = create_shader() ) )
goto error_shader;
gload_program( shader, vs, VERTEX );
gload_program( shader, fs, FRAGMENT );
use_shader( shader );
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
n_cube = fill_normal( d_cube, 3 );
n_axis = fill_normal( d_axis, 3 );
if( !( m_cube = create_mesh( d_cube, n_cube ) ) )
goto error_mesh_cube;
if( !( m_axis = create_mesh( d_axis, n_axis ) ) )
goto error_mesh_axis;
free( n_cube );
free( n_axis );
texture=create_palette_texture( palette );
use_texture( texture );
if( !( shader = create_shader() ) )
goto error_shader;
gload_program( shader, vs, VERTEX );
gload_program( shader, fs, FRAGMENT );
if( !( shader_plain = create_shader() ) )
goto error_shader_plain;
gload_program( shader_plain, vs, VERTEX );
gload_program( shader_plain, fs_plain, FRAGMENT );
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
load_fix_matrix( shader_plain, (float)WIDTH/HEIGHT );
/* Fill m_cube */
{
float * n_cube, *d_cube;
d_cube = generate_surface(16);
n_cube = fill_normal( d_cube, 4 );
if( !( m_cube = create_mesh( d_cube, n_cube, coordanate, 4 ) ) )
goto error_mesh_cube;
free( n_cube );
free( d_cube);
}
/* Fill m_axis */
{
float * n_axis;
n_axis = fill_normal( d_axis, 3 );
if( !( m_axis = create_mesh( d_axis, n_axis, coordanate, 3 ) ) )
goto error_mesh_axis;
free( n_axis );
}
while( is_open_window( window ) )
{
quat_t q;
q=poll_input( window );
load_rot_matrix( shader, q );
load_rot_matrix( shader_plain, q );
clean_context();
#ifndef DEBUG
load_mdl_matrix( shader, 0, 0 );
load_mdl_matrix( shader_plain, 0, 0 );
draw_mesh( m_axis );
load_mdl_matrix( shader, 1, 1 );
load_mdl_matrix( shader_plain, 1, 1 );
draw_mesh( m_axis );
load_mdl_matrix( shader, 2, 2 );
load_mdl_matrix( shader_plain, 2, 2 );
draw_mesh( m_axis );
#endif
load_mdl_matrix( shader, 0, 3 );
draw_mesh( m_cube );
}
destroy_texture( texture );
destroy_mesh( m_axis );
destroy_mesh( m_cube );
destroy_shader( shader_plain );
destroy_shader( shader );
destroy_texture( texture );
close_window( window );
return 0;
error_mesh_axis:
destroy_mesh( m_cube );
error_mesh_cube:
destroy_shader( shader_plain );
error_shader_plain:
destroy_shader( shader );
error_shader:
close_window( window );
destroy_texture( texture );
error_window:
return 1;
}