#define WIN32_LEAN_AND_MEAN
#define STRICT

#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <winsock2.h>
#include <commctrl.h>
#include <commdlg.h>
#include <mmsystem.h>
#include <commctrl.h>
#include <shlwapi.h>

#include <io.h>
#include <conio.h>
#include <commctrl.h>
#include <shlwapi.h>

#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <time.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <math.h>

#define _USE_BETTLEJUICE_

#include "beetlejuice.h"


#define L -.5       /* For x: left side     */
#define R  .5       /* For x: right side    */
#define D -.5       /* For y: down side     */
#define U  .5       /* For y: upper side    */
#define F  .5       /* For z: far side      */
#define N -.5       /* For z: near side     */

/* UnitCube(): define a cube in the graphics environment */
void UnitCube(FRtShaderHandle _hShader, FRtMatrix _objToWorld, int _id)
{
unsigned char szBuf[256];

    static FRtPoint Cube[6][4] = {
        { {L,D,F},  {L,D,N},  {R,D,N},  {R,D,F} },   /* Bottom face  */
        { {L,D,F},  {L,U,F},  {L,U,N},  {L,D,N} },   /* Left face    */
        { {R,U,N},  {L,U,N},  {L,U,F},  {R,U,F} },   /* Top  face    */
        { {R,U,N},  {R,U,F},  {R,D,F},  {R,D,N} },   /* Right face   */
        { {R,D,F},  {R,U,F},  {L,U,F},  {L,D,F} },   /* Far face     */
        { {L,U,N},  {R,U,N},  {R,D,N},  {L,D,N} }    /* Near face    */
    };
    int i;
FRiAttributeBegin();
    for( i = 0; i < 6; i++)  
	{
	sprintf((char *)szBuf, "cubeface%d%d" , _id, i);

	FRiAttribute(FRI_ATT_IDENTIFIER, szBuf, FRI_NULL);

	FRiSurfaceInstance((FRtShaderHandle)_hShader);

	FRiTransform(_objToWorld);

    FRiPolygon( (FRtInt) 4, FRI_P, (FRtPointer) Cube[i], FRI_NULL);    

	FRiAttributeEnd();
	}
}

BOOL Plane(FRtShaderHandle _hShader)
{
	FRtInt numVerts=4;
	FRtInt numFaces=2;

	FRtPoint verts[4];
	FRtInt faces[6];
	FRtUInt smgroups[2];

	FRtMatrix objToWorld;
	objToWorld[0][0]=1.000000f; objToWorld[0][1]=0.000000f; objToWorld[0][2]=-0.000000f; objToWorld[0][3]=0.000000f;
	objToWorld[1][0]=0.000000f; objToWorld[1][1]=1.000000f; objToWorld[1][2]=-0.000000f; objToWorld[1][3]=0.000000f;
	objToWorld[2][0]=-0.000000f; objToWorld[2][1]=-0.000000f; objToWorld[2][2]=1.000000f; objToWorld[2][3]=0.000000f;
	objToWorld[3][0]=0.000005f; objToWorld[3][1]=0.000005f; objToWorld[3][2]=-0.000000f; objToWorld[3][3]=1.000000f;


	verts[0][0]=-100.000000f; verts[0][1]=-100.000000f; verts[0][2]=0.000000f;
	verts[1][0]=100.000000f; verts[1][1]=-100.000000f; verts[1][2]=0.000000f;
	verts[2][0]=-100.000000f; verts[2][1]=100.000000f; verts[2][2]=0.000000f;
	verts[3][0]=100.000000f; verts[3][1]=100.000000f; verts[3][2]=0.000000f;

	faces[0]=2; faces[1]=0; faces[2]=3; smgroups[0]=1;
	faces[3]=1; faces[4]=3; faces[5]=0; smgroups[1]=1;

	FRiAttributeBegin();

		FRiAttribute(FRI_ATT_IDENTIFIER, "Plane01", FRI_NULL);

		FRiSurfaceInstance(_hShader);

		FRiTransform(objToWorld);
		FRiPointsTriangles(2, 4, faces, FRI_P, &verts, FRI_SMGROUP, &smgroups, FRI_NULL);

	FRiAttributeEnd();

	return TRUE;
}

void go()
{
FRtFloat		i_amb = 0.3f;
FRtFloat		i_dist = 1.0f;

FRtPoint		from = {-0.1f, 0.5f, -1.0f};
FRtPoint		to = {0.0, 0.0, 0.0};

FRtColor gray,red,yellow;
gray[0]  =0.85f; gray[1]  =0.85f; gray[2]  =0.85f;
red[0]   =0.85f; red[1]   =0.0f;  red[2]   =0.0f;
yellow[0]=1.0f;  yellow[1]=1.0f;  yellow[2]=0.0f;

FRtShaderHandle grayShader   = FRiSurface("standard", FRI_COLOR, gray,   FRI_NULL);
FRtShaderHandle redShader    = FRiSurface("standard", FRI_COLOR, red,    FRI_NULL);
FRtShaderHandle yellowShader = FRiSurface("standard", FRI_COLOR, yellow, FRI_NULL);

FRtMatrix objToWorld;

objToWorld[0][0]=1.000000f; objToWorld[0][1]=0.000000f; objToWorld[0][2]=-0.000000f; objToWorld[0][3]=0.000000f;
objToWorld[1][0]=0.000000f; objToWorld[1][1]=1.000000f; objToWorld[1][2]=-0.000000f; objToWorld[1][3]=0.000000f;
objToWorld[2][0]=-0.000000f; objToWorld[2][1]=-0.000000f; objToWorld[2][2]=1.000000f; objToWorld[2][3]=0.000000f;
objToWorld[3][0]=0.000005f; objToWorld[3][1]=0.000005f; objToWorld[3][2]=-0.000000f; objToWorld[3][3]=1.000000f;


	FRiLightSource (FRI_AMBIENTLIGHT, FRI_INTENSITY, &i_amb, FRI_NULL);
	FRiLightSource (FRI_DISTANTLIGHT, FRI_INTENSITY, &i_dist, FRI_FROM, &from, FRI_TO, &to, FRI_NULL);

Plane(grayShader);

objToWorld[3][0]=0.000005f; 
objToWorld[3][1]=0.000005f; 
objToWorld[3][2]=1.000000f;


UnitCube(yellowShader, objToWorld, 0);

objToWorld[3][0]=-2.000005f; 
objToWorld[3][1]=0.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 1);

objToWorld[3][0]=-2.000005f; 
objToWorld[3][1]=-2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 2);

objToWorld[3][0]=0.000005f; 
objToWorld[3][1]=-2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 3);


objToWorld[3][0]=2.000005f; 
objToWorld[3][1]=-2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 4);

objToWorld[3][0]=-2.000005f; 
objToWorld[3][1]=2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 5);

objToWorld[3][0]=2.000005f; 
objToWorld[3][1]=2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 6);

objToWorld[3][0]=0.000005f; 
objToWorld[3][1]=2.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 7);

objToWorld[3][0]=2.000005f; 
objToWorld[3][1]=0.000005f; 
objToWorld[3][2]=1.000000f;

UnitCube(redShader, objToWorld, 8);
}



// EOF