1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <stdio.h>
#include <ri.h>
/*
* BMRT Introduction - Michael J. Hammel
* Example 1b - a sphere over a plane
*/
main()
{
/* The angle of the field of view of this image */
RtFloat fov = 35.0;
/* The color we'll use for the sphere */
RtColor blue = { 0.2,0.3,0.9 };
/* The color we'll use for the plane under the sphere */
RtColor gray = { 0.9, 0.9, 0.9 };
/* The intensity level of the distant light */
RtFloat intensity = 1.0;
/*
* Coordinates for the distant light.
*/
RtPoint from = {0.0, 10.5, -100.0};
RtPoint to = {0.0, 0.0, 0.0};
RtPoint from2 = {0.0, 0.0, 2.0};
RtPoint to2 = {0.0, -1.0, 3.5};
/* The coordinates of the corners of our plane */
RtPoint points[4] = {
-3.0, 0.0, 0.0,
3.0, 0.0, 0.0,
3.0, 3.0, 0.0,
-3.0, 3.0, 0.0
};
/*
* RI_NULL means send RIB output to standard out; this could be
* changed to a filename to force the RIB to a specific file. You can
* also specify the name of the one of the BMRT renderers which will
* cause the output to be piped directly to that renderer.
*/
RiBegin(RI_NULL);
/*
* The filename of the rendered image is specfified in the RiDisplay
* command. This is not where the RIB output goes, this is where
* the output from the renderer goes.
*/
RiDisplay ("example-2a.tif", RI_FILE, RI_RGB, RI_NULL);
/*
* Image size - the "1" is the ratio of width to height for pixels.
* Unless you're using non-square pixels this should always be 1.
*/
RiFormat (480, 360, 1);
/*
* Set the samples per pixel to be 1 in each direction.
*/
RiPixelSamples ( 1, 1 );
/*
* Perspective views give a more realistic sense of depth to
* the image.
*/
RiProjection ( RI_PERSPECTIVE, RI_FOV, (RtPointer)&fov, RI_NULL );
/*
* Set our initial position for World objects. Basically this
* is just setting our initial camera position to 8 units in
* the positive Z direction. Any changes we would make to the
* cameras postion would be relative to this.
*/
RiTranslate (0, 0, 8);
/*
* Now we start to define the objects in our scene.
* All our rendering options are frozen inside the World commands.
*/
RiWorldBegin();
/*
* Set up a distant light source. Distant lights have parallel
* rays which follow a line parallel to the line defined by
* "from" and "to" below.
*/
RiLightSource(RI_DISTANTLIGHT, RI_INTENSITY, &intensity,
RI_FROM, (RtPointer)from, RI_TO, (RtPointer)to, RI_NULL);
/*
* Each object has its own set of attributes. Putting them
* inside the Attribute commands prevents us from accidently
* forgetting to reset the attributes, such as a colors,
* for a later object.
*/
RiAttributeBegin();
/*
* We need to set the surface texture of the sphere first. Here
* we use a simple matte surface shader which is provided
* in the BMRT distribution. The surface will have a blue
* color.
*/
RiColor(blue);
RiSurface("matte", RI_NULL);
/*
* Next we define our sphere. We'll move it up a little from
* the XZ plane.
*/
RiTranslate ( 0, 0.75, 0.0 );
RiSphere(0.8,-0.8, 0.8, 360.0, RI_NULL);
RiAttributeEnd();
RiLightSource(RI_SPOTLIGHT, RI_INTENSITY, &intensity,
RI_FROM, (RtPointer)from2, RI_TO, (RtPointer)to2, RI_NULL);
/*
* Now a shiny, metal plane below the sphere.
*/
RiAttributeBegin();
RiColor(gray);
RiSurface("matte", RI_NULL);
RiTranslate ( 0, -1.0, 2.0 );
RiRotate ( 80, 1, 0, 0 );
RiPolygon(4, RI_P, (RtPointer)points, RI_NULL);
RiAttributeEnd();
/*
* Don't forget: RiWorldEnd() causes the current scene to be
* written to the output file (or standard out if no file is
* defined).
*/
RiWorldEnd();
}
|