WIP: Rotations in R4, and change colors
This commit is contained in:
20
src/input.c
20
src/input.c
@@ -9,6 +9,8 @@ unsigned char selected_axis = 0;
|
|||||||
int window_width;
|
int window_width;
|
||||||
int window_height;
|
int window_height;
|
||||||
|
|
||||||
|
unsigned char animate_index=0;
|
||||||
|
|
||||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
vec3 axis[3] = {
|
vec3 axis[3] = {
|
||||||
@@ -49,24 +51,28 @@ void __key_callback_input(
|
|||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
unsigned char tmp;
|
unsigned char tmp;
|
||||||
|
case GLFW_KEY_I:
|
||||||
case GLFW_KEY_P:
|
|
||||||
tmp = projection.w;
|
tmp = projection.w;
|
||||||
projection.w = projection.x;
|
projection.w = projection.x;
|
||||||
projection.x = tmp;
|
projection.x = tmp;
|
||||||
|
|
||||||
|
animate_index=1;
|
||||||
break;
|
break;
|
||||||
case GLFW_KEY_O:
|
case GLFW_KEY_O:
|
||||||
tmp = projection.w;
|
tmp = projection.w;
|
||||||
projection.w = projection.y;
|
projection.w = projection.y;
|
||||||
projection.y = tmp;
|
projection.y = tmp;
|
||||||
|
animate_index=2;
|
||||||
break;
|
break;
|
||||||
case GLFW_KEY_I:
|
case GLFW_KEY_P:
|
||||||
tmp = projection.w;
|
tmp = projection.w;
|
||||||
projection.w = projection.z;
|
projection.w = projection.z;
|
||||||
projection.z = tmp;
|
projection.z = tmp;
|
||||||
|
animate_index=3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set_projection_mesh(projection);
|
set_projection_mesh(projection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -157,5 +163,13 @@ end:
|
|||||||
glm_quat_rotatev(p, axis[1], axis[1]);
|
glm_quat_rotatev(p, axis[1], axis[1]);
|
||||||
glm_quat_rotatev(p, axis[2], axis[2]);
|
glm_quat_rotatev(p, axis[2], axis[2]);
|
||||||
glm_quat_normalize(q);
|
glm_quat_normalize(q);
|
||||||
|
|
||||||
|
// LOG INFO
|
||||||
|
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("\n");
|
||||||
|
}
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/main.c
59
src/main.c
@@ -12,18 +12,22 @@
|
|||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159
|
||||||
|
#endif
|
||||||
|
|
||||||
float *generate_data_surface(unsigned int, unsigned char *);
|
float *generate_data_surface(unsigned int, unsigned char *);
|
||||||
float *generate_normals_surface(float *, unsigned char);
|
float *generate_normals_surface(float *, unsigned char);
|
||||||
|
|
||||||
const char *wname = "manigraph: manifold grapher";
|
struct projection projection = {.x = 3, .y=1, .z=2, .w=0 };
|
||||||
|
|
||||||
struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3};
|
const char *wname = "manigraph: manifold grapher";
|
||||||
|
|
||||||
unsigned char palette[][4] = {
|
unsigned char palette[][4] = {
|
||||||
{0xEB, 0xD3, 0xF8, 0xff},
|
{0xEB, 0xD3, 0xF8, 0xff},
|
||||||
{0xEB, 0xD4, 0xF8, 0xff},
|
{0xEB, 0xD4, 0xF8, 0xff},
|
||||||
{0xEB, 0xD5, 0xF8, 0xff},
|
{0xEB, 0xD5, 0xF8, 0xff},
|
||||||
{0x7A, 0x1C, 0xAC, 0xff},
|
{0x2F, 0x3C, 0x7E, 0xff},
|
||||||
};
|
};
|
||||||
|
|
||||||
void mlog(char *msg)
|
void mlog(char *msg)
|
||||||
@@ -37,6 +41,8 @@ window_t window;
|
|||||||
mesh_t m_surface, m_axis;
|
mesh_t m_surface, m_axis;
|
||||||
id_t shader, shader_plain;
|
id_t shader, shader_plain;
|
||||||
|
|
||||||
|
extern volatile unsigned char animate_index;
|
||||||
|
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
static inline
|
static inline
|
||||||
#endif
|
#endif
|
||||||
@@ -45,23 +51,48 @@ void main_loop(void)
|
|||||||
quat_t q;
|
quat_t q;
|
||||||
|
|
||||||
q = poll_input(window);
|
q = poll_input(window);
|
||||||
|
|
||||||
load_rot_matrix(shader, q);
|
load_rot_matrix(shader, q);
|
||||||
load_rot_matrix(shader_plain, q);
|
load_rot_matrix(shader_plain, q);
|
||||||
|
|
||||||
|
{
|
||||||
|
static float angle = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if( animate_index )
|
||||||
|
{
|
||||||
|
angle+=0.01;
|
||||||
|
|
||||||
|
load_uint_to_shader( shader, "i", animate_index-1 );
|
||||||
|
load_uint_to_shader( shader_plain, "i", animate_index-1 );
|
||||||
|
load_float_to_shader( shader, "angle", angle);
|
||||||
|
load_float_to_shader( shader_plain, "angle", angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( angle > M_PI/2 && angle )
|
||||||
|
{
|
||||||
|
animate_index=0;
|
||||||
|
angle = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
clean_context();
|
clean_context();
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
load_mdl_matrix(shader_plain, 0, 0);
|
load_mdl_matrix(shader_plain, 0, 0);
|
||||||
draw_mesh(m_axis);
|
draw_mesh(m_axis, 1);
|
||||||
load_mdl_matrix(shader_plain, 1, 1);
|
load_mdl_matrix(shader_plain, 1, 1);
|
||||||
draw_mesh(m_axis);
|
draw_mesh(m_axis, 1);
|
||||||
load_mdl_matrix(shader_plain, 2, 2);
|
load_mdl_matrix(shader_plain, 2, 2);
|
||||||
draw_mesh(m_axis);
|
draw_mesh(m_axis, 1);
|
||||||
load_mdl_matrix(shader, 0, 3);
|
|
||||||
#else
|
|
||||||
load_mdl_matrix(shader_plain, 0, 3);
|
|
||||||
#endif
|
#endif
|
||||||
draw_mesh(m_surface);
|
load_mdl_matrix(shader, 0, 3);
|
||||||
|
draw_mesh(m_surface,0);
|
||||||
|
|
||||||
|
load_mdl_matrix(shader_plain, 0, 3);
|
||||||
|
draw_mesh(m_surface,1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -86,7 +117,7 @@ int main(void)
|
|||||||
mlog("[CONTEXT] Error al inicializar...\n");
|
mlog("[CONTEXT] Error al inicializar...\n");
|
||||||
goto error_context;
|
goto error_context;
|
||||||
}
|
}
|
||||||
set_clean_color_context(0x2E, 0x07, 0x3F);
|
set_clean_color_context(0xFB, 0xEA, 0xEB);
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog("[TEXTURE] Inicializando...\n");
|
mlog("[TEXTURE] Inicializando...\n");
|
||||||
@@ -126,16 +157,18 @@ int main(void)
|
|||||||
d_surface = generate_data_surface(16, &m);
|
d_surface = generate_data_surface(16, &m);
|
||||||
n_surface = generate_normals_surface(d_surface, m);
|
n_surface = generate_normals_surface(d_surface, m);
|
||||||
|
|
||||||
projection.m = m;
|
|
||||||
|
|
||||||
if (!(m_surface = create_mesh(d_surface, n_surface, m)))
|
if (!(m_surface = create_mesh(d_surface, n_surface, m)))
|
||||||
{
|
{
|
||||||
mlog("[MESH] Error al inicializar...\n");
|
mlog("[MESH] Error al inicializar...\n");
|
||||||
goto error_mesh_surface;
|
goto error_mesh_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
projection.m = m;
|
||||||
projection.mesh = m_surface;
|
projection.mesh = m_surface;
|
||||||
|
|
||||||
|
set_projection_mesh( projection );
|
||||||
|
|
||||||
|
|
||||||
free(n_surface);
|
free(n_surface);
|
||||||
free(d_surface);
|
free(d_surface);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main.h
10
src/main.h
@@ -57,7 +57,7 @@ void set_projection_mesh( struct projection );
|
|||||||
|
|
||||||
void destroy_mesh(mesh_t p);
|
void destroy_mesh(mesh_t p);
|
||||||
|
|
||||||
void draw_mesh(mesh_t p);
|
void draw_mesh(mesh_t p, char lines);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set background color:
|
Set background color:
|
||||||
@@ -99,6 +99,14 @@ unsigned char load_program_to_shader(id_t shader, const char * src, unsigned int
|
|||||||
|
|
||||||
void load_float_to_shader(id_t shader, char * var, float f);
|
void load_float_to_shader(id_t shader, char * var, float f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
load unsigned int to shader:
|
||||||
|
var: name of glsl variable.
|
||||||
|
u: unsigned int to load
|
||||||
|
*/
|
||||||
|
|
||||||
|
void load_uint_to_shader(id_t shader, char * var, unsigned int u);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
load matrix 4 to shader:
|
load matrix 4 to shader:
|
||||||
var: name of glsl variable.
|
var: name of glsl variable.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void load_fix_matrix(id_t shader, float ratio)
|
|||||||
|
|
||||||
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c)
|
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c)
|
||||||
{
|
{
|
||||||
load_float_to_shader(shader, "idx", c);
|
load_uint_to_shader(shader, "idx", c);
|
||||||
load_mat4_to_shader(shader, "mdl", (mat4_t)ortho[i]);
|
load_mat4_to_shader(shader, "mdl", (mat4_t)ortho[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
src/mesh.c
22
src/mesh.c
@@ -78,19 +78,6 @@ mesh_t create_mesh(float *d, float *n, unsigned char m)
|
|||||||
glEnableVertexAttribArray(i + 4);
|
glEnableVertexAttribArray(i + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
struct projection projection = {
|
|
||||||
.x = 0,
|
|
||||||
.y = 1,
|
|
||||||
.z = 2,
|
|
||||||
.w = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
projection.m = m;
|
|
||||||
projection.mesh = p;
|
|
||||||
set_projection_mesh(projection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,18 +91,19 @@ void destroy_mesh(mesh_t p)
|
|||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_mesh(mesh_t p)
|
void draw_mesh(mesh_t p, char lines )
|
||||||
{
|
{
|
||||||
struct obj *obj = p;
|
struct obj *obj = p;
|
||||||
|
|
||||||
glBindVertexArray(obj->vao);
|
glBindVertexArray(obj->vao);
|
||||||
#ifdef DEBUG
|
if( lines )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < obj->vertex; i += 3)
|
for (i = 0; i < obj->vertex; i += 3)
|
||||||
glDrawArrays(GL_LINE_LOOP, i, 3);
|
glDrawArrays(GL_LINE_LOOP, i, 3);
|
||||||
}
|
}
|
||||||
#else
|
else
|
||||||
|
{
|
||||||
glDrawArrays(GL_TRIANGLES, 0, obj->vertex);
|
glDrawArrays(GL_TRIANGLES, 0, obj->vertex);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ void load_float_to_shader(unsigned int program, char *var, float f)
|
|||||||
glUniform1f(glGetUniformLocation(program, var), f);
|
glUniform1f(glGetUniformLocation(program, var), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_uint_to_shader(unsigned int program, char *var, unsigned int u)
|
||||||
|
{
|
||||||
|
glUseProgram(program);
|
||||||
|
glUniform1ui(glGetUniformLocation(program, var), u);
|
||||||
|
}
|
||||||
|
|
||||||
void load_mat4_to_shader(unsigned int program, char *var, float *mat)
|
void load_mat4_to_shader(unsigned int program, char *var, float *mat)
|
||||||
{
|
{
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|||||||
Reference in New Issue
Block a user