G3dRayTrace.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 15, 1992 10:42 pm PDT
DIRECTORY CedarProcess, G3dBasic, G3dLight, G3dMatrix, G3dView, Imager, ImagerColor, ImagerPixel, ImagerSample, IO, Rope, ViewerClasses;
G3dRayTrace: CEDAR DEFINITIONS
~ BEGIN
Imported Types
Process:    TYPE ~ CedarProcess.Process;
PixelMap:    TYPE ~ ImagerPixel.PixelMap;
SampleMap:   TYPE ~ ImagerSample.SampleMap;
Ray:     TYPE ~ G3dBasic.Ray;
IntegerPair:   TYPE ~ G3dBasic.IntegerPair;
Triple:    TYPE ~ G3dBasic.Triple;
LightSequence:  TYPE ~ G3dLight.LightSequence;
Matrix:    TYPE ~ G3dMatrix.Matrix;
Viewport:    TYPE ~ G3dMatrix.Viewport;
Context:    TYPE ~ Imager.Context;
RGB:     TYPE ~ ImagerColor.RGB;
ROPE:     TYPE ~ Rope.ROPE;
origin:    Triple ~ G3dBasic.origin;
yAxis:    Triple ~ G3dBasic.yAxis;
zAxis:     Triple ~ G3dBasic.zAxis;
Local Types
ClientProc:   TYPE ~ PROC [clientData: REF ANY];
RayProc:    TYPE ~ PROC [ray: Ray, clientData: REF ANY] RETURNS [rgb: RGB];
RayData:    TYPE ~ REF RayDataRep;
RayDataRep:   TYPE ~ RECORD [
State:
nextPixel:      IntegerPair ¬ [0, 0],   -- the next pixel to ray-trace
Viewing:
eyePoint:      Triple ¬ origin,    -- base of ray
eyeView:      Triple ¬ zAxis,    -- direction of ray
upDirection:     Triple ¬ yAxis,    -- up orientation
fieldOfView:     REAL ¬ 40.0,     -- angle for half screen
Lighting:
lights:       LightSequence ¬ NIL,  -- sequence of lights
Surface:
portionSpecular:    REAL ¬ 0.5,     -- portion of specularity
Image:
x, y:       NAT ¬ 0,      -- origin of image (in pixels)
w, h:       NAT ¬ 80,     -- size of image (in pixels)
display:      PixelMap,     -- the color display
redo:       SampleMap ¬ NIL,   -- used for adaptive sampling
Miscellany:
clientData:     REF ANY ¬ NIL,    -- passed to in rayProc
finishProc:     ClientProc ¬ NIL,   -- called upon completion
Ray-Tracing:
jitter:       BOOL ¬ FALSE,    -- stochastic ray from pixel center
noShading:     BOOL ¬ FALSE,    -- iff true, show hit-testing only
traceOctree:     BOOL ¬ FALSE,    -- iff true, show octree hit-testing
nPixelSamples:    NAT ¬ 1,      -- sub-sampling of pixels
adaptiveLimit:    NAT ¬ 0 ,     -- # levels of adaptive refinement
rgb:       RGB ¬ [0, 0, 0],    -- pixel value
ray:       Ray ¬ [origin, origin],  -- the ray
rayProc:      RayProc ¬ NIL,    -- client supplied ray-trace proc
process:      Process ¬ NIL    -- forked process
];
Ray Tracing
RayTrace: PROC [
display:      PixelMap,     -- place to create the ray-traced image
eyePoint:      Triple ¬ origin,    -- position of the eye
eyeView:      Triple ¬ zAxis,    -- view direction
upDirection:     Triple ¬ yAxis,    -- orientation
fieldOfView:     REAL ¬ 40.0,     -- half horizontal view in degrees
jitter:       BOOL ¬ FALSE,    -- stochastic ray from pixel center
nPixelSamples:    NAT ¬ 1,      -- sub-sampling of pixels
adaptiveLimit:    NAT ¬ 0,      -- # levels of adaptive refinement
rayProc:      RayProc ¬ NIL,    -- client supplied ray-tracing proc
clientData:     REF ANY ¬ NIL]    -- passed to the rayProc
RETURNS      [RayData];
This forks a ray-tracing process and the sampleMaps are painted accordingly.
The eyeView is mapped to the center of the sampleMaps and the fieldOfView spans
the right half of the sampleMaps. rayProc is called with a unit length ray.
StartRayTracing: PROC [r: RayData];
Begin or resume the ray-tracing.
StopRayTracing: PROC [r: RayData];
Suspend the ray-tracing.
ResetRayTracing: PROC [r: RayData];
Reset the next pixel to be the starting pixel of the image.
SetNextPixel: PROC [r: RayData];
Advance to the next ray-traced image pixel.
SetRay: PROC [r: RayData, x, y: NAT];
Set the ray given the ray-traced image pixel location.
Miscellany
AspectRatio: PROC [r: RayData] RETURNS [REAL];
Return the aspect ratio of the ray-traced image.
RayImageScreenCorners: PROC [r: RayData] RETURNS [p1, p2, p3, p4: Triple];
Return the four 3D corners of the image screen.
DrawRayTip: PROC [context: Context, r: RayData, view: Matrix, viewport: Viewport];
Place a dot at the tip of the current ray.
DrawRayImageScreen: PROC [context: Context, r: RayData, view: Matrix, viewport: Viewport];
Draw a rectangle to represent the ray-traced image extent.
ParametersMessage: PROC [r: RayData] RETURNS [rope: ROPE];
Produce a rope indicating the mode of ray tracing.
END.