X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fscr_mod.c;h=680c754325552397e42d89b17501570f345c076f;hb=ada9427ce6be3fb43fd9c36e0ac02809e762a88e;hp=0a177451c8bfb37ca36017ea1045351ac57605ea;hpb=15a4548ff09afb37dd33786cafd50b060a64f840;p=retroray diff --git a/src/scr_mod.c b/src/scr_mod.c index 0a17745..680c754 100644 --- a/src/scr_mod.c +++ b/src/scr_mod.c @@ -83,6 +83,7 @@ static void tbn_callback(rtk_widget *w, void *cls); static void draw_rband(void); static void primray(cgm_ray *ray, int x, int y); +static void moveobj(struct object *obj, int px0, int py0, int px1, int py1); struct app_screen scr_model = { @@ -110,6 +111,7 @@ static int selobj = -1; static rtk_rect rband; static int rband_valid; + static int mdl_init(void) { int i, toolidx; @@ -233,7 +235,9 @@ static void draw_object(struct object *obj) { struct sphere *sph; - calc_object_matrix(obj); + if(!obj->xform_valid) { + calc_object_matrix(obj); + } gaw_push_matrix(); gaw_mult_matrix(obj->xform); @@ -362,10 +366,24 @@ static void mdl_motion(int x, int y) } } else { if(mouse_state[0]) { - if(rband.x != x || rband.y != y) { - rband.width = x - rband.x; - rband.height = y - rband.y; - rband_valid = 1; + switch(cur_tool) { + case TOOL_SEL: + if(rband.x != x || rband.y != y) { + rband.width = x - rband.x; + rband.height = y - rband.y; + rband_valid = 1; + } + break; + + case TOOL_MOVE: + if(selobj >= 0) { + struct object *obj = scn->objects[selobj]; + moveobj(obj, mouse_x, mouse_y, x, y); + } + break; + + default: + break; } } app_redisplay(); @@ -484,3 +502,22 @@ static void primray(cgm_ray *ray, int x, int y) ray->dir.y = farpt.y - ray->origin.y; ray->dir.z = farpt.z - ray->origin.z; } + +static void moveobj(struct object *obj, int px0, int py0, int px1, int py1) +{ + cgm_ray ray; + float dist; + cgm_vec3 p0, p1; + + primray(&ray, px0, py0); + cgm_vnormalize(&ray.dir); + dist = ray_object_dist(&ray, obj); + cgm_raypos(&p0, &ray, dist); + primray(&ray, px1, py1); + cgm_vnormalize(&ray.dir); + cgm_raypos(&p1, &ray, dist); + + cgm_vsub(&p1, &p0); + cgm_vadd(&obj->pos, &p1); + obj->xform_valid = 0; +}