/// rotate selection void selection_rotate(const vec3f& ea) { if(selected_point) return; if(selected_frame) { auto m = translation_matrix(selected_frame->o) * rotation_matrix(ea.x, selected_frame->x) * rotation_matrix(ea.y, selected_frame->y) * rotation_matrix(ea.z, selected_frame->z) * translation_matrix(- selected_frame->o); *selected_frame = transform_frame(m, *selected_frame); } }
frame3f lineset_frame(LineSet* lines, int elementid, const vec2f& uv) { auto l = lines->line[elementid]; auto f = lineset_cylinder_frame(lines, elementid); auto r = (lines->radius[l.y]+lines->radius[l.x])/2; auto h = length(lines->pos[l.y]-lines->pos[l.x]); float phi = 2 * pif * uv.x; float hh = h*uv.y; float cp = cos(phi); float sp = sin(phi); frame3f frame; frame.o = vec3f(r*cp,r*sp,hh); frame.x = vec3f(sp,cp,0); frame.y = z3f; frame.z = vec3f(cp,sp,0); return transform_frame(f,frame); }
// compute the frame from an animation frame3f animate_compute_frame(FrameAnimation* animation, int time) { // find keyframe interval and t auto interval_t = get_keyframe_details(animation->keytimes, time); auto interval = interval_t.first; auto t = interval_t.second; // get translation and rotation matrices auto trans=translation_matrix(t*(animation->translation)[interval+1]+(1-t)*(animation->translation)[interval]); auto rot=t*((animation->rotation)[interval+1])+(1-t)*((animation->rotation)[interval]); // compute combined xform matrix auto rot_x=rotation_matrix(rot[0], x3f); auto rot_y=rotation_matrix(rot[1], y3f); auto rot_z=rotation_matrix(rot[2], z3f); // return the transformed rest frame return transform_frame(trans*rot_z*rot_y*rot_x, animation->rest_frame); }