/* taken from Listing 2.8 : A simple rib generating file  */
#include <ri.h>
#include <math.h>

#define WINDOWX    256        /* Width of the window               */
#define WINDOWY    256        /* Height of the window              */

#define PI         3.14159256 /* PI */

main()
{
  RtPoint from, to;
  RtFloat intensity, fov, yAngle, xAngle;
  
  RiBegin(RI_NULL);    /* Start the renderer */
  
  from[0] =  1.0; to[0] = 0.0;
  from[1] =  1.0; to[1] = 0.0;
  from[2] = -2.0; to[2] = 0.0;

  intensity = 1.5;

  RiLightSource("distantlight", "intensity", &intensity, "from", from, "to", to, RI_NULL);  
  
  /*** Viewing transformation ***/
  fov = 50; /* measured in degrees of the field of view */
  RiProjection("perspective", RI_FOV, (RtPointer) &fov, RI_NULL);
  RiTranslate(0.0, 0.0, 2.0);
  
  /*** Display information ***/
  RiDisplay("simple.tif", RI_FILE, RI_RGB, RI_NULL);
  RiFormat((RtInt) WINDOWX, (RtInt) WINDOWY, -1.0); 
  RiShadingRate(1.0);

  /*** Geometry Begin ***/
  RiWorldBegin();
  
  /*** So that it rotates about world y first and then world x ***/
  xAngle = yAngle = 30.0;
  RiRotate(yAngle, 0.0, 1.0, 0.0); 
  RiRotate(-xAngle, cos(yAngle * PI/180.0), 0.0, sin(yAngle * PI/180.0));

  /*** Surface information ***/
  RiSurface("plastic", RI_NULL);  

  /*** Geometry information ***/
  UnitCube();

  RiWorldEnd();
  RiEnd();

  return 0;
}