diff -urN wf-/Makefile wf/Makefile --- wf-/Makefile 2015-12-20 00:00:00.000000000 +0900 +++ wf/Makefile 2016-01-03 00:00:00.000000000 +0900 @@ -4,15 +4,20 @@ CFLAGS += -Wall -I/usr/X11R6/include #CFLAGS += -DDBG -WF_OBJS = wf_ex.o data.o eye.o way.o d3.o x.o util.o key.o select.o +OBJS = data.o eye.o way.o d3.o x.o util.o key.o select.o +WF_OBJS = wf_ex.o $(OBJS) +NT_OBJS = nt.o $(OBJS) -all: wf_ex +all: wf_ex nt wf_ex: $(WF_OBJS) $(CC) -o $@ $(WF_OBJS) $(LIBS) +nt: $(NT_OBJS) + $(CC) -o $@ $(NT_OBJS) $(LIBS) + clean: - rm -f wf_ex + rm -f wf_ex nt rm -f *.o *~ # EOF diff -urN wf-/data.c wf/data.c --- wf-/data.c 2015-12-30 00:00:00.000000000 +0900 +++ wf/data.c 2016-01-03 00:00:00.000000000 +0900 @@ -9,6 +9,7 @@ switch(type){ CASE_RET(type_end); + CASE_RET(type_none); CASE_RET(type_wire_frame); CASE_RET(type_bar); CASE_RET(type_cross); @@ -16,6 +17,7 @@ CASE_RET(type_cube); CASE_RET(type_circle); CASE_RET(type_ball); + CASE_RET(type_arc); CASE_RET(type_arr); CASE_RET(type_op_data_set); CASE_RET(type_slide); @@ -27,12 +29,14 @@ CASE_RET(type_timeshift); CASE_RET(type_rdiv); CASE_RET(type_slide_way); + CASE_RET(type_slide_way_liss); CASE_RET(type_rot_way); CASE_RET(type_copy); CASE_RET(type_copy_rot); CASE_RET(type_copy_point_symmetry); CASE_RET(type_copy_mirror); CASE_RET(type_copy_timeshift); + CASE_RET(type_test_conv); default: break; } return "???"; @@ -248,8 +252,8 @@ odr[i] = i; } - odr[n] = 0; - odr[n+1] = odr[n+2] = -1; + odr[i++] = 0; + odr[i] = odr[i+1] = -1; data_draw(&data, prm); } @@ -269,6 +273,31 @@ } static void +arc_draw(struct arc *arc, prm_t *prm) +{ + int i, n = arc->n; + d3_t p[256*3]; + int odr[256+2]; + data_t data = { + type_wire_frame, + &(struct wire_frame){ n, p, odr, &p[n], &p[n*2] } + }; + + if(n > 256) ERR("n>256"); + + for(i=0; idec_s + (arc->dec_e - arc->dec_s) * i / (n-1); + pos_t *pp = &p[i]; + d3_set(pp, arc->r,0,0); + pos_rot(pp, &(line_t)LINE_Z, deg); + + odr[i] = i; + } + odr[i] = odr[i+1] = -1; + data_draw(&data, prm); +} + +static void arr_draw(data_t *data, prm_t *prm) { for(; data->type!=type_end; data++){ @@ -282,12 +311,20 @@ op_data_draw(set->op, set->data, prm); } +static void +test_conv_draw(pos_t *p, prm_t *prm) +{ + if(!prm->skip_af){ + affin_conv(&prm->af, p); + } +} + void data_draw(data_t *data, prm_t *prm) { #ifdef DBG - fprintf(stderr, "%s() type=%s\r\n", - __func__, type_str(data->type)); + fprintf(stderr, "%s() data=%p ", __func__, data); + fprintf(stderr, "type=%s\r\n", type_str(data->type)); #endif switch(data->type){ case type_wire_frame: @@ -311,14 +348,23 @@ case type_ball: ball_draw(data->p, prm); break; + case type_arc: + arc_draw(data->p, prm); + break; case type_arr: arr_draw(data->p, prm); break; case type_op_data_set: op_data_set_draw(data->p, prm); + break; + + case type_test_conv: + test_conv_draw(data->p, prm); + break; case type_end: + case type_none: default: break; } @@ -418,6 +464,18 @@ } static void +op_data_slide_way_liss(struct slide_way_liss *swl, data_t *data, prm_t *prm) +{ + struct way_liss wl; + pos_t p; + data_t op = { type_slide, &p }; + + way_liss_init(&wl, &swl->ps, &swl->pe, &swl->sec, &swl->init_sec); + way_liss_get(&wl, prm->sec, &p); + op_data_draw(&op, data, prm); +} + +static void op_data_rot_way(struct rot_way *rw, data_t *data, prm_t *prm) { struct way way = rw->deg_way; @@ -509,8 +567,9 @@ prm_t bak = *prm; #ifdef DBG - fprintf(stderr, "%s() op.type=%s data.type=%s\r\n", - __func__, type_str(op->type), type_str(data->type)); + fprintf(stderr, "%s() op=%p data=%p ", __func__, op, data); + fprintf(stderr, "op.type=%s data.type=%s\r\n", + type_str(op->type), type_str(data->type)); #endif switch(op->type){ case type_arr: @@ -545,6 +604,9 @@ case type_slide_way: op_data_slide_way(op->p, data, prm); break; + case type_slide_way_liss: + op_data_slide_way_liss(op->p, data, prm); + break; case type_rot_way: op_data_rot_way(op->p, data, prm); break; @@ -568,6 +630,10 @@ op_data_copy_timeshift(op->p, data, prm); break; + case type_none: + data_draw(data, prm); + break; + case type_end: default: break; diff -urN wf-/data.h wf/data.h --- wf-/data.h 2015-12-30 00:00:00.000000000 +0900 +++ wf/data.h 2016-01-03 00:00:00.000000000 +0900 @@ -10,6 +10,8 @@ } data_t; #define type_end (-1) +#define type_none 255 + #define type_wire_frame 0 #define type_bar 1 #define type_cross 2 @@ -17,6 +19,7 @@ #define type_cube 4 #define type_circle 5 #define type_ball 6 +#define type_arc 7 #define type_arr 10 #define type_op_data_set 11 @@ -31,6 +34,7 @@ #define type_rdiv 107 #define type_slide_way 120 +#define type_slide_way_liss 121 #define type_rot_way 130 #define type_rdiv_way 131 @@ -40,6 +44,8 @@ #define type_copy_mirror 203 #define type_copy_timeshift 204 +#define type_test_conv 254 + struct wire_frame{ int n; /* ex. n = 4 */ @@ -63,10 +69,21 @@ int n; }; +struct arc{ + double r; + double dec_s, dec_e; + int n; +}; + struct op_data_set{ data_t *op, *data; }; +struct slide_way_liss{ + pos_t ps, pe; + d3_t sec, init_sec; +}; + struct rot{ line_t l; double deg; diff -urN wf-/nt.c wf/nt.c --- wf-/nt.c 1970-01-01 09:00:00.000000000 +0900 +++ wf/nt.c 2016-01-03 00:00:00.000000000 +0900 @@ -0,0 +1,44 @@ +#include "data.h" + +static double +fz(double sec, int ac, char **av) +{ + double r = 30; + double sky_deg = 10; + pos_t p = {0,0,-r}; + data_t data = { type_op_data_set, &(struct op_data_set){ + .op = &(data_t){ type_rot_way, &(struct rot_way){ + .l=LINE_Y,.deg_way=WAY_V2(-90-sky_deg,90+sky_deg, 10,10, 3) }}, + .data = &(data_t){ type_test_conv, &p } + }}; + + eye_t eye; + prm_t prm; + + eye_init(&eye, 640, 480, ac, av); + d3_set(&eye.p, 0,0,0); + d3_set(&eye.t, 0,1,0); + + eye.sec = sec; + prm_set_eye_update(&prm, &eye); + data_draw(&data, &prm); +#ifdef DBG + printf("(%f %f %f)\n", p.x, p.y, p.z); +#endif + return p.z; +} + +int +main(int ac, char **av) +{ + double l_sec = 0, r_sec = 5, sec = 2.5; + + while(r_sec - l_sec > 5*0.0000001){ + sec = (l_sec + r_sec) * 0.5; + if(fz(sec, ac, av) < 0) r_sec = sec; + else l_sec = sec; + } + printf("sec=%f,5-sec=%f\n", sec, 5-sec); + printf("%f:%f=%f:5\n", sec, 5-sec, sec*5/(5-sec)); + return 0; +} diff -urN wf-/way.h wf/way.h --- wf-/way.h 2015-12-30 00:00:00.000000000 +0900 +++ wf/way.h 2016-01-03 00:00:00.000000000 +0900 @@ -1,6 +1,7 @@ #ifndef __INTERP_H__ #define __INTERP_H__ +#include #include "d3.h" /* diff -urN wf-/wf_ex.c wf/wf_ex.c --- wf-/wf_ex.c 2015-12-30 00:00:00.000000000 +0900 +++ wf/wf_ex.c 2016-01-03 00:00:00.000000000 +0900 @@ -196,7 +196,6 @@ data_t *rcube = &(data_t){ type_op_data_set, &(struct op_data_set){ .op = &(data_t){ type_rdiv_way, &(struct rdiv_way){ .n=4, - //.rate_way={ .n=2, .vs=(double[]){-0.5,1.0}, .ts=(double[]){3,3}, .ps=NULL, .dg=3 } } }, .rate_way=WAY_V2(-0.5,1.0, 3,3, 3) } }, .data = &(data_t){ type_cube } }}; @@ -301,15 +300,29 @@ .op = &(data_t){ type_arr, (data_t[]){ { type_copy_timeshift, &(struct copy_timeshift){ .n=10, .init_sec=0, .step_sec=-0.3, .init=D3_O, .step=D3_O } }, - { type_slide_way, &(struct way){ .n=2, .ps=(pos_t[]){{0,0,-20},{0,0,20}}, .ts=(double[]){5,5}, .vs=NULL, .dg=3} }, - { type_slide_way, &(struct way){ .n=2, .ps=(pos_t[]){{0,-20,0},{0,20,0}}, .ts=(double[]){4.5,4.5}, .vs=NULL, .dg=3} }, - { type_slide_way, &(struct way){ .n=2, .ps=(pos_t[]){{-20,0,0},{20,0,0}}, .ts=(double[]){3,3}, .vs=NULL, .dg=3} }, + { type_slide_way_liss, &(struct slide_way_liss){ + .ps={-20,-20,-20},.pe={20,20,20},.sec={5*2,4.5*2,3*2},.init_sec={0,0,0}} }, { type_rot_way, &(struct rot_way){ .l={D3_O,D3_I}, .deg_way=WAY_V2(0,360*2, 1,1, 3) } }, { type_end } }}, .data = &(data_t){ type_circle, &(struct circle){ .r=1,.n=10*4 } } }}; + double r = 30; + data_t *half_pipe = &(data_t){ type_op_data_set, &(struct op_data_set){ + .op = &(data_t){ type_zoom_and_slide, (d3_t[]){{0.1,0.1,0.1},{-30,-30,-10}} }, + .data = &(data_t){ type_arr, (data_t[]){ + { type_circle, &(struct circle){ .r=r*3, .n=360/10 } }, + { type_circle, &(struct circle){ .r=r*5, .n=360/10 } }, + { type_op_data_set, &(struct op_data_set){ + .op = &(data_t){ type_arr, (data_t[]){ + { type_copy_rot, &(struct copy_rot){ .n=360/10, .l=LINE_Z, .init_deg=0, .step_deg=10 } }, + { type_slide, &(d3_t){r*4,0,0} }, + { type_copy_rot, &(struct copy_rot){ .n=5, .l=LINE_Y, .init_deg=-90+30, .step_deg=30 } }, + { type_end } }}, + .data = &(data_t){ type_cross, (pos_t[]){{-1,0,-r},{1,0,-r}} } }}, + { type_end } }} }}; + data.type = type_arr; data.p = (data_t[]){ *axyz, @@ -317,6 +330,7 @@ *cube, *cube3, *cup, *ferris_wheel, *merry_go_round, *ship, *exile, *lissajours, + *half_pipe, { type_end } }; }