+package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
+import java.util.*;
+
+public class BindingGroup<T extends HasBindingGroup> {
+
+ private T master = null;
+ private HashMap<T,Matrix> matrices = new HashMap<T,Matrix>();
+
+ public BindingGroup(T master) {
+ this.master = master;
+ matrices.put(master, Matrix.ONE);
+ }
+
+ public void merge(BindingGroup<T> bg, Matrix m) {
+ for(HasBindingGroup hbg : bg.matrices.keySet()) {
+ matrices.put((T)hbg, bg.matrices.get(hbg).times(m));
+ hbg.bindingGroup = this;
+ }
+ bg.matrices.clear();
+ bg.master = null;
+ }
+
+ public T getMaster() { return master; }
+ public Matrix getMatrix(T t) { return matrices.get(t); }
+
+ // t1 = getMatrix(t1) * master
+ // getMatrix(t2)^-1 * t2 = master
+ // t1 = getMatrix(t1) * getMatrix(t2)^-1 * t2
+ /** t1 = getMatrix(t1, t2) * t2 */
+ public Matrix getMatrix(T t1, T t2) {
+ return getMatrix(t1).times(getMatrix(t2).inverse());
+ }
+
+}