📄 transition.cpp
字号:
lib::dpoint ambulant::smil2::transition_engine_roundrectwipe::m_template[] = { lib::dpoint(-1, -1), lib::dpoint(1, -1), lib::dpoint(1, 1), lib::dpoint(1, 1)};lib::dpoint *transition_engine_roundrectwipe::get_template(int *size){ *size = sizeof(m_template) / sizeof(m_template[0]); return m_template;}lib::dpoint ambulant::smil2::transition_engine_ellipsewipe::m_template[] = { lib::dpoint(-1, -1), lib::dpoint(1, -1), lib::dpoint(1, 1), lib::dpoint(1, 1)};lib::dpoint *transition_engine_ellipsewipe::get_template(int *size){ *size = sizeof(m_template) / sizeof(m_template[0]); return m_template;}lib::dpoint ambulant::smil2::transition_engine_starwipe::m_template[] = { lib::dpoint(-1, -1), lib::dpoint(1, -1), lib::dpoint(1, 1), lib::dpoint(1, 1)};lib::dpoint *transition_engine_starwipe::get_template(int *size){ *size = sizeof(m_template) / sizeof(m_template[0]); return m_template;}lib::dpoint ambulant::smil2::transition_engine_miscshapewipe::m_template[] = { lib::dpoint(-1, -1), lib::dpoint(1, -1), lib::dpoint(1, 1), lib::dpoint(1, 1)};lib::dpoint *transition_engine_miscshapewipe::get_template(int *size){ *size = sizeof(m_template) / sizeof(m_template[0]); return m_template;}// series 3: clock-type wipesdetail::angle_computer::angle_computer(lib::rect rect): m_initialized(true), m_rect(rect){ recompute_angles();}booldetail::angle_computer::matches(lib::rect rect){ if (!m_initialized) return false; return rect == m_rect;}voiddetail::angle_computer::recompute_angles(){ AM_DBG lib::logger::get_logger()->debug("angle_computer::recompute_angles()"); int l = m_rect.left(), r = m_rect.right(), t = m_rect.top(), b = m_rect.bottom(); m_xmid = (l+r)/2; m_ymid = (t+b)/2; m_xdist = (r-l)/2; m_ydist = (b-t)/2; m_angle_topleft = atan2(m_ydist, -m_xdist); m_angle_topright = atan2(m_ydist, m_xdist); m_angle_botleft = atan2(-m_ydist, -m_xdist); m_angle_botright = atan2(-m_ydist, m_xdist); AM_DBG lib::logger::get_logger()->debug("angle_computer::recompute_angles: tl=%d, tr=%d, bl=%d, br=%d", (int)(m_angle_topleft * 180 / M_PI), (int)(m_angle_topright * 180 / M_PI), (int)(m_angle_botleft * 180 / M_PI), (int)(m_angle_botright * 180 / M_PI));}voiddetail::angle_computer::angle2poly(std::vector<lib::point> &outpolygon, double angle, bool clockwise){ AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2poly()"); assert(clockwise); // Compute where a line with this angle intersects our rectangle int l = m_rect.left(), r = m_rect.right(), t = m_rect.top(), b = m_rect.bottom(); lib::point edgepoint; detail::edgetype edge = angle2edge(angle, edgepoint); // We always have the hitpoint, the center and the top edge. // Then we progress over all cornerpoints that are part of the figure. outpolygon.push_back(edgepoint); outpolygon.push_back(lib::point(m_xmid, m_ymid)); outpolygon.push_back(lib::point(m_xmid, t)); if (edge == edge_topright) return; outpolygon.push_back(lib::point(r, t)); if (edge == edge_right) return; outpolygon.push_back(lib::point(r, b)); if (edge == edge_bottom) return; outpolygon.push_back(lib::point(l, b)); if (edge == edge_left) return; outpolygon.push_back(lib::point(l, t)); assert(edge == edge_topleft); return;}detail::edgetypedetail::angle_computer::angle2edge(double angle, lib::point &edgepoint){ AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge(%f) %d degrees", angle, (int)(angle*180/M_PI)); // Normalize angle to [-pi, pi) range while (angle < -M_PI) angle = angle + 2*M_PI; while (angle >= M_PI) angle = angle -2*M_PI; // Now find between which cornerpoint angles we are detail::edgetype edge; if (angle >= m_angle_topright && angle <= M_PI/2) { edge = edge_topright; AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge: topright"); } else if (angle >= m_angle_botright && angle <= m_angle_topright) { edge = edge_right; AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge: right"); } else if (angle >= m_angle_botleft && angle <= m_angle_botright) { edge = edge_bottom; AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge: bottom"); } else if (angle >= m_angle_topleft || angle <= m_angle_botleft) { edge = edge_left; AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge: left"); } else if (angle >= M_PI/2 && angle <= m_angle_topleft) { edge = edge_topleft; AM_DBG lib::logger::get_logger()->debug("angle_computer::angle2edge: topleft"); } else lib::logger::get_logger()->trace("transition_engine: impossible angle %f", angle); // Next compute the intersection point int l = m_rect.left(), r = m_rect.right(), t = m_rect.top(), b = m_rect.bottom(); if (edge == edge_topleft || edge == edge_topright) edgepoint = lib::point(round(m_xmid + m_xdist/tan(angle)), t); else if (edge == edge_right) edgepoint = lib::point(r, round(m_ymid - m_ydist*tan(angle))); else if (edge == edge_bottom) edgepoint = lib::point(round(m_xmid - m_xdist/tan(angle)), b); else edgepoint = lib::point(l, round(m_ymid + m_ydist*tan(angle))); return edge;}voidtransition_engine_clockwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); // First check whether we're done. clear(); if (m_progress > 0.999) { int l = dstrect.left(), r = dstrect.right(), t = dstrect.top(), b = dstrect.bottom(); m_newpolygon.push_back(lib::point(l, t)); m_newpolygon.push_back(lib::point(r, t)); m_newpolygon.push_back(lib::point(r, b)); m_newpolygon.push_back(lib::point(l, b)); return; } if (!m_angle_computer.matches(dstrect)) m_angle_computer = detail::angle_computer(dstrect); m_stepcount = 2*dstrect.width() + 2*dstrect.height(); double angle = M_PI/2 - (m_progress*2*M_PI); AM_DBG lib::logger::get_logger()->debug("transition_engine_clockwipe::compute: progress %f angle %f (%d)", m_progress, angle, (int)(angle*180/M_PI)); m_angle_computer.angle2poly(m_newpolygon, angle, true);}voidtransition_engine_singlesweepwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype singleSweepWipe not yet implemented");}voidtransition_engine_doublesweepwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype doubleSweepWipe not yet implemented");}voidtransition_engine_saloondoorwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype saloonDoorWipe not yet implemented");}voidtransition_engine_windshieldwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype windshieldWipe not yet implemented");}voidtransition_engine_fanwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype fanWipe not yet implemented");}voidtransition_engine_doublefanwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype doubleFanWipe not yet implemented");}voidtransition_engine_pinwheelwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype pinWheelWipe not yet implemented");}// series 4: matrix wipe typesvoidtransition_engine_snakewipe::compute(){ lib::rect dstrect = m_dst->get_rect(); int index = (int)(m_progress*MATRIX_HSTEPS*MATRIX_VSTEPS); int hindex = index % MATRIX_HSTEPS; int vindex = index / MATRIX_HSTEPS; int vindexpos = (dstrect.top() + vindex*(dstrect.height())/MATRIX_VSTEPS); int vindex2pos = (dstrect.top() + (vindex+1)*(dstrect.height())/MATRIX_VSTEPS); m_stepcount = MATRIX_HSTEPS*MATRIX_VSTEPS; clear(); if (vindex) m_newrectlist.push_back(lib::rect( dstrect.left_top(), lib::size(dstrect.width(), vindexpos-dstrect.top()))); if (hindex) { if (vindex & 1) { int hindexpos = (dstrect.right() - hindex*(dstrect.width())/MATRIX_VSTEPS); m_newrectlist.push_back(lib::rect( lib::point(hindexpos, vindexpos), lib::size(dstrect.width(), vindex2pos-vindexpos))); } else { int hindex2pos = (dstrect.left() + hindex*(dstrect.width())/MATRIX_VSTEPS); m_newrectlist.push_back(lib::rect( lib::point(dstrect.left(), vindexpos), lib::size(hindex2pos-dstrect.left(), vindex2pos-vindexpos))); } }}voidtransition_engine_waterfallwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); int index = (int)(m_progress*MATRIX_HSTEPS*MATRIX_VSTEPS); int hindex = index / MATRIX_HSTEPS; int vindex = index % MATRIX_HSTEPS; int hindexpos = (dstrect.left() + hindex*(dstrect.width())/MATRIX_VSTEPS); int hindex2pos = (dstrect.top() + (hindex+1)*(dstrect.width())/MATRIX_VSTEPS); int vindexpos = (dstrect.top() + vindex*(dstrect.height())/MATRIX_VSTEPS); m_stepcount = MATRIX_HSTEPS*MATRIX_VSTEPS; clear(); if (hindex) m_newrectlist.push_back(lib::rect( dstrect.left_top(), lib::size(hindexpos-dstrect.left(), dstrect.height()))); if (vindex) m_newrectlist.push_back(lib::rect( lib::point(hindexpos, dstrect.top()), lib::size(hindex2pos-hindexpos, vindexpos-dstrect.top())));}voidtransition_engine_spiralwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype spiralWipe not yet implemented");}voidtransition_engine_parallelsnakeswipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype parallelSnakesWipe not yet implemented");}voidtransition_engine_boxsnakeswipe::compute(){ lib::rect dstrect = m_dst->get_rect(); lib::logger::get_logger()->trace("transitiontype boxSnakesWipe not yet implemented");}// series 5: SMIL-specific typesvoidtransition_engine_pushwipe::compute(){ lib::rect dstrect = m_dst->get_rect(); int half_width = round(m_progress*dstrect.width());// int half_height = round(m_progress*(ymid - dstrect.top())); m_stepcount = dstrect.width(); m_oldsrcrect = lib::rect( dstrect.left_top(), lib::size(dstrect.width()-half_width, dstrect.height())); m_olddstrect = lib::rect( lib::point(dstrect.left()+half_width, dstrect.top()), lib::size(dstrect.width()-half_width, dstrect.height())); m_newsrcrect = lib::rect( lib::point(dstrect.right()-half_width, dstrect.top()), lib::size(half_width, dstrect.height())); m_newdstrect = lib::rect( dstrect.left_top(), lib::size(half_width, dstrect.height()));}voidtransition_engine_slidewipe::compute(){ lib::rect dstrect = m_dst->get_rect(); int half_width = round(m_progress*dstrect.width());// int half_height = round(m_progress*(ymid - dstrect.top())); m_stepcount = dstrect.width(); m_oldsrcrect = lib::rect( lib::point(dstrect.left()+half_width, dstrect.top()), lib::size(dstrect.width()-half_width, dstrect.height())); m_olddstrect = lib::rect( lib::point(dstrect.left()+half_width, dstrect.top()), lib::size(dstrect.width()-half_width, dstrect.height())); m_newsrcrect = lib::rect( lib::point(dstrect.right()-half_width, dstrect.top()), lib::size(half_width, dstrect.height())); m_newdstrect = lib::rect( dstrect.left_top(), lib::size(half_width, dstrect.height()));}voidtransition_engine_fade::compute(){ m_stepcount = 256;}audio_transition_engine::audio_transition_engine(): m_start_time(0), m_dur(0), m_startProgress(0), m_endProgress(1), m_outtrans(false), m_event_processor(NULL){}void audio_transition_engine::init(const lib::event_processor* evp,bool outtrans, const lib::transition_info* info) { m_event_processor = evp; m_outtrans = outtrans; m_start_time = m_event_processor->get_timer()->elapsed(); m_dur = info->m_dur; m_startProgress = info->m_startProgress; m_endProgress = info->m_endProgress; AM_DBG lib::logger::get_logger()->debug("audio_transition_engine::audio_transition_engine(0x%x): m_start_time=%d m_dur=%d m_startProgress=%f m_endProgress=%f",this,m_start_time,m_dur,m_startProgress,m_endProgress);}const doubleaudio_transition_engine::get_volume(const double soundlevel) { double progress; lib::transition_info::time_type now; now = m_event_processor->get_timer()->elapsed(); if (m_dur == 0 || is_done(now)) // no transition or transition finished return soundlevel; progress = ((double) (now - m_start_time) / m_dur) * (m_endProgress - m_startProgress); progress += m_startProgress; if (progress > m_endProgress) progress = m_endProgress; if (progress < m_startProgress) progress = m_startProgress; AM_DBG lib::logger::get_logger()->debug("audio_transition_engine::get_transition_volume(0x%x): soundlevel=%f m_outtrans=%d now=%d dur=%d progress=%f",this,soundlevel,m_outtrans,now,m_dur,progress); double level = soundlevel; if (m_outtrans) level *= (1.0 - progress); else level *= progress; return level;}const boolaudio_transition_engine::is_done(lib::transition_info::time_type now) { return now >= m_start_time + m_dur;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -