Controls3d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1987 7:27:22 pm PST
DIRECTORY Controls, Imager, Matrix3d, ThreeDBasics, Vector3d;
Controls3d: CEDAR DEFINITIONS
~ BEGIN
Notes
The viewer is considered a screen, dimensioned [-1..1] in x and y.

Rotations are performed with respect to the specified origin (defaulted to [0, 0, 0]).

If the camera is in global mode the three rotations (y, x, z) are applied sequentially about the vertical, horizontal, and screen axes; these rotations are independent, each not influencing the others.

If the camera is in local mode, updating the rotations causes only the most recently adjusted rotation control to be applied to the local (current) coordinate system. Thus, the final orientation of the coordinate system is accumulated over time and can not be replicated directly from the control settings.
Type Declarations
CameraMode:  TYPE ~ {local, global};
CameraProc:  TYPE ~ PROC [control: Control, data: REF ANY];
Camera:   TYPE ~ REF CameraRep;
CameraRep:  TYPE ~ RECORD [
data:      REF ANYNIL,   -- client data
proc:      CameraProc ← NIL,  -- client proc called when camera changed
view:      Matrix ← NIL,   -- tranformed matrix by viewport
matrix:     Matrix ← NIL,   -- camera matrix
fieldOfView:    Control ← NIL,   -- field of view
zDistance:    Control ← NIL,   -- distance of eye along negative z-axis
x:       Control ← NIL,   -- x coordinate of origin
y:       Control ← NIL,   -- y coordinate of origin
z:       Control ← NIL,   -- z coordinate of origin
xGlobal:     Control ← NIL,   -- rotation about global x-axis
yGlobal:     Control ← NIL,   -- rotation about global y-axis
zGlobal:     Control ← NIL,   -- rotation about global z-axis
xLocal:     Control ← NIL,   -- rotation about local x-axis
yLocal:     Control ← NIL,   -- rotation about local y-axis
zLocal:     Control ← NIL,   -- rotation about local z-axis
xMove:     Control ← NIL,   -- x-translation
yMove:     Control ← NIL,   -- y-translation
zMove:     Control ← NIL,   -- z-translation
scale:      Control ← NIL,   -- scale about local origin
hScreen:     Control ← NIL,   -- horizontal screen translation
vScreen:     Control ← NIL,   -- vertical screen translation
lastMoused:    Control ← NIL   -- last control moused
];
ViewPort:   TYPE ~ RECORD [xo, yo: INTEGER, xs, ys: REAL];
Hold:    TYPE ~ REF HoldRep;
HoldRep:   TYPE ~ RECORD [lng, lat, mag, x, y, z: Control ← NIL];
Imported Types
Triple:   TYPE ~ Vector3d.Triple;
TripleSequence: TYPE ~ Vector3d.TripleSequence;
Pair:    TYPE ~ Vector3d.Pair;
PairSequence: TYPE ~ Vector3d.PairSequence;
Matrix:   TYPE ~ Matrix3d.Matrix;
Context:   TYPE ~ Imager.Context;
Viewer:   TYPE ~ Controls.Viewer;
Mouse:   TYPE ~ Controls.Mouse;
Control:   TYPE ~ Controls.Control;
ControlProc:  TYPE ~ Controls.ControlProc;
ControlType:  TYPE ~ Controls.ControlType;
ControlList:  TYPE ~ Controls.ControlList;
Context3d:  TYPE ~ REF ThreeDBasics.Context;
xAxis:    Triple ~ Vector3d.xAxis;
yAxis:   Triple ~ Vector3d.yAxis;
zAxis:    Triple ~ Vector3d.zAxis;
Camera Procedures
InitCamera: PROC [
origin:  Triple ← [0.0, 0.0, 0.0],
globalRotate: Triple ← [0.0, 0.0, 0.0],
localRotate: Triple ← [0.0, 0.0, 0.0],
move:   Triple ← [0.0, 0.0, 0.0],
scale:   REAL ← 1.0,
fieldOfView: REAL ← 0.0,
zDistance: REAL ← 10.0,
screenMove: Pair ← [0.0, 0.0],
proc:   CameraProc ← NIL,
data:   REF ANYNIL]
RETURNS [Camera];
Return the set of camera controls and intialize the camera matrix.
ComputeNewMatrix: PUBLIC PROC [
origin:   Triple ← [0.0, 0.0, 0.0],
rotate:    Triple ← [0.0, 0.0, 0.0],
move:    Triple ← [0.0, 0.0, 0.0],
scale:    REAL ← 0.0,
fieldOfView:  REAL ← 0.0,
zDistance:  REAL ← 0.0,
m:     Matrix ← NIL]
RETURNS [Matrix];
Compute a camera matrix, using m if non-nil.
InitContext: PROC [context: Context, camera: Camera, in: Matrix ← NIL] RETURNS [Matrix];
Clear context and return viewport concatenated with camera matrix; use in if non-nil.
UpdateCamera: PROC [camera: Camera];
Set the camera matrix based upon its control settings.
If the camera is in global mode, the entire camera matrix is recomputed from the camera
control settings; if the camera is in local mode, then only the most recently changed control
is used to modify the current transformation.
UpdateGlobalRotates: PROC [camera: Camera, rotates: Triple];
Set the camera matrix incorporating new rotation settings; the rot controls are repainted.
UpdateLocalRotates: PROC [camera: Camera, rotates: Triple];
Set the camera matrix incorporating new rotation settings; the rot controls are repainted.
UpdateOrigin: PROC [camera: Camera, origin: Triple];
Set the camera matrix incorporating new origin setting; the x, y, z controls are repainted.
UpdateMove: PROC [camera: Camera, move: Triple];
Set the camera matrix incorporating new translation setting; the Mov controls are repainted.
UpdateFieldOfView: PROC [camera: Camera, fieldOfView: REAL];
Set the camera matrix incorporating a new fov setting; the fov control is repainted.
UpdateScale: PROC [camera: Camera, scale: REAL];
Set the camera matrix incorporating a new scale setting; the scale control is repainted.
UpdateScreen: PROC [camera: Camera, screen: Pair];
Set the camera matrix incorporating new screen settings; the screen controls are repainted.
UpdateZDistance: PROC [camera: Camera, zDistance: REAL];
Set the camera matrix incorporating new eye position; the z-distance control is repainted.
GetCameraMatrix: PROC [camera: Camera] RETURNS [Matrix];
Return the camera matrix translated by hScreen and vScreen.
GetViewMatrix: PROC [camera: Camera, context: Context] RETURNS [Matrix];
Return viewport concatenated with camera matrix translated by hScreen and vScreen.
GetViewPort: PROC [context: Context] RETURNS [ViewPort];
Return viewport necessary to fit [-1..1] (in x and y) image to Imager context.
TransformByViewPort: PROC [in: Matrix, context: Context, out: Matrix ← NIL]
RETURNS [Matrix];
Transform in by the viewport; use out if non-nil.
SetContext3dView: PROC [context3d: Context3d, camera: Camera];
Set the context3d view parameters. This will not result in a view which is
completely consistent with the views obtained with camera.matrix. Stay tuned.
LastAdjustedCamera: PROC RETURNS [Camera];
Return the camera most recently adjusted.
Hold Procedures
InitHold: PROC [proc: ControlProc ← NIL, data: REF ANYNIL] RETURNS [Hold];
Return set of six controls for position and orientation.
FocusHold: PROC [vector: Triple, hold: Hold];
Set hold.lng, hold.lat and hold.mag controls to be vector; set hold.dx, hold.dy, hold.dz to 0.0.
Miscellaneous Procedures
PaintControls: PROC [c1, c2, c3, c4, c5, c6: Control ← NIL];
Repaint non-nil arguments.
ScreenPick: PROC [points: TripleSequence, pairs: PairSequence, view: Matrix, mouse: Mouse]
RETURNS [pointPicked: INTEGER];
Pairs is the projection of points onto the screen and is recomputed if mouse.state = down.
Return the index of the pair nearest the mouse coordinates.
-1 is returned if the length of pairs is less than the length of points.
END.