import java.awt.Event;
import zBuffer;

public class World extends zBuffer
{
  Matrix TRAFO=new Matrix();
  XYZ OldPT,NewPT;
  XYZ Null,North,Green;
  RGB backcolor;
  PixelGraphic pgr;

public void init()
  {
    Resize(120,120);
    Null=new XYZ(0f,0f,0f);
    North=new XYZ(0f,-1f,0f);
    Green=new XYZ(-1f,0f,0f);
    /* Green stands for 'Greenwich', not for the color */
    backcolor=new RGB(0f,0f,0.25f);
    pgr=new PixelGraphic(this,getCodeBase(),"world-map.gif");
    LightSource(new XYZ(-0.5f,-0.5f,1f),0.1f);
    DrawScene();
  }

public void DrawScene()
  {
    int i;
    PushMatrix();
    Clear();
    SetBackground(backcolor);
    Sphere(Null,0.9f,pgr,North,Green,1,1);
    repaint();
    PopMatrix();
  }

public boolean handleEvent(Event e)
  {
    switch (e.id) {
    case Event.MOUSE_DOWN:
      OldPT=GetMousePosition(e);
    case Event.MOUSE_DRAG:
      NewPT=GetMousePosition(e);
      TRAFO=GetMatrix();
      ClearMatrix();
      RotateY(NewPT.x-OldPT.x);
      RotateX(OldPT.y-NewPT.y);
      MultMatrix(TRAFO);
      OldPT=new XYZ(NewPT);
      DrawScene();
      break;
    };
    return true;
  }

}
