/*
 * Class GrModel for Hierarchical Modeling
 * 
 * Don Fussell
 * October 2002
 */

import java.awt.*;
import java.awt.geom.*;

public class GrModel {

    // Make the instances to be moved fields of the class so they are
    // known in both makeModel and moveModel
    private GrInstance rotbox, top;

    private GrInstance root;

    public GrModel(){
	root = makeModel();
    }

    public GrInstance makeModel () {
	GrObject rect0 = new GrObject();
	rect0.addShape(new Rectangle2D.Double(-25,-15,50,30));

	// We didn't declare this here, it's a field of the class,
	// because we're going to animate this instance in timestep().
	rotbox = new GrInstance(rect0);

	GrObject rect1 = new GrObject();
	rect1.addInstance(rotbox);
	GrInstance box1 = new GrInstance(rect1);
	box1.transform.setToTranslation(50,30);
	GrInstance box2 = new GrInstance(rect1);
	box2.transform.setToTranslation(100,60);
	GrInstance box3 = new GrInstance(rect1);
	box3.transform.setToTranslation(150,90);
	GrObject boxes = new GrObject();
	boxes.addInstance(box2);
	boxes.addInstance(box3);
	boxes.addInstance(box1);

	// We didn't declare this here, it's a field of the class,
	// because we're going to animate this instance in timestep().
	top = new GrInstance(boxes);

	GrObject topobj = new GrObject();
	topobj.addInstance(top);

	// The root must be an instance defining all that you want
	// to display.  It must be a field of the class in this code.
	GrInstance rt = new GrInstance(topobj);
	rt.transform.setToTranslation(250,200);
	return rt;
    }

    // Here's where you move stuff.  Put your animation transforms
    // here, and make sure all instances you reference are fields of
    // the class, not local variables in the constructor.
    public void moveModel() {
    	rotbox.transform.rotate(Math.PI/10,0,0);
    	top.transform.rotate(Math.PI/100,0,0);
    }

    public GrInstance getRoot() {
	return root;
    }
}
