0.3 Rotate axis
This commit is contained in:
14
DESIGN.ms
14
DESIGN.ms
@@ -117,19 +117,19 @@ Prioridad alta
|
||||
.IP _
|
||||
El usuario quiere:
|
||||
.QS
|
||||
.IP _
|
||||
.IP X
|
||||
Ver 3 ejes en todo momento.
|
||||
.IP _
|
||||
Ver que ejes esta viendo.
|
||||
.IP _
|
||||
Ver cuantos ejes hay.
|
||||
.QE
|
||||
.IP _
|
||||
.IP X
|
||||
El usuario quiere:
|
||||
.QS
|
||||
.IP _
|
||||
.IP X
|
||||
Rotar estos ejes,
|
||||
.IP _
|
||||
.IP X
|
||||
Ver donde quedan los ejes despues de la rotados.
|
||||
.QE
|
||||
.IP _
|
||||
@@ -182,11 +182,11 @@ Camino
|
||||
Se hace un programa que muestre un cubo.
|
||||
.IP 2
|
||||
Se muestran los 3 ejes del cubo
|
||||
.IP 2
|
||||
Se rota el cubo en sus 3 ejes usando el teclado.
|
||||
.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
|
||||
Se rota el cubo en sus 3 ejes usando el mouse.
|
||||
.IP 5
|
||||
Se muestran la etiqueta de los ejes.
|
||||
.QE
|
||||
.IP 1
|
||||
|
||||
4
Makefile
4
Makefile
@@ -6,6 +6,7 @@ OBJ = \
|
||||
src/window.o \
|
||||
src/matrix.o \
|
||||
src/shader.o \
|
||||
src/input.o \
|
||||
src/color.o \
|
||||
src/mesh.o \
|
||||
src/main.o
|
||||
@@ -33,6 +34,9 @@ run:
|
||||
LD_LIBRARY_PATH=. $(BIN)
|
||||
|
||||
clean:
|
||||
rm $(OBJ) $(BIN)
|
||||
|
||||
clean-all:
|
||||
rm $(OBJ) $(DOC) $(LIB) $(BIN)
|
||||
|
||||
.SUFFIXES: .ms .pdf .c .o
|
||||
|
||||
@@ -20,7 +20,7 @@ const float Z = 0.1;
|
||||
#define G X, Y,-Z,
|
||||
#define H X, Y, Z,
|
||||
|
||||
float axis[] =
|
||||
float d_axis[] =
|
||||
{
|
||||
3*3*2*6,
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define G 1, 1,-1,
|
||||
#define H 1, 1, 1,
|
||||
|
||||
float cube[] =
|
||||
float d_cube[] =
|
||||
{
|
||||
3*3*2*6,
|
||||
|
||||
|
||||
21
src/main.c
21
src/main.c
@@ -11,17 +11,16 @@
|
||||
unsigned char palette[] =
|
||||
{
|
||||
16,
|
||||
0x90,0x90,0x90,0xff,
|
||||
0x91,0x91,0x91,0xff,
|
||||
0x92,0x92,0x92,0xff,
|
||||
0xff,0x88,0x33,0xff,
|
||||
0xEB,0xD3,0xF8,0xff,
|
||||
0xEB,0xD4,0xF8,0xff,
|
||||
0xEB,0xD5,0xF8,0xff,
|
||||
0x7A,0x1C,0xAC,0xff,
|
||||
};
|
||||
|
||||
const char * wname = "manigraph: manifold grapher";
|
||||
|
||||
int main( void )
|
||||
{
|
||||
unsigned char rot[3] = {0,0,0};
|
||||
unsigned int shader, texture;
|
||||
void * m_cube, *m_axis;
|
||||
|
||||
@@ -31,7 +30,7 @@ int main( void )
|
||||
goto error_window;
|
||||
|
||||
use_window( window );
|
||||
set_color( 0x33, 0x00, 0x00 );
|
||||
set_color( 0x2E, 0x07, 0x3F );
|
||||
|
||||
if( !( shader = create_shader() ) )
|
||||
goto error_shader;
|
||||
@@ -42,10 +41,10 @@ int main( void )
|
||||
|
||||
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
||||
|
||||
if( !( m_cube = create_mesh( cube ) ) )
|
||||
if( !( m_cube = create_mesh( d_cube ) ) )
|
||||
goto error_mesh_cube;
|
||||
|
||||
if( !( m_axis = create_mesh( axis ) ) )
|
||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
||||
goto error_mesh_axis;
|
||||
|
||||
texture=create_palette_texture( palette );
|
||||
@@ -53,9 +52,9 @@ int main( void )
|
||||
|
||||
while( is_open_window( window ) )
|
||||
{
|
||||
++rot[1];
|
||||
|
||||
load_rot_matrix( shader, rot );
|
||||
float * q;
|
||||
q=poll_input( window );
|
||||
load_rot_matrix( shader, q );
|
||||
|
||||
draw_color();
|
||||
|
||||
|
||||
@@ -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_rot_matrix( unsigned int shader, unsigned char * angle );
|
||||
void load_rot_matrix( unsigned int shader, float * q );
|
||||
|
||||
unsigned int config_texture( unsigned short type );
|
||||
|
||||
@@ -48,3 +48,5 @@ void use_texture( unsigned int texture );
|
||||
void destroy_texture( unsigned int texture );
|
||||
|
||||
unsigned int create_palette_texture( const unsigned char * colors );
|
||||
|
||||
float * poll_input( window_t window );
|
||||
|
||||
16
src/matrix.c
16
src/matrix.c
@@ -1,6 +1,8 @@
|
||||
#include "main.h"
|
||||
#define inline
|
||||
#include <cglm/cglm.h>
|
||||
#include <cglm/mat4.h>
|
||||
#include <cglm/cam.h>
|
||||
#include <cglm/quat.h>
|
||||
|
||||
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] );
|
||||
}
|
||||
|
||||
void load_rot_matrix( unsigned int shader, unsigned char * angle )
|
||||
void load_rot_matrix( unsigned int shader, float * q )
|
||||
{
|
||||
mat4 m, n;
|
||||
|
||||
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 );
|
||||
|
||||
mat4 m;
|
||||
glm_quat_mat4( q, m );
|
||||
gload_mat4( shader, "rot", (float*)m );
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include <GLFW/glfw3.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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
glfwSetWindowSizeCallback( window, window_callback );
|
||||
|
||||
glfwSetWindowSizeCallback( window, __window_callback );
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user