0.3 Rotate axis

This commit is contained in:
PedroEdiaz
2024-09-06 05:08:07 +06:00
parent 0f387f8a71
commit 6161d310bc
8 changed files with 35 additions and 36 deletions

View File

@@ -117,19 +117,19 @@ Prioridad alta
.IP _ .IP _
El usuario quiere: El usuario quiere:
.QS .QS
.IP _ .IP X
Ver 3 ejes en todo momento. Ver 3 ejes en todo momento.
.IP _ .IP _
Ver que ejes esta viendo. Ver que ejes esta viendo.
.IP _ .IP _
Ver cuantos ejes hay. Ver cuantos ejes hay.
.QE .QE
.IP _ .IP X
El usuario quiere: El usuario quiere:
.QS .QS
.IP _ .IP X
Rotar estos ejes, Rotar estos ejes,
.IP _ .IP X
Ver donde quedan los ejes despues de la rotados. Ver donde quedan los ejes despues de la rotados.
.QE .QE
.IP _ .IP _
@@ -182,11 +182,11 @@ Camino
Se hace un programa que muestre un cubo. Se hace un programa que muestre un cubo.
.IP 2 .IP 2
Se muestran los 3 ejes del cubo Se muestran los 3 ejes del cubo
.IP 2
Se rota el cubo en sus 3 ejes usando el teclado.
.IP 3 .IP 3
Se rota el cubo en sus 3 ejes usando el mouse. Se rota el cubo en sus 3 ejes usando el teclado.
.IP 4 .IP 4
Se rota el cubo en sus 3 ejes usando el mouse.
.IP 5
Se muestran la etiqueta de los ejes. Se muestran la etiqueta de los ejes.
.QE .QE
.IP 1 .IP 1

View File

@@ -6,6 +6,7 @@ OBJ = \
src/window.o \ src/window.o \
src/matrix.o \ src/matrix.o \
src/shader.o \ src/shader.o \
src/input.o \
src/color.o \ src/color.o \
src/mesh.o \ src/mesh.o \
src/main.o src/main.o
@@ -33,6 +34,9 @@ run:
LD_LIBRARY_PATH=. $(BIN) LD_LIBRARY_PATH=. $(BIN)
clean: clean:
rm $(OBJ) $(BIN)
clean-all:
rm $(OBJ) $(DOC) $(LIB) $(BIN) rm $(OBJ) $(DOC) $(LIB) $(BIN)
.SUFFIXES: .ms .pdf .c .o .SUFFIXES: .ms .pdf .c .o

View File

@@ -20,7 +20,7 @@ const float Z = 0.1;
#define G X, Y,-Z, #define G X, Y,-Z,
#define H X, Y, Z, #define H X, Y, Z,
float axis[] = float d_axis[] =
{ {
3*3*2*6, 3*3*2*6,

View File

@@ -7,7 +7,7 @@
#define G 1, 1,-1, #define G 1, 1,-1,
#define H 1, 1, 1, #define H 1, 1, 1,
float cube[] = float d_cube[] =
{ {
3*3*2*6, 3*3*2*6,

View File

@@ -11,17 +11,16 @@
unsigned char palette[] = unsigned char palette[] =
{ {
16, 16,
0x90,0x90,0x90,0xff, 0xEB,0xD3,0xF8,0xff,
0x91,0x91,0x91,0xff, 0xEB,0xD4,0xF8,0xff,
0x92,0x92,0x92,0xff, 0xEB,0xD5,0xF8,0xff,
0xff,0x88,0x33,0xff, 0x7A,0x1C,0xAC,0xff,
}; };
const char * wname = "manigraph: manifold grapher"; const char * wname = "manigraph: manifold grapher";
int main( void ) int main( void )
{ {
unsigned char rot[3] = {0,0,0};
unsigned int shader, texture; unsigned int shader, texture;
void * m_cube, *m_axis; void * m_cube, *m_axis;
@@ -31,7 +30,7 @@ int main( void )
goto error_window; goto error_window;
use_window( window ); use_window( window );
set_color( 0x33, 0x00, 0x00 ); set_color( 0x2E, 0x07, 0x3F );
if( !( shader = create_shader() ) ) if( !( shader = create_shader() ) )
goto error_shader; goto error_shader;
@@ -42,10 +41,10 @@ int main( void )
load_fix_matrix( shader, (float)WIDTH/HEIGHT ); load_fix_matrix( shader, (float)WIDTH/HEIGHT );
if( !( m_cube = create_mesh( cube ) ) ) if( !( m_cube = create_mesh( d_cube ) ) )
goto error_mesh_cube; goto error_mesh_cube;
if( !( m_axis = create_mesh( axis ) ) ) if( !( m_axis = create_mesh( d_axis ) ) )
goto error_mesh_axis; goto error_mesh_axis;
texture=create_palette_texture( palette ); texture=create_palette_texture( palette );
@@ -53,9 +52,9 @@ int main( void )
while( is_open_window( window ) ) while( is_open_window( window ) )
{ {
++rot[1]; float * q;
q=poll_input( window );
load_rot_matrix( shader, rot ); load_rot_matrix( shader, q );
draw_color(); draw_color();

View File

@@ -39,7 +39,7 @@ void load_fix_matrix( unsigned int shader, float ratio );
void load_mdl_matrix( unsigned int shader, unsigned char i, unsigned char c ); void load_mdl_matrix( unsigned int shader, unsigned char i, unsigned char c );
void load_rot_matrix( unsigned int shader, unsigned char * angle ); void load_rot_matrix( unsigned int shader, float * q );
unsigned int config_texture( unsigned short type ); unsigned int config_texture( unsigned short type );
@@ -48,3 +48,5 @@ void use_texture( unsigned int texture );
void destroy_texture( unsigned int texture ); void destroy_texture( unsigned int texture );
unsigned int create_palette_texture( const unsigned char * colors ); unsigned int create_palette_texture( const unsigned char * colors );
float * poll_input( window_t window );

View File

@@ -1,6 +1,8 @@
#include "main.h" #include "main.h"
#define inline #define inline
#include <cglm/cglm.h> #include <cglm/mat4.h>
#include <cglm/cam.h>
#include <cglm/quat.h>
mat4 ortho[] = mat4 ortho[] =
{ {
@@ -42,15 +44,9 @@ void load_mdl_matrix( unsigned int shader, unsigned char i, unsigned char c )
gload_mat4( shader, "mdl", (float*)ortho[i] ); gload_mat4( shader, "mdl", (float*)ortho[i] );
} }
void load_rot_matrix( unsigned int shader, unsigned char * angle ) void load_rot_matrix( unsigned int shader, float * q )
{ {
mat4 m, n; mat4 m;
glm_quat_mat4( q, m );
glm_rotate_make( m, (float)angle[0]/0xff*2*GLM_PI, (vec3){1,0,0} );
glm_rotate_make( n, (float)angle[1]/0xff*2*GLM_PI, (vec3){0,1,0} );
glm_mat4_mul( n, m, m );
glm_rotate_make( n, (float)angle[2]/0xff*2*GLM_PI, (vec3){0,0,1} );
glm_mat4_mul( n, m, m );
gload_mat4( shader, "rot", (float*)m ); gload_mat4( shader, "rot", (float*)m );
} }

View File

@@ -1,10 +1,9 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "main.h" #include "main.h"
void window_callback( GLFWwindow * window, int w, int h ) void __window_callback( GLFWwindow * window, int w, int h )
{ {
int m = ( w<h )? w: h; int m = ( w<h )? w: h;
glViewport( (w-m)/2, (h-m)/2, m, m ); glViewport( (w-m)/2, (h-m)/2, m, m );
} }
@@ -27,8 +26,7 @@ window_t init_window( unsigned int w, unsigned int h, const char * name )
return NULL; return NULL;
} }
glfwSetWindowSizeCallback( window, window_callback ); glfwSetWindowSizeCallback( window, __window_callback );
return window; return window;
} }