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

public class SinusoidImageProjection extends ImageProjection
{
    public SinusoidImageProjection(int w, int h, SolidNoiseGenerator sng)
    {
	super(w, h, sng);
    }
    public void renderTerrain()
    {
  double x,y,theta1,theta2,cos2,l1,i1,scale1;
  int k,i,j,l,c;

  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; iMath.PI/12.0) pixels[j*Width+i] = SNG.background();
	  else
	    pixels[j*Width+i] =
		SNG.color(Math.cos(theta1+theta2)*cos2,Math.sin(y),
			-Math.sin(theta1+theta2)*cos2);
        }
      }
    }
  }
}
    public void renderLatitudes()
    {
	double x,y,cos2,theta1,theta2;
	int i,i1,j,k,l,l1;

	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;
	  cos2 = Math.cos(y);
	  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=0 && c