1 package prefuse.action.animate; 2 3 import java.awt.geom.Point2D ; 4 5 import prefuse.Display; 6 import prefuse.action.ItemAction; 7 import prefuse.util.MathLib; 8 import prefuse.visual.VisualItem; 9 10 11 17 public class PolarLocationAnimator extends ItemAction { 18 19 private Point2D m_anchor = new Point2D.Double (); 20 private String m_linear = null; 21 22 private double ax, ay, sx, sy, ex, ey, x, y; 24 private double dt1, dt2, sr, st, er, et, r, t, stt, ett; 25 26 30 public PolarLocationAnimator() { 31 super(); 32 } 33 34 39 public PolarLocationAnimator(String group) { 40 super(group); 41 } 42 43 54 public PolarLocationAnimator(String group, String linearGroup) { 55 super(group); 56 m_linear = linearGroup; 57 } 58 59 private void setAnchor() { 60 Display d = getVisualization().getDisplay(0); 61 m_anchor.setLocation(d.getWidth()/2,d.getHeight()/2); 62 d.getAbsoluteCoordinate(m_anchor, m_anchor); 63 ax = m_anchor.getX(); 64 ay = m_anchor.getY(); 65 } 66 67 70 public void run(double frac) { 71 setAnchor(); 72 super.run(frac); 73 } 74 75 78 public void process(VisualItem item, double frac) { 79 if ( m_linear != null && item.isInGroup(m_linear) ) { 80 double s = item.getStartX(); 82 item.setX(s + frac*(item.getEndX()-s)); 83 s = item.getStartY(); 84 item.setY(s + frac*(item.getEndY()-s)); 85 return; 86 } 87 88 sx = item.getStartX() - ax; 90 sy = item.getStartY() - ay; 91 ex = item.getEndX() - ax; 92 ey = item.getEndY() - ay; 93 94 sr = Math.sqrt(sx*sx + sy*sy); 95 st = Math.atan2(sy,sx); 96 97 er = Math.sqrt(ex*ex + ey*ey); 98 et = Math.atan2(ey,ex); 99 100 stt = st < 0 ? st+MathLib.TWO_PI : st; 101 ett = et < 0 ? et+MathLib.TWO_PI : et; 102 103 dt1 = et - st; 104 dt2 = ett - stt; 105 106 if ( Math.abs(dt1) < Math.abs(dt2) ) { 107 t = st + frac * dt1; 108 } else { 109 t = stt + frac * dt2; 110 } 111 r = sr + frac * (er - sr); 112 113 x = Math.round(ax + r*Math.cos(t)); 114 y = Math.round(ay + r*Math.sin(t)); 115 116 item.setX(x); 117 item.setY(y); 118 } 119 120 } | Popular Tags |