//
import java.awt.*;
import render.*;
public class SimpleExample extends RenderApplet
{
Geometry upperLeftArm, lowerLeftArm;
Geometry upperRightArm, lowerRightArm;
String message = "no message";
Matrix cam = new Matrix();
public void drawOverlay(Graphics g) {
g.setColor(Color.black);
g.drawString(message, 5, 14);
}
public void initialize() {
message = getParameter("fred");
Material plastic = new Material();
plastic.setAmbient(.2,0,0);
plastic.setDiffuse(.8,0,0);
plastic.setSpecular(1,1,1,10);
setBgColor(.6,.6,.8);
addLight(1,1,1, 1,1,1);
upperLeftArm = getWorld().add().ball(4);
upperLeftArm.setMaterial(plastic);
lowerLeftArm = getWorld().add().ball(4);
lowerLeftArm.setMaterial(plastic);
upperRightArm = getWorld().add().ball(4);
upperRightArm.setMaterial(plastic);
lowerRightArm = getWorld().add().ball(4);
lowerRightArm.setMaterial(plastic);
}
public void animate(double time) {
double leftSignal = 3 * time;
double rightSignal = 3 * time + Math.PI;
double leftShoulder = Math.sin(leftSignal);
double leftElbow = Math.cos(leftSignal) * .5 + .5;
double rightShoulder = Math.PI - Math.sin(rightSignal);
double rightElbow = - (Math.cos(rightSignal) * .5 + .5);
// TRANSFORM MY CAMERA
cam.identity();
cam.translate(0, time, 0);
// APPLY INVERSE OF CAMERA HERE TO MATRIX ON STACK
m().invert(cam);
rotateZ(0.3 * Math.sin(3 * time + 1));
push();
translate(1,0,0);
rotateZ(leftShoulder);
limb(upperLeftArm);
translate(2,0,0);
rotateZ(leftElbow);
limb(lowerLeftArm);
pop();
push();
translate(-1,0,0);
rotateZ(rightShoulder);
limb(upperRightArm);
translate(2,0,0);
rotateZ(rightElbow);
limb(lowerRightArm);
pop();
}
void limb(Geometry shape) {
push();
translate(1,0,0);
scale(1,0.2,0.2);
transform(shape);
pop();
}
}