189 lines
5.8 KiB
C
189 lines
5.8 KiB
C
/* Copyrighted Pixar 1989 */
|
|
/* From the RenderMan Companion p. 168 */
|
|
/* Listing 8.5 An improved boilerplate viewing program */
|
|
|
|
#include <stdio.h>
|
|
#include <jman/ri.h>
|
|
#include <jman/camset.h>
|
|
|
|
#define NFRAMES 20
|
|
#define SHADING_RATE 20
|
|
/* viewbasics.c: file compiling view options into a rendering shell. */
|
|
|
|
#define DATATYPE RI_RGBA /* Pixels have RGB and coverage */
|
|
#define PICXRES 800.0 /* Horizontal output resolution */
|
|
#define PICYRES 600.0 /* Vertical output resolution */
|
|
|
|
#define CROPMINX 0.0 /* RiCropWindow() parameters */
|
|
#define CROPMAXX 1.0
|
|
#define CROPMINY 0.0
|
|
#define CROPMAXY 1.0
|
|
#define CAMXFROM -0.0 /* Camera position */
|
|
#define CAMYFROM 1.0
|
|
#define CAMZFROM -4.0
|
|
|
|
#define CAMXTO 0.0 /* Camera direction */
|
|
#define CAMYTO -3.0
|
|
#define CAMZTO 10.0
|
|
#define CAMROLL 0.0 /* Camera roll */
|
|
|
|
#define CAMZOOM 1.0 /* Camera zoom rate */
|
|
|
|
//--------------------------------------------------------------------
|
|
#define PATCH 1
|
|
|
|
#define X0 -1
|
|
#define X1 -.33
|
|
#define X2 .33
|
|
#define X3 1
|
|
#define Y0 -.7
|
|
#define Y1 -.1
|
|
#define Y2 0.1
|
|
#define Y3 0.7
|
|
#define Z0 -1
|
|
#define Z1 -.33
|
|
#define Z2 .33
|
|
#define Z3 1
|
|
|
|
void PatchExample(Patch)
|
|
RtPoint Patch[4][4];
|
|
{
|
|
RtPoint blpatch[2][2];
|
|
RtColor color = {1,1,0};
|
|
RtColor CpColors[16] = {{ .8, 0, 0 }, { 0, .8, 0 }, { 0, 0, .8 }, { .8, 0, .8 }, { .8, 0, 0 }, { 0, .8, 0 }, { 0, 0, .8 }, { .8, 0, .8 }, { .8, 0, 0 }, { 0, .8, 0 }, { 0, 0, .8 }, { .8, 0, .8 }, { .8, 0, 0 }, { 0, .8, 0 }, { 0, 0, .8 }, { .8, 0, .8 }};
|
|
int u, v;
|
|
#define MOVE_PT(d, s) {d[0]=s[0]; d[1]=s[1]; d[2]=s[2];}
|
|
#ifdef PATCH
|
|
RiColor(color);
|
|
// RiBasis(RiPowerBasis, RI_POWERSTEP, RiPowerBasis, RI_POWERSTEP);
|
|
// RiBasis(RiHermiteBasis, RI_HERMITESTEP, RiHermiteBasis, RI_HERMITESTEP);
|
|
// RiBasis(RiCatmullRomBasis, RI_CATMULLROMSTEP, RiCatmullRomBasis, RI_CATMULLROMSTEP);
|
|
// RiBasis(RiBSplineBasis, RI_BSPLINESTEP, RiBSplineBasis, RI_BSPLINESTEP);
|
|
RiPatch(RI_BICUBIC, RI_P, (RtPointer) Patch, "Cs", (RtPointer)CpColors, RI_NULL);
|
|
#endif
|
|
#ifdef HULL
|
|
for (v = 0; v < 3; v++) {
|
|
for (u = 0; u < 3; u++) {
|
|
MOVE_PT(blpatch[0][0], Patch[v][u])
|
|
MOVE_PT(blpatch[0][1], Patch[v][u+1])
|
|
MOVE_PT(blpatch[1][0], Patch[v+1][u])
|
|
MOVE_PT(blpatch[1][1], Patch[v+1][u+1])
|
|
color[0] = 1;
|
|
color[1] = 0.5*v;
|
|
color[2] = 0.5*u;
|
|
RiAttributeBegin();
|
|
RiColor(color);
|
|
RiPatch(RI_BILINEAR, RI_P, (RtPointer) blpatch, RI_NULL);
|
|
RiAttributeEnd();
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Go()
|
|
{
|
|
static RtPoint Patch[16] = {
|
|
{ X0, Y0, Z0}, { X1, Y2, Z0}, { X2, Y1, Z0}, { X3, Y3, Z0},
|
|
{ X0, Y1, Z1}, { X1, Y2, Z1}, { X2, Y1, Z1}, { X3, Y2, Z1},
|
|
{ X0, Y1, Z2}, { X1, Y2, Z2}, { X2, Y1, Z2}, { X3, Y2, Z2},
|
|
{ X0, Y0, Z3}, { X1, Y2, Z3}, { X2, Y1, Z3}, { X3, Y3, Z3}};
|
|
PatchExample(Patch);
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
RtPoint CameraFrom = { CAMXFROM, CAMYFROM, CAMZFROM },
|
|
CameraTo = { CAMXTO, CAMYTO, CAMZTO };
|
|
|
|
static RtColor Color = { .6, .8, .2 };
|
|
RtPoint Square[4] = { {.5,.5,0}, {.5,-.5,0}, {-.5,-.9,0}, {-.1,.5,0} };
|
|
RtPoint Hexagon[6] = { {.2,.5,0}, {.5,0,0}, {.2,-.5,0}, {-.2,-.5,0}, {-.5,0,0}, {-.2,.5,0} };
|
|
RtColor VertColors[6] = {{ .8, 0, 0 }, { 0, .8, 0 }, { 0, 0, .8 }, { .8, 0, .8 }, { .8, .8, 0 }, { 0, .8, .8 }};
|
|
RtPoint hull[8] = { {.5,.5,0}, {.5,-.5,0}, {-.5,-.5,0}, {-.5,.5,0}, {.3,-.3,0}, {-.5,-.5,1}, {-.3,.1,-.5}, {.5,.5,0} };
|
|
|
|
typedef struct _testi
|
|
{
|
|
RtInt dummy;
|
|
RtPointer p;
|
|
} testi;
|
|
|
|
int main()
|
|
{
|
|
RtInt frame, i, nverts[] = {4, 4};
|
|
RtToken my_var;
|
|
RtFloat width[4] = {0.005, 0.005, 0.03, 0.04};
|
|
|
|
RtLightHandle lighthnd;
|
|
|
|
RiBegin(RI_NULL); /* As always */
|
|
|
|
my_var = RiDeclare("Jens", "uniform string");
|
|
|
|
/* Output image characteristics */
|
|
RiShadingRate(SHADING_RATE);
|
|
RiFormat((RtInt)PICXRES, (RtInt)PICYRES, -1.0); /* Image resolution */
|
|
|
|
RiTransformBegin();
|
|
RiTranslate(10, 10, -5);
|
|
lighthnd = RiLightSource( "distantlight", RI_NULL);
|
|
RiTransformEnd();
|
|
RiIlluminate(lighthnd, RI_TRUE);
|
|
|
|
/* Region of image rendered */
|
|
RiCropWindow(CROPMINX, CROPMAXX, CROPMINY, CROPMAXY);
|
|
FrameCamera2(PICXRES*CAMZOOM, PICXRES, PICYRES);
|
|
|
|
RiClipping(1E-3, RI_INFINITY); /* Clipping planes*/
|
|
|
|
/* Now describe the world */
|
|
for (frame=0; frame < NFRAMES; frame++)
|
|
{
|
|
RiFrameBegin(frame);
|
|
RiDisplay(RI_NULL, RI_FRAMEBUFFER, DATATYPE, RI_NULL);
|
|
|
|
/* Camera position and orientation */
|
|
PlaceCamera(CameraFrom, CameraTo, CAMROLL);
|
|
// RiTranslate(1, 2, 3);
|
|
CameraFrom[0] += 2.0/NFRAMES;
|
|
|
|
RiWorldBegin();
|
|
|
|
RiBasis(RiBezierBasis, RI_BEZIERSTEP, RiBezierBasis, RI_BEZIERSTEP);
|
|
// RiBasis(RiBSplineBasis, RI_BSPLINESTEP, RiBSplineBasis, RI_BSPLINESTEP);
|
|
|
|
/* ...Your scene here... */
|
|
RiSurface("constant", RI_NULL);
|
|
RiRotate((360.0*frame)/NFRAMES, 0, 1, 0);
|
|
// RiCurves(RI_CUBIC, 1, nverts, RI_NONPERIODIC, RI_P, (RtPointer)hull, RI_WIDTH, (RtPointer)&width, RI_NULL);
|
|
RiAttributeBegin();
|
|
RiSides(2);
|
|
// RiTranslate(1, -0.5, 0);
|
|
Go();
|
|
RiAttributeEnd();
|
|
RiTransformBegin();
|
|
RiTransformBegin();
|
|
RiTranslate(0, -9.5, 0);
|
|
RiTransformEnd();
|
|
RiTranslate(0, -0.5, 0);
|
|
RiSurface("constant", RI_NULL);
|
|
RiPolygon(6, "P", (RtPointer)Hexagon, "Cs", (RtPointer)VertColors, RI_NULL);
|
|
RiTransformEnd();
|
|
RiTransformBegin();
|
|
RiTranslate(0, 0.5, 0);
|
|
// RiRotate(90, 1, 0, 0);
|
|
// RiRotate(45, 0, 1, 0);
|
|
RiColor(Color); /* Declare the color */
|
|
RiSides(2);
|
|
RiSphere(0.5, -0.5, 0.5, 360, RI_NULL);
|
|
RiTranslate(0, 0.5, 0);
|
|
RiTransformEnd();
|
|
|
|
RiWorldEnd();
|
|
RiFrameEnd();
|
|
}
|
|
|
|
RiEnd();
|
|
|
|
return 0;
|
|
}
|