/*
 * SquareImageProjection.java  1.0  98/06/03  Carl Burke
 *
 * Provides a square projection of data on a sphere.
 *
 * Copyright (c) 1998 Carl Burke.
 *
 * Derived from code in planet.c Copyright 1998 Torben AE. Mogensen
 */

public class SquareImageProjection extends ImageProjection
{
    public SquareImageProjection(int w, int h, SolidNoiseGenerator sng)
    {
	super(w, h, sng);
    }
    public void renderTerrain()
    {
  double x,y,scale1,theta1,cos2;
  int k,i,j;

  k = (int)(lat*Width*scale/Math.PI);
  for (j = 0; j < Height; j++) {
    y = (2.0*(j-k)-Height)/Width/scale*Math.PI;
    if (Math.abs(y)>=0.5*Math.PI) for (i = 0; i < Width ; i++)
       pixels[j*Width+i] = SNG.background();
    else {
      cos2 = Math.cos(y);
      if (cos2>0.0) {
	SNG.setScaling((scale*Width/Height/cos2/Math.PI), Width, Height);
	for (i = 0; i < Width ; i++) {
	  theta1 = longi-0.5*Math.PI+Math.PI*(2.0*i-Width)/Width/scale;
	  pixels[j*Width+i] = SNG.color(Math.cos(theta1)*cos2,Math.sin(y),-Math.sin(theta1)*cos2);
        }
      }
    }
  }
}
    public void renderLatitudes()
    {
	double y,theta1;
	int i,j,k;

	k = (int)(lat*Width*scale/Math.PI);
	for (theta1 = 0.0; theta1>-90.0; theta1-=hgrid);
	for (theta1 = theta1; theta1<90.0; theta1+=hgrid)
	{
	    y = DEG2RAD*theta1;
	    j = Height/2+(int)(0.5*y*Width*scale/Math.PI)+k;
	    if (j>=0 && j-360.0; theta1-=vgrid);
	for (theta1 = theta1; theta1<360.0; theta1+=vgrid)
	{
	    i = (int)(0.5*Width*(1.0+scale*(DEG2RAD*theta1-longi)/Math.PI));
	    if (i>=0 && i




1