Assert Style

This commit is contained in:
PedroEdiaz
2024-11-30 22:33:28 -06:00
parent df5ae70aa2
commit ee144f2286
5 changed files with 140 additions and 139 deletions

View File

@@ -9,7 +9,7 @@ unsigned char selected_axis = 0;
int window_width;
int window_height;
unsigned char animate_index=0;
unsigned char animate_index = 0;
versor q = GLM_QUAT_IDENTITY_INIT;
@@ -56,23 +56,22 @@ void __key_callback_input(
projection.w = projection.x;
projection.x = tmp;
animate_index=1;
animate_index = 1;
break;
case GLFW_KEY_O:
tmp = projection.w;
projection.w = projection.y;
projection.y = tmp;
animate_index=2;
animate_index = 2;
break;
case GLFW_KEY_P:
tmp = projection.w;
projection.w = projection.z;
projection.z = tmp;
animate_index=3;
animate_index = 3;
break;
}
return;
}
@@ -114,9 +113,9 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
versor p = GLM_QUAT_IDENTITY_INIT;
versor r = GLM_QUAT_IDENTITY_INIT;
//glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1,0,0});
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0,1,0});
// glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1, 0, 0});
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0, 1, 0});
glm_quat_mul(p, q, q);
glm_quat_mul(r, q, q);
@@ -172,10 +171,11 @@ end:
glm_quat_normalize(q);
// LOG INFO
if(0)
if (0)
{
printf("QUAT: %2.5f %2.5f %2.5f %2.5f\n", q[0], q[1], q[2], q[3]);
printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y, projection.z, projection.w );
printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y,
projection.z, projection.w);
printf("\n");
}
return q;

View File

@@ -19,7 +19,7 @@
float *generate_data_surface(unsigned int, unsigned char *);
float *generate_normals_surface(float *, unsigned char);
struct projection projection = {.x = 0, .y=1, .z=2, .w=3 };
struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3};
const char *wname = "manigraph: manifold grapher";
@@ -59,29 +59,27 @@ static inline
{
static float angle = 0;
if( angle > M_PI/2 )
if (angle > M_PI / 2)
{
animate_index=0;
animate_index = 0;
angle = 0;
load_float_to_shader( shader, "angle", angle);
load_float_to_shader( shader_plain, "angle", angle);
set_projection_mesh( projection );
load_float_to_shader(shader, "angle", angle);
load_float_to_shader(shader_plain, "angle", angle);
set_projection_mesh(projection);
}
if( animate_index )
if (animate_index)
{
load_uint_to_shader( shader, "i", animate_index-1 );
load_uint_to_shader( shader_plain, "i", animate_index-1 );
load_uint_to_shader(shader, "i", animate_index - 1);
load_uint_to_shader(shader_plain, "i", animate_index - 1);
angle+=0.01;
load_float_to_shader( shader, "angle", angle);
load_float_to_shader( shader_plain, "angle", angle);
angle += 0.01;
load_float_to_shader(shader, "angle", angle);
load_float_to_shader(shader_plain, "angle", angle);
}
}
clean_context();
#ifndef DEBUG
@@ -93,11 +91,10 @@ static inline
draw_mesh(m_axis, 1);
#endif
load_mdl_matrix(shader, 0, 3);
draw_mesh(m_surface,0);
draw_mesh(m_surface, 0);
load_mdl_matrix(shader_plain, 0, 3);
draw_mesh(m_surface,1);
draw_mesh(m_surface, 1);
}
int main(void)
@@ -170,8 +167,7 @@ int main(void)
projection.m = m;
projection.mesh = m_surface;
set_projection_mesh( projection );
set_projection_mesh(projection);
free(n_surface);
free(d_surface);

Binary file not shown.

View File

@@ -91,12 +91,12 @@ void destroy_mesh(mesh_t p)
free(p);
}
void draw_mesh(mesh_t p, char lines )
void draw_mesh(mesh_t p, char lines)
{
struct obj *obj = p;
glBindVertexArray(obj->vao);
if( lines )
if (lines)
{
int i;
for (i = 0; i < obj->vertex; i += 3)

View File

@@ -12,16 +12,16 @@
#endif
#ifndef CMPLX
#define CMPLX(a,b) (a+I*b)
#define CMPLX(a, b) (a + I * b)
#endif
void riemman(float *d_surface, int * coords, int grid_size)
void riemman(float *d_surface, int *coords, int grid_size)
{
complex double eq;
float u = 2 * ((float)coords[0] / grid_size) - 1;
float v = 2 * ((float)coords[1] / grid_size) - 1;
eq = csqrt(CMPLX(u,v));
eq = csqrt(CMPLX(u, v));
d_surface[0] = u;
d_surface[1] = v;
@@ -29,16 +29,15 @@ void riemman(float *d_surface, int * coords, int grid_size)
d_surface[3] = cimag(eq);
}
void cube( float *d_surface, int * coord, int grid_size )
void cube(float *d_surface, int *coord, int grid_size)
{
unsigned char i;
for(int i=0; i<4; i++ )
d_surface[i]=(float)coord[i]/grid_size;
for (int i = 0; i < 4; i++)
d_surface[i] = (float)coord[i] / grid_size;
}
void mobius(float *d_surface, int * coord, int grid_size)
void mobius(float *d_surface, int *coord, int grid_size)
{
const float width = 0.5;
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
@@ -49,7 +48,7 @@ void mobius(float *d_surface, int * coord, int grid_size)
d_surface[2] = v * sin(u / 2);
}
void torus(float *d_surface, int * coord, int grid_size)
void torus(float *d_surface, int *coord, int grid_size)
{
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
float v = (2 * M_PI) * ((float)coord[1] / grid_size);
@@ -59,10 +58,10 @@ void torus(float *d_surface, int * coord, int grid_size)
d_surface[2] = 0.5 * sin(v);
}
void klein(float *d_surface, int * coord, int grid_size)
void klein(float *d_surface, int *coord, int grid_size)
{
float u = (2 * M_PI) * ((float)coord[0] / grid_size);
float v = (2 * M_PI) * ((float)coord[1]/ grid_size);
float v = (2 * M_PI) * ((float)coord[1] / grid_size);
d_surface[0] = (0.5 * cos(v) + 0.5) * cos(u);
d_surface[1] = (0.5 * cos(v) + 0.5) * sin(u);
@@ -75,38 +74,38 @@ typedef void (*function_t)(float *, int *, int);
float *generate_data_surface(int grid_size, unsigned char *s)
{
unsigned int i, j, k, o, p, l, n, m;
long size, q=0;
long size, q = 0;
function_t f;
float *d_surface;
const int dim =2;
const int dim = 2;
int cara[dim];
char bits[dim+1];
bits[dim]=0;
char bits[dim + 1];
bits[dim] = 0;
f =klein ;
f = klein;
*s = 4;
size = grid_size * grid_size * 6 * (*s) * 24;
d_surface = malloc((size + 1) * sizeof(float));
d_surface[0] = size;
for(o = 0; o < dim; o ++)
for (o = 0; o < dim; o++)
{
for (p = 0; p < o; p++)
{
for (k = 0; k < (1 << (dim-2)); k++)
for (k = 0; k < (1 << (dim - 2)); k++)
{
unsigned char skip=0;
for(n = 0; n < dim-2; n++)
unsigned char skip = 0;
for (n = 0; n < dim - 2; n++)
{
if( n==(o-1) || n==p )
if (n == (o - 1) || n == p)
skip++;
cara[n+skip] = (k & (1<<n))?grid_size:0;
cara[n + skip] = (k & (1 << n)) ? grid_size : 0;
}
for(i = 0; i < grid_size; i++)
for (i = 0; i < grid_size; i++)
{
for (j = 0; j < grid_size; j++)
{
@@ -121,22 +120,22 @@ float *generate_data_surface(int grid_size, unsigned char *s)
q += *s;
cara[o] = i + 1;
cara [p] = j + 1;
cara[p] = j + 1;
f(&d_surface[q + 1], cara, grid_size);
q += *s;
cara[o] = i;
cara [p] = j;
cara[p] = j;
f(&d_surface[q + 1], cara, grid_size);
q += *s;
cara[o] = i;
cara [p] = j + 1;
cara[p] = j + 1;
f(&d_surface[q + 1], cara, grid_size);
q += *s;
cara[o] = i + 1;
cara [p] = j + 1;
cara[p] = j + 1;
f(&d_surface[q + 1], cara, grid_size);
q += *s;
}
@@ -148,8 +147,6 @@ float *generate_data_surface(int grid_size, unsigned char *s)
return d_surface;
}
static void __calculate_normal(
float *p1, float *p2, float *p3, float *normal, unsigned char n)
{
@@ -169,26 +166,30 @@ static void __calculate_normal(
Calculate a normal vector of a plain using Gram-Schmidt process
*/
{
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
v1[i] = p2[i] - p1[i];
v2[i] = p3[i] - p1[i];
v3[i] = p1[i];
}
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
u1[i] = v1[i];
}
{
float proj[n];
float dot_v2_u1 = 0.0f, dot_u1_u1 = 0.0f;
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
dot_v2_u1 += v2[i] * u1[i];
dot_u1_u1 += u1[i] * u1[i];
}
alpha = dot_v2_u1 / dot_u1_u1;
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
proj[i] = u1[i] * alpha;
u2[i] = v2[i] - proj[i];
}
@@ -199,31 +200,37 @@ static void __calculate_normal(
float dot_v3_u1 = 0.0f, dot_u1_u1 = 0.0f;
float dot_v3_u2 = 0.0f, dot_u2_u2 = 0.0f;
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
dot_v3_u1 += v3[i] * u1[i];
dot_u1_u1 += u1[i] * u1[i];
}
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
proj1[i] = u1[i] * (dot_v3_u1 / dot_u1_u1);
}
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
dot_v3_u2 += v3[i] * u2[i];
dot_u2_u2 += u2[i] * u2[i];
}
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
proj2[i] = u2[i] * (dot_v3_u2 / dot_u2_u2);
u3[i] = v3[i] - proj1[i] - proj2[i];
}
}
float magnitude = 0.0f;
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
magnitude += u3[i] * u3[i];
}
magnitude = sqrtf(magnitude);
for (i = 0; i < n; ++i) {
for (i = 0; i < n; ++i)
{
normal[i] = u3[i] / magnitude;
}
@@ -237,20 +244,18 @@ static void __calculate_normal(
}
}
float *generate_normals_surface(float *d, unsigned char m)
{
float *n;
n = malloc((*d + 1) * sizeof(float));
*n = *d;
float * norm_vec;
norm_vec=malloc(m*sizeof(float));
float *norm_vec;
norm_vec = malloc(m * sizeof(float));
for (int i = 0; i < *d; i += 3 * m)
{
__calculate_normal(
(d + 1) + i, (d + 1) + i + m, (d + 1) + i + 2 * m, norm_vec, m);
glm_vec3_copy(norm_vec, (n + 1) + i);