/* $Id: quads_b.c,v 1.2 1998/04/09 21:27:43 penguin Exp $  (Pixar - RenderMan Division)  $Date: 1998/04/09 21:27:43 $ */
/*
** Copyright (c) 1998 PIXAR.  All rights reserved.  This program or
** documentation contains proprietary confidential information and trade
** secrets of PIXAR.  Reverse engineering of object code is prohibited.
** Use of copyright notice is precautionary and does not imply publication.
**
**                      RESTRICTED RIGHTS NOTICE
**
** Use, duplication, or disclosure by the Government is subject to the
** following restrictions:  For civilian agencies, subparagraphs (a) through
** (d) of the Commercial Computer Software--Restricted Rights clause at
** 52.227-19 of the FAR; and, for units of the Department of Defense, DoD
** Supplement to the FAR, clause 52.227-7013 (c)(1)(ii), Rights in
** Technical Data and Computer Software.
**
** Pixar
** 1001 West Cutting Blvd.
** Richmond, CA  94804
*/

/* Listing 16a - Routine generating quadric surfaces shown in Figure 4.1 */

#include <ri.h>
#include <math.h>
#include "go.h"

#define OFFSET 1.2

RtPoint Square[4] = { {1,1,0}, {1,-1,0}, {-1,-1,0}, {-1,1,0} };

static void
ShowQuads(void)
{
    static RtColor matcolor = { 0.85, 0.87, 0.87};
    static RtColor tablecolor = { 0.85, 0.87, 0.5};
    static RtColor darkwood = { 84.0/255.0, 56.0/255.0, 34.0/255.0};
    static RtColor lightwood = { 132.0/255.0, 100.0/255.0, 68.0/255.0 };
    

    //RtFloat Ks, Ka, Kd;
    //RtPoint hyperpt1, hyperpt2;
    RtToken RI_KM = RiDeclare("Km", "uniform float");
    RtToken RI_OFFSET = RiDeclare("offset", "uniform float");
    RtToken RI_LIGHTWOOD = RiDeclare("darkwood", "uniform color");
    RtToken RI_DARKWOOD = RiDeclare("lightwood", "uniform color");
    RtToken RI_ROUGHNESS = RiDeclare("roughness", "uniform float");
    RtToken RI_RINGSCALE = RiDeclare("ringscale", "uniform float");
    RtFloat km = 2.5;
    RtFloat ka = 0.5;
    RtFloat kd = 0.5;
    RtFloat off = 0.33;
    RtFloat woodrough = 0.001;
    RtFloat ringscale = 20;
    RtFloat woodkd = 0.7;

    RiColor(matcolor);
    RiRotate(-90.0, 1.0, 0.0, 0.0);

    RiRotate(130, 1, -.15, .25);
    RiAttributeBegin();
    //RiSurface("matte", RI_KA, &ka, RI_KD, &kd, RI_NULL); 
    //RiSurface("show_st", RI_NULL); 
    //RiSurface("show_uv", RI_NULL); 
    RiSurface("placematsurf", RI_KA, &ka, RI_KD, &kd, RI_NULL); 
    //RiDisplacement("placematwave", RI_OFFSET, &off, RI_KM, &km, RI_NULL);

    RiPolygon( (RtInt) 4,        /* Declare the square */
	       RI_P, (RtPointer) Square, RI_NULL);
    RiAttributeEnd();


    RiColor(tablecolor);
    RiAttributeBegin();
    RiSurface("wood", 
	      RI_ROUGHNESS, &woodrough, RI_RINGSCALE, &ringscale, 
	      RI_LIGHTWOOD, &lightwood, RI_DARKWOOD, &darkwood, 
	      RI_KD, &woodkd , RI_NULL); 
    //RiSurface("show_st", RI_NULL); 
    //RiSurface("show_uv", RI_NULL); 
    //RiSurface("placematsurf", RI_KA, &ka, RI_KD, &kd, RI_NULL); 
    //RiDisplacement("placematwave", RI_OFFSET, &off, RI_KM, &km, RI_NULL);

    RiTranslate(0,1,.02);
    RiScale(3,2.3,2);
    RiPolygon( (RtInt) 4,        /* Declare the square */
	       RI_P, (RtPointer) Square, RI_NULL);
    RiAttributeEnd();
}

void
Go(void)
{
    RtFloat intensity;
    RtPoint from = { -40.0, 50, -40 };
    RtColor lightcolor = { 0.8, 0.9, 1 };

    intensity = 0.2;

    RiDeclare("intensity", "uniform float");
    RiDeclare("from", "uniform point");
    RiLightSource("ambientlight",
        (RtToken)"intensity",(RtPointer)&intensity, RI_NULL);

    intensity = 1.4;
    /*
    RiLightSource("pointlight", 
		  (RtToken)"intensity", (RtPointer)&intensity,
		  (RtToken)"lightcolor", (RtPointer)&lightcolor,
		  (RtToken)"from", (RtPointer)from, RI_NULL);
    */
    
    RiLightSource("distantlight", 
		  (RtToken)"intensity", (RtPointer)&intensity,
		  (RtToken)"lightcolor", (RtPointer)&lightcolor,
		  (RtToken)"from", (RtPointer)from, RI_NULL);
    ShowQuads();
}
