File: SVDraw3dImpl.mesa
Last edited by Bier on December 18, 1982 1:19 am
Author: Eric Bier on September 23, 1987 7:41:14 pm PDT
Reconstructed from memory on July 18, 1985 1:02:55 pm PDT
Contents: Some useful combinations of Imager operations
DIRECTORY
SVCoordSys, SVGraphics, Imager, ImagerPath, ImagerTransformation, SVMatrix3d, SV2d, SV3d, SVBoundBox, SVBoundSphere, SVDraw3d, SVMatrix2d, SVModelTypes, SVSceneTypes, SVVector2d, SVVector3d;
SVDraw3dImpl: CEDAR PROGRAM
IMPORTS SVCoordSys, SVGraphics, Imager, ImagerPath, ImagerTransformation, SVBoundBox, SVBoundSphere, SVMatrix3d, SVVector2d, SVVector3d
EXPORTS SVDraw3d =
BEGIN
Camera: TYPE = SVModelTypes.Camera;
Composite: TYPE = SVSceneTypes.Composite;
CoordSystem: TYPE = SVModelTypes.CoordSystem;
CSGTree: TYPE = SVSceneTypes.CSGTree;
Matrix4by4: TYPE = SV3d.Matrix4by4;
Point2d: TYPE = SV2d.Point2d;
Point3d: TYPE = SV3d.Point3d;
Primitive: TYPE = SVSceneTypes.Primitive;
SelectionClass: TYPE = SVSceneTypes.SelectionClass;
Vector3d: TYPE = SV3d.Vector3d;
Vector2d: TYPE = SV2d.Vector2d;
DrawCoordSys: PUBLIC PROC [dc: Imager.Context, csCAMERA: Matrix4by4, camera: Camera] = {
origin: Point3d;
xAxis, yAxis, zAxis: Vector3d;
length: REAL = 50.0;
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← SVVector3d.Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← SVVector3d.Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← SVVector3d.Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
xAxis ← SVVector3d.Scale[xAxis, length];
yAxis ← SVVector3d.Scale[yAxis, length];
zAxis ← SVVector3d.Scale[zAxis, length];
DrawVector[dc, xAxis, origin, camera];
SVGraphics.DrawChar[dc, 'x, camera];
DrawVector[dc, yAxis, origin, camera];
SVGraphics.DrawChar[dc, 'y, camera];
DrawVector[dc, zAxis, origin, camera];
SVGraphics.DrawChar[dc, 'z, camera];
};
alpha: REAL ← 0.25;
DrawSkitter: PUBLIC PROC [dc: Imager.Context, csCAMERA: Matrix4by4, camera: Camera] = {
OPEN SVVector3d;
origin: Point3d;
xAxis, yAxis, zAxis: Vector3d;
c, d: Point3d;
length: REAL = 50.0;
Imager.SetStrokeWidth[dc, 1.0];
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
xAxis ← Scale[xAxis, length];
yAxis ← Scale[yAxis, length];
zAxis ← Scale[zAxis, length];
DrawVector[dc, xAxis, origin, camera];
SVGraphics.DrawChar[dc, 'x, camera];
DrawVector[dc, yAxis, origin, camera];
SVGraphics.DrawChar[dc, 'y, camera];
DrawVector[dc, zAxis, origin, camera];
SVGraphics.DrawChar[dc, 'z, camera];
c ← Add[origin, Add[zAxis, Scale[yAxis, alpha]]];
d ← Add[origin, Add[zAxis, Scale[yAxis, -alpha]]];
SVGraphics.SetCPAbsolute[dc, origin, camera];
SVGraphics.DrawToAbsolute[dc, c, camera];
SVGraphics.DrawToAbsolute[dc, d, camera];
SVGraphics.DrawToAbsolute[dc, origin, camera];
};
DrawTargetCoordSys: PUBLIC PROC [dc: Imager.Context, csCAMERA: Matrix4by4, camera: Camera] = {
origin: Point3d;
xAxis, yAxis, zAxis: Vector3d;
upLeftVector, upRightVector, downRightVector, downLeftVector: Vector3d;
length: REAL = 50.0;
scalar: REAL = 0.8;
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← SVVector3d.Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← SVVector3d.Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← SVVector3d.Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
xAxis ← SVVector3d.Scale[xAxis, length];
yAxis ← SVVector3d.Scale[yAxis, length];
zAxis ← SVVector3d.Scale[zAxis, length];
DrawVector[dc, xAxis, origin, camera];
SVGraphics.DrawChar[dc, 'x, camera];
DrawVector[dc, yAxis, origin, camera];
SVGraphics.DrawChar[dc, 'y, camera];
DrawVector[dc, zAxis, origin, camera];
SVGraphics.DrawChar[dc, 'z, camera];
Now draw the landing pad (in the z = 0 plane).
upLeftVector ← SVVector3d.Sub[yAxis, xAxis];
upRightVector ← SVVector3d.Add[yAxis, xAxis];
downRightVector ← SVVector3d.Negate[upLeftVector];
downLeftVector ← SVVector3d.Negate[upRightVector];
upLeftVector ← SVVector3d.Scale[upLeftVector, scalar];
upRightVector ← SVVector3d.Scale[upRightVector, scalar];
downRightVector ← SVVector3d.Scale[downRightVector, scalar];
downLeftVector ← SVVector3d.Scale[downLeftVector, scalar];
SVGraphics.SetCPAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
};
scalar: REAL ← 4.0;
DrawAnchor: PUBLIC PROC [dc: Imager.Context, csCAMERA: Matrix4by4, camera: Camera] = {
OPEN SVVector3d, SVGraphics;
origin: Point3d;
xAxis, yAxis, zAxis: Vector3d;
plusX, minusX, plusY, minusY: Vector3d;
plusXWing, minusXWing, plusYWing, minusYWing: Vector3d;
widthX, widthY, nearStab, farStab, nearSide, downVec, bitDown, bitIn: Vector3d;
width: REAL ← 6.0*scalar;
sideAndWingF: REAL ← 7.0*scalar;
side: REAL ← 3.5*scalar;
sideAndWing: REAL ← 7.5*scalar;
down: REAL ← 8.5*scalar;
bit: REAL ← scalar;
Triangle: PROC [] = {
path: ImagerPath.Trajectory;
path ← SVGraphics.MoveToAbsolute[Add[origin, nearStab], camera];
path ← SVGraphics.LineToAbsolute[path, Add[origin, farStab], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, nearStab], downVec], camera];
Imager.MaskFillTrajectory[dc, path];
};
Rectangle: PROC [] = {
path: ImagerPath.Trajectory;
path ← SVGraphics.MoveToAbsolute[Add[origin, nearSide], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, nearSide], bitDown], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, nearStab], bitDown], camera];
path ← SVGraphics.LineToAbsolute[path, Add[origin, nearStab], camera];
Imager.MaskFillTrajectory[dc, path];
};
SquareSide: PROC [] = {
path: ImagerPath.Trajectory;
path ← SVGraphics.MoveToAbsolute[Add[origin, nearStab], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, nearStab], bitDown], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, farStab], bitDown], camera];
path ← SVGraphics.LineToAbsolute[path, Add[origin, farStab], camera];
Imager.MaskFillTrajectory[dc, path];
path ← SVGraphics.MoveToAbsolute[Add[origin, nearStab], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, nearStab], bitIn], camera];
path ← SVGraphics.LineToAbsolute[path, Add[Add[origin, farStab], bitIn], camera];
path ← SVGraphics.LineToAbsolute[path, Add[origin, farStab], camera];
Imager.MaskFillTrajectory[dc, path];
};
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← SVVector3d.Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← SVVector3d.Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← SVVector3d.Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
bitDown ← SVVector3d.Scale[zAxis, bit];
Imager.SetStrokeWidth[dc, 2.0];
Imager.SetColor[dc, Imager.black];
Imager.SetStrokeEnd[dc, square];
Imager.SetStrokeJoint[dc, round];
plusX ← Scale[xAxis, side];
minusX ← Scale[xAxis, -side];
plusY ← Scale[yAxis, side];
minusY ← Scale[yAxis, -side];
Draw the square in the middle.
nearStab ← Add[minusX, plusY]; farStab ← Add[plusX, plusY];
bitIn ← Scale[yAxis, -bit]; SquareSide[];
nearStab ← farStab; farStab ← Add[plusX, minusY];
bitIn ← Scale[xAxis, -bit]; SquareSide[];
nearStab ← farStab; farStab ← Add[minusX, minusY];
bitIn ← Scale[yAxis, bit]; SquareSide[];
nearStab ← farStab; farStab ← Add[minusX, plusY];
bitIn ← Scale[xAxis, bit]; SquareSide[];
Draw the Four Wings and the Four Stabilizers
plusXWing ← SVVector3d.Scale[xAxis, sideAndWing];
minusXWing ← SVVector3d.Scale[xAxis, -sideAndWing];
plusYWing ← SVVector3d.Scale[yAxis, sideAndWing];
minusYWing ← SVVector3d.Scale[yAxis, -sideAndWing];
downVec ← SVVector3d.Scale[zAxis, down];
widthX ← SVVector3d.Scale[xAxis, width];
widthY ← SVVector3d.Scale[yAxis, width];
nearStab ← plusXWing; farStab ← Add[plusXWing, widthX]; Triangle[];
nearSide ← plusX; Rectangle[];
nearStab ← minusXWing; farStab ← Sub[minusXWing, widthX]; Triangle[];
nearSide ← minusX; Rectangle[];
nearStab ← plusYWing; farStab ← Add[plusYWing, widthY]; Triangle[];
nearSide ← plusY; Rectangle[];
nearStab ← minusYWing; farStab ← Sub[minusYWing, widthY]; Triangle[];
nearSide ← minusY; Rectangle[];
};
DrawJack: PUBLIC PROC [dc: Imager.Context, cs: CoordSystem, camera: Camera] = {
csCAMERA: Matrix4by4 ← SVCoordSys.WRTCamera[cs, camera.coordSys];
DrawCoordSys[dc, csCAMERA, camera];
};
DrawMovee: PUBLIC PROC [dc: Imager.Context, cs: CoordSystem, camera: Camera] = {
origin: Point3d;
xAxis, yAxis, zAxis: Vector3d;
csCAMERA: Matrix4by4 ← SVCoordSys.WRTCamera[cs, camera.coordSys];
upLeftVector, upRightVector, downRightVector, downLeftVector: Vector3d;
length: REAL = 50.0;
scalar: REAL = 0.2;
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← SVVector3d.Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← SVVector3d.Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← SVVector3d.Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
xAxis ← SVVector3d.Scale[xAxis, length];
yAxis ← SVVector3d.Scale[yAxis, length];
zAxis ← SVVector3d.Scale[zAxis, length];
DrawVector[dc, xAxis, origin, camera];
SVGraphics.DrawChar[dc, 'x, camera];
DrawVector[dc, yAxis, origin, camera];
SVGraphics.DrawChar[dc, 'y, camera];
DrawVector[dc, zAxis, origin, camera];
SVGraphics.DrawChar[dc, 'z, camera];
Now draw the landing pad (in the z = 0 plane).
upLeftVector ← SVVector3d.Sub[yAxis, xAxis];
upRightVector ← SVVector3d.Add[yAxis, xAxis];
downRightVector ← SVVector3d.Negate[upLeftVector];
downLeftVector ← SVVector3d.Negate[upRightVector];
upLeftVector ← SVVector3d.Scale[upLeftVector, scalar];
upRightVector ← SVVector3d.Scale[upRightVector, scalar];
downRightVector ← SVVector3d.Scale[downRightVector, scalar];
downLeftVector ← SVVector3d.Scale[downLeftVector, scalar];
SVGraphics.SetCPAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
};
DrawPlaneSelection: PUBLIC PROC [dc: Imager.Context, cs: CoordSystem, planeNum: NAT, camera: Camera] = {
origin: Point3d;
csCAMERA: Matrix4by4 ← SVCoordSys.WRTCamera[cs, camera.coordSys];
xAxis, yAxis, zAxis: Vector3d;
tightRopeStart, tightRopeEnd: Point3d;
upLeftVector, upRightVector, downRightVector, downLeftVector: Vector3d;
length: REAL = 50.0;
SELECT planeNum FROM
1 => { -- x = 0 plane
csCAMERA ← SVMatrix3d.LocalRotateY[csCAMERA, -90];
};
2 => { -- y = 0 plane
csCAMERA ← SVMatrix3d.LocalRotateX[csCAMERA, 90];
};
3 => { -- z = 0 plane
};
ENDCASE => ERROR;
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
xAxis ← SVVector3d.Normalize[SVMatrix3d.XAxisOfMatrix[csCAMERA]];
yAxis ← SVVector3d.Normalize[SVMatrix3d.YAxisOfMatrix[csCAMERA]];
zAxis ← SVVector3d.Normalize[SVMatrix3d.ZAxisOfMatrix[csCAMERA]];
xAxis ← SVVector3d.Scale[xAxis, length];
yAxis ← SVVector3d.Scale[yAxis, length];
zAxis ← SVVector3d.Scale[zAxis, length];
Now draw the landing pad (in the z = 0 plane).
upLeftVector ← SVVector3d.Sub[yAxis, xAxis];
upRightVector ← SVVector3d.Add[yAxis, xAxis];
downRightVector ← SVVector3d.Negate[upLeftVector];
downLeftVector ← SVVector3d.Negate[upRightVector];
SVGraphics.SetCPAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downRightVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, downLeftVector], camera];
SVGraphics.DrawToAbsolute[dc, SVVector3d.Add[origin, upLeftVector], camera];
Now draw the tightrope (along the z axis).
tightRopeStart ← SVVector3d.Sub[origin, zAxis];
tightRopeEnd ← SVVector3d.Add[origin, zAxis];
SVGraphics.SetCPAbsolute[dc, tightRopeStart, camera];
SVGraphics.DrawToAbsolute[dc, tightRopeEnd, camera];
};
DrawPlane: PUBLIC PROC [dc: Imager.Context, left, right, down, up: REAL, cs: CoordSystem, camera: Camera, plane: [1..3] ← 1] = {
Draw the square bounded by left, right, down, and up (left-right = z, down-up = y) in the x = 0 plane of cs. In other words, draw the square [left, up], [right, up], [right, down], [left, down] defined in the coordinates of cs.
localCamera: Matrix4by4 ← SVCoordSys.WRTCamera[cs, camera.coordSys];
IF plane # 1 THEN ERROR; -- not implemented
SVGraphics.SetCP[dc, [0, up, left], camera, localCamera];
SVGraphics.DrawTo[dc, [0, up, right], camera, localCamera];
SVGraphics.DrawTo[dc, [0, down, right], camera, localCamera];
SVGraphics.DrawTo[dc, [0, down, left], camera, localCamera];
SVGraphics.DrawTo[dc, [0, up, left], camera, localCamera];
};
DrawVector: PUBLIC PROC [dc: Imager.Context, v: Vector3d, origin: Point3d, camera: Camera, strokeWidth: REAL ← 1.0] = {
Assumes v and origin are in camera coords.
tip: Point3d;
originOnScreen, tipOnScreen, textOnScreen: Point2d;
vProjected: Vector2d;
mag: REAL;
epsilon: REAL = 1.0e-3;
tip ← SVVector3d.Add[origin, v];
SVGraphics.SetCPAbsolute[dc, origin, camera];
SVGraphics.DrawToAbsolute[dc, tip, camera, strokeWidth];
Now set current position in case the caller wants to draw a character after this vector.
originOnScreen ← SVGraphics.DoProjection[origin, camera];
tipOnScreen ← SVGraphics.DoProjection[tip, camera];
vProjected ← SVVector2d.Sub[tipOnScreen, originOnScreen];
mag ← SVVector2d.Magnitude[vProjected];
IF mag < epsilon THEN vProjected ← [-7.0, 0.0]
ELSE vProjected ← SVVector2d.Scale[vProjected, 7.0/mag];
textOnScreen ← SVVector2d.Add[tipOnScreen, vProjected];
SVGraphics.SetCPAbsolute[dc, [textOnScreen[1], textOnScreen[2], 0.0], camera];
};
DrawLocalVector: PUBLIC PROC [dc: Imager.Context, v: Vector3d, origin: Point3d, camera: Camera, localCS: CoordSystem, strokeWidth: REAL ← 1.0] = {
Assumes v and origin are in localCS coords.
tip: Point3d;
localCamera: Matrix4by4 ← SVCoordSys.WRTCamera[localCS, camera.coordSys];
tip ← SVVector3d.Add[origin, v];
SVGraphics.SetCP[dc, origin, camera, localCamera];
SVGraphics.DrawTo[dc, tip, camera, localCamera, strokeWidth];
};
Two Dimensional Objects
Draw2dCoordSys: PUBLIC PROC [dc: Imager.Context, origin: Point2d, camera: Camera] = {
Poorly named. This function draws cross hairs. origin is in camera coordinates.
originScreen: Point2d;
big: REAL = 9999.0;
originScreen ← SVCoordSys.CameraToScreen[origin, camera.screenCS];
Imager.MaskVector[dc, [originScreen[1]-big, originScreen[2]],
[originScreen[1]+big, originScreen[2]]];
Imager.MaskVector[dc, [originScreen[1], originScreen[2] + big], [originScreen[1], originScreen[2] - big]];
};
DrawX: PUBLIC PROC [dc: Imager.Context, point: Point2d, camera: Camera] = {
Used by Draw Point to indicate a point of interest. Would be in SVDraw, except that the point is in camera coordinates.
origin: Point2d;
side: REAL ← 7.0;
origin ← SVCoordSys.CameraToScreen[point, camera.screenCS];
Imager.MaskVector[dc, [origin[1]-side, origin[2] + side], [origin[1]+side, origin[2] - side]];
Imager.MaskVector[dc, [origin[1] + side, origin[2] + side], [origin[1]-side, origin[2] - side]];
};
DrawFilledSquare: PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera, side: REAL] = {
halfSide: REAL ← side/2.0;
DoDrawFilledSquare: PROC = {
Imager.SetXY[dc, [screenPt[1], screenPt[2]] ]; -- set the current position
Imager.Move[dc];
Imager.SetColor[dc, Imager.black];
Imager.MaskRectangle[dc, [- halfSide, - halfSide, side, side]];
};
worldCamera: Matrix4by4 ← SVCoordSys.FindWorldInTermsOf[camera.coordSys];
cameraPt: Point3d ← SVMatrix3d.Update[worldPt, worldCamera];
screenPt: Point2d;
screenPt ← SVGraphics.DoProjection[cameraPt, camera];
screenPt ← SVCoordSys.CameraToScreen[screenPt, camera.screenCS];
Imager.DoSave[dc, DoDrawFilledSquare];
};
DrawEmptySquare: PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera, side: REAL] = {
halfSide: REAL ← side/2.0;
DoDrawEmptySquare: PROC = {
Imager.SetXY[dc, [screenPt[1], screenPt[2]]]; -- set the current position
Imager.Move[dc];
Imager.SetColor[dc, Imager.black];
Imager.MaskRectangle[dc, [- halfSide, - halfSide, side, side]];
Imager.SetColor[dc, Imager.white];
Imager.MaskRectangle[dc, [- halfSide+1, - halfSide+1, side-2, side-2]];
};
worldCamera: Matrix4by4 ← SVCoordSys.FindWorldInTermsOf[camera.coordSys];
cameraPt: Point3d ← SVMatrix3d.Update[worldPt, worldCamera];
screenPt: Point2d;
screenPt ← SVGraphics.DoProjection[cameraPt, camera];
screenPt ← SVCoordSys.CameraToScreen[screenPt, camera.screenCS];
Imager.DoSave[dc, DoDrawEmptySquare];
};
DrawSelectedJoint: PUBLIC PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera, selectClass: SelectionClass] = {
jointSize: REAL = 6.0;
hotJointSize: REAL = 10.0;
IF selectClass=hot THEN DrawEmptySquare[dc, worldPt, camera, hotJointSize]
ELSE IF selectClass=normal THEN DrawFilledSquare[dc, worldPt, camera, jointSize]
ELSE {DrawEmptySquare[dc, worldPt, camera, jointSize]; DrawFilledSquare[dc, worldPt, camera, 2.0]};
};
DrawCP: PUBLIC PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera] = {
DoDrawEmptySquare: PROC [dc: Imager.Context] = {
halfJointSize: REAL = 3.0;
jointSize: REAL = 6.0;
Imager.SetColor[dc, Imager.black];
Imager.MaskRectangle[dc, [-halfJointSize, -halfJointSize, jointSize, jointSize]];
Imager.SetColor[dc, Imager.white];
Imager.MaskRectangle[dc, [-halfJointSize+1, -halfJointSize+1, jointSize-2, jointSize-2]];
};
DrawPointAux[dc, worldPt, camera, DoDrawEmptySquare];
};
DrawGlow: PUBLIC PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera] = {
Draw a six pointed star-burst of outer radius R and inner radius r.
DoDrawGlow: PROC [dc: Imager.Context] = {
cos30, sin30, xr, xR, yr, yR: REAL;
r: REAL = 3.0;
R: REAL = 7.0;
cos30 ← 0.8660254;
sin30 ← 0.5;
Imager.SetColor[dc, Imager.black];
Imager.SetStrokeWidth[dc, 2.0];
Imager.MaskVector[dc, [0.0, r], [0.0, R]];
Imager.MaskVector[dc, [0.0, -r], [0.0, -R]];
xr ← cos30*r;
xR ← cos30*R;
yr ← sin30*r;
yR ← sin30*R;
Imager.MaskVector[dc, [xr, yr], [xR, yR]];
Imager.MaskVector[dc, [-xr, -yr], [-xR, -yR]];
Imager.MaskVector[dc, [-xr, yr], [-xR, yR]];
Imager.MaskVector[dc, [xr, -yr], [xR, -yR]];
};
DrawPointAux[dc, worldPt, camera, DoDrawGlow];
};
DrawProc: TYPE = PROC [dc: Imager.Context];
DrawPointAux: PROC [dc: Imager.Context, worldPt: Point3d, camera: Camera, drawProc: DrawProc] = {
DoDrawBody: PROC = {
Imager.SetXY[dc, [screenPt[1], screenPt[2]]]; -- set the current position
Imager.Move[dc];
drawProc[dc];
};
worldCamera: Matrix4by4 ← SVCoordSys.FindWorldInTermsOf[camera.coordSys];
cameraPt: Point3d ← SVMatrix3d.Update[worldPt, worldCamera];
screenPt: Point2d;
screenPt ← SVGraphics.DoProjection[cameraPt, camera];
screenPt ← SVCoordSys.CameraToScreen[screenPt, camera.screenCS];
Imager.DoSaveAll[dc, DoDrawBody];
};
DrawBoundBoxes: PUBLIC PROC [dc: Imager.Context, tree: CSGTree, camera: Camera] = {
DrawBoundBoxNode[dc, tree.son, camera];
};
DrawBoundBoxNode: PROC [dc: Imager.Context, node: REF ANY, camera: Camera] = {
IF node = NIL THEN RETURN;
WITH node SELECT FROM
composite: Composite => {
SVBoundBox.DrawBoundBox[dc, composite.boundBox, camera.screenCS];
DrawBoundBoxNode[dc, composite.leftSolid, camera];
DrawBoundBoxNode[dc, composite.rightSolid, camera];
};
prim: Primitive => {
SVBoundBox.DrawBoundBox[dc, prim.boundBox, camera.screenCS];
};
ENDCASE => ERROR;
};
DrawBoundBox: PUBLIC PROC [dc: Imager.Context, node: REF ANY, camera: Camera, xor: BOOL] = {};
DrawBoundSpheres: PUBLIC PROC [dc: Imager.Context, tree: CSGTree, camera: Camera] = {
DrawBoundSphereNode[dc, tree.son, camera];
};
DrawBoundSphereNode: PROC [dc: Imager.Context, node: REF ANY, camera: Camera] = {
IF node = NIL THEN RETURN;
WITH node SELECT FROM
composite: Composite => {
SVBoundSphere.DrawBoundSphere[dc, composite.boundSphere, camera];
DrawBoundSphereNode[dc, composite.leftSolid, camera];
DrawBoundSphereNode[dc, composite.rightSolid, camera];
};
prim: Primitive => {
SVBoundSphere.DrawBoundSphere[dc, prim.boundSphere, camera];
};
ENDCASE => ERROR;
};
DrawTransformedShape: PUBLIC PROC [dc: Imager.Context, csCAMERA: Matrix4by4, camera: Camera, path: Imager.PathProc] = {
Any two dimensional shape that can be drawn with the Imager, can be drawn as though its sheet of paper has been embedded in 3-space, rotated, scaled, and translated by csCAMERA. This procedure only works for the orthogonal projection.
DrawIt: PROC = {
DrawPath: Imager.PathProc = {
ImagerPath.Transform[path, projection, moveTo, lineTo, curveTo, conicTo, arcTo];
};
Imager.SetStrokeWidth[dc, 3.0];
Imager.MaskStroke[context: dc, path: DrawPath, closed: TRUE];
};
xAxis, yAxis: Vector3d;
origin: Point3d;
projection, localCamera, cameraScreen: ImagerTransformation.Transformation;
xAxis ← SVMatrix3d.XAxisOfMatrix[csCAMERA];
yAxis ← SVMatrix3d.YAxisOfMatrix[csCAMERA];
origin ← SVMatrix3d.OriginOfMatrix[csCAMERA];
localCamera ← ImagerTransformation.Create[xAxis[1], yAxis[1], origin[1], xAxis[2], yAxis[2], origin[2]];
cameraScreen ← CameraWRTScreen[camera];
projection ← ImagerTransformation.Concat[localCamera, cameraScreen];
Imager.DoSaveAll[dc, DrawIt];
};
CameraWRTScreen: PROC [camera: Camera] RETURNS [cameraScreen: ImagerTransformation.Transformation] = {
screenCoordSys: CoordSystem ← camera.screenCS;
screenMat: Matrix4by4 ← SVCoordSys.GetMat[screenCoordSys];
cameraScreen ← ImagerTransformation.Translate[t:
[- screenMat[1][4], - screenMat[2][4]]
];
};
END.