package myGraphics.Kinematics; import myGraphics.Shape3d.*; import myGraphics.VectorGrafix.*; import myGraphics.Perspective.*; import java.awt.Graphics; public class StackMachine { Transformation3d[] theStack; int sp = 0; static final int DEFAULT_MAX_STACK = 50; int maxStack = DEFAULT_MAX_STACK; public StackMachine() { theStack = new Transformation3d[DEFAULT_MAX_STACK]; maxStack = DEFAULT_MAX_STACK; sp = 0; theStack[0] = new Transformation3d(); // identity matrix } public StackMachine(int maxHeight) { theStack = new Transformation3d[maxHeight]; maxStack = maxHeight; sp = 0; theStack[0] = new Transformation3d(); // identity matrix } public Transformation3d top() { return theStack[sp]; } public void translate(double x, double y, double z) { Transformation3d T = new Transformation3d(); // identity matrix T = T.translate(x, y, z); theStack[sp] = T.appliedBefore(theStack[sp]); } public void rotate(double ax, double ay, double az) { Transformation3d R = new Transformation3d(); // identity matrix R = R.x_rotate(ax); R = R.y_rotate(ay); R = R.z_rotate(az); theStack[sp] = R.appliedBefore(theStack[sp]); } public void push() { theStack[sp + 1] = theStack[sp].copy(); sp++; } public void pop() { sp--; } public void render(Model theModel, Graphics g, Camera c, Viewport v) { theModel.trans = (theModel.defaultTrans).appliedBefore(theStack[sp]); theModel.displayShape(g, c, v); } public void stop() { /* Stop the interpreter. How do we do that? */ } }