Animate3d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 24, 1987 1:08:18 pm PST
DIRECTORY Controls, Imager, Matrix3d, ThreeDBasics, Vector3d;
Animate3d: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
CameraMode:  TYPE ~ {local, global};
CameraProc:  TYPE ~ PROC [control: Control, data: REF ANY];
Camera:   TYPE ~ REF CameraRec;
CameraRec:  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 HoldRec;
HoldRec:   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 ~ Animate.Viewer;
Mouse:   TYPE ~ Animate.Mouse;
Control:   TYPE ~ Animate.Control;
ControlProc:  TYPE ~ Animate.ControlProc;
ControlType:  TYPE ~ Animate.ControlType;
ControlList:  TYPE ~ Animate.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 animate 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 animate are repainted.
UpdateLocalRotates: PROC [camera: Camera, rotates: Triple];
Set the camera matrix incorporating new rotation settings; the rot animate are repainted.
UpdateOrigin: PROC [camera: Camera, origin: Triple];
Set the camera matrix incorporating new origin setting; the x, y, z animate are repainted.
UpdateMove: PROC [camera: Camera, move: Triple];
Set the camera matrix incorporating new translation setting; the Mov animate 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 animate 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 animate for position and orientation.
FocusHold: PROC [vector: Triple, hold: Hold];
Set hold.lng, hold.lat and hold.mag animate to be vector; set hold.dx, hold.dy, hold.dz to 0.0.
Miscellaneous Procedures
PaintAnimate: 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.