ca07312ad88e317eab2cb207b78ab7de3c855306
[anneal.git] / src / edu / berkeley / qfat / geom / BindingGroup.java
1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3 import java.util.*;
4
5 public class BindingGroup<T extends HasBindingGroup> {
6
7     private T                  master   = null;
8     private HashMap<T,Matrix>  matrices = new HashMap<T,Matrix>();
9
10     public BindingGroup(T master) {
11         this.master = master;
12         matrices.put(master, Matrix.ONE);
13     }
14
15     public void merge(BindingGroup<T> bg, Matrix m) {
16         for(HasBindingGroup hbg : bg.matrices.keySet()) {
17             matrices.put((T)hbg, bg.matrices.get(hbg).times(m));
18             hbg.bindingGroup = this;
19         }
20         bg.matrices.clear();
21         bg.master = null;
22     }
23
24     public T getMaster() { return master; }
25     public Matrix getMatrix(T t) { return matrices.get(t); }
26
27     //                    t1 = getMatrix(t1) * master
28     // getMatrix(t2)^-1 * t2 =                 master
29     //                    t1 = getMatrix(t1) * getMatrix(t2)^-1 * t2
30     /** t1 = getMatrix(t1, t2) * t2 */
31     public Matrix getMatrix(T t1, T t2) {
32         return getMatrix(t1).times(getMatrix(t2).inverse());
33     }
34
35 }