G3dTimeTreesDefaultsImpl.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Glassner, June 27, 1990 3:39:37 pm PDT
Bloomenthal, July 15, 1992 11:31 pm PDT
DIRECTORY G3dMatrix, G3dRender, G3dShape, Rope, G3dTimeTrees;
G3dTimeTreesDefaultsImpl: CEDAR PROGRAM
IMPORTS G3dMatrix, G3dRender, G3dTimeTrees
EXPORTS G3dTimeTrees
~ BEGIN
Types
ROPE:     TYPE ~ Rope.ROPE;
TimeTree:   TYPE ~ G3dTimeTrees.TimeTree;
TTInterpolateProc: TYPE ~ G3dTimeTrees.TTInterpolateProc;
TTReportProc:  TYPE ~ G3dTimeTrees.TTReportProc;
InterpolationType: TYPE ~ G3dTimeTrees.InterpolationType;
KeySequence:  TYPE ~ G3dTimeTrees.KeySequence;
Triple:    TYPE ~ G3dTimeTrees.Triple;
Matrix:    TYPE ~ G3dTimeTrees.Matrix;
Shape:    TYPE ~ G3dShape.Shape;
Constants
diffuseName:   ROPE = "diffuseReflectivity";
specularName:  ROPE = "specularReflectivity";
metallicityName:  ROPE = "metallicity";
shininessName:  ROPE = "shininess";
transmittanceName: ROPE = "transmittance";
colorName:   ROPE = "color";
transformName:  ROPE = "transform";
Initialization Procs
InitializeGraphicsTimeTree: PUBLIC PROC [tt: TimeTree] ~ {
-- the reals
G3dTimeTrees.RegisterKeyType[tt, diffuseName, real, ReportDiffuse];
G3dTimeTrees.RegisterKeyType[tt, specularName, real, ReportSpecular];
G3dTimeTrees.RegisterKeyType[tt, metallicityName, real, ReportMetallicity];
G3dTimeTrees.RegisterKeyType[tt, shininessName, real, ReportShininess];
G3dTimeTrees.RegisterKeyType[tt, transmittanceName, real, ReportTransmittance];
-- the triples
G3dTimeTrees.RegisterKeyType[tt, colorName, triple, ReportColor];
-- the matrices
G3dTimeTrees.SetTransformProcs[tt, ReportTransform];
};
Report Procs
ReportDiffuse: PUBLIC TTReportProc ~ {
diffuse: REF REAL ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetDiffuse[shape, diffuse­];
};
ReportSpecular: PUBLIC TTReportProc ~ {
specular: REF REAL ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetSpecular[shape, specular­];
};
ReportMetallicity: PUBLIC TTReportProc ~ {
metallicity: REF REAL ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetMetallicity[shape, metallicity­];
};
ReportShininess: PUBLIC TTReportProc ~ {
shininess: REF REAL ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetShininess[shape, shininess­];
};
ReportTransmittance: PUBLIC TTReportProc ~ {
transmittance: REF REAL ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetTransmittance[shape, transmittance­];
};
ReportColor: PUBLIC TTReportProc ~ {
color: REF Triple ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN G3dRender.SetColor[shape, [color.x, color.y, color.z]];
};
ReportTransform: PUBLIC TTReportProc ~ {
transform: Matrix ¬ NARROW[strobe];
shape: Shape ¬ NARROW[object];
IF shape # NIL THEN shape.matrix ← G3dMatrix.Mul[shape.matrix, transform];
IF shape # NIL THEN {
IF transform # NIL
THEN shape.matrix ¬ G3dMatrix.CopyMatrix[transform]
ELSE shape.matrix ¬ G3dMatrix.Identity[];
};
};
Assignment Procs
AssignDiffuse: PUBLIC PROC [tt: TimeTree, time: REAL, diffuse: REAL] ~ {
localDiffuse: REF REAL ¬ NEW[REAL ¬ diffuse];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localDiffuse, diffuseName];
};
AssignSpecular: PUBLIC PROC [tt: TimeTree, time: REAL, specular: REAL] ~ {
localSpecular: REF REAL ¬ NEW[REAL ¬ specular];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localSpecular, specularName];
};
AssignMetallicity: PUBLIC PROC [tt: TimeTree, time: REAL, metallicity: REAL] ~ {
localMetallicity: REF REAL ¬ NEW[REAL ¬ metallicity];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localMetallicity, metallicityName];
};
AssignShininess: PUBLIC PROC [tt: TimeTree, time: REAL, shininess: REAL] ~ {
localShininess: REF REAL ¬ NEW[REAL ¬ shininess];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localShininess, shininessName];
};
AssignTransmittance: PUBLIC PROC [tt: TimeTree, time: REAL, transmittance: REAL] ~ {
localTransmittance: REF REAL ¬ NEW[REAL ¬ transmittance];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localTransmittance, transmittanceName];
};
AssignColor: PUBLIC PROC [tt: TimeTree, time: REAL, color: Triple] ~ {
localColor: REF Triple ¬ NEW[Triple ¬ color];
[] ¬ G3dTimeTrees.InsertKey[tt, time, localColor, colorName];
};
AssignTransform: PUBLIC PROC [tt: TimeTree, time: REAL, transform: Matrix] ~ {
localTransform: Matrix ¬ G3dMatrix.CopyMatrix[transform];
[] ¬ G3dTimeTrees.InsertTransform[tt, time, localTransform];
};
Interpolation Procs
SetDiffuseInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, diffuseName, type];
};
SetSpecularInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, specularName, type];
};
SetMetallicityInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, metallicityName, type];
};
SetShininessInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, shininessName, type];
};
SetTransmittanceInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, transmittanceName, type];
};
SetColorInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetKeyHeadInterpType[tt, colorName, type];
};
SetTransformInterpolationType: PUBLIC PROC [tt: TimeTree, type: InterpolationType] ~ {
G3dTimeTrees.SetTransformInterpType[tt, type];
};
END.
..
Debug Stuff
Report Procs
ReportDiffuse: PUBLIC TTReportProc ~ {
diffuse: REF REAL ¬ NARROW[strobe];
RealResponse[object, diffuse­, "diffuse"];
};
ReportSpecular: PUBLIC TTReportProc ~ {
specular: REF REAL ¬ NARROW[strobe];
RealResponse[object, specular­, "specular"];
};
ReportMetallicity: PUBLIC TTReportProc ~ {
metallicity: REF REAL ¬ NARROW[strobe];
RealResponse[object, metallicity­, "metallicity"];
};
ReportShininess: PUBLIC TTReportProc ~ {
shininess: REF REAL ¬ NARROW[strobe];
RealResponse[object, shininess­, "shininess"];
};
ReportTransmittance: PUBLIC TTReportProc ~ {
transmittance: REF REAL ¬ NARROW[strobe];
RealResponse[object, transmittance­, "transmittance"];
};
ReportColor: PUBLIC TTReportProc ~ {
color: REF Triple ¬ NARROW[strobe];
TripleResponse[object, color­, "color"];
};
ReportTransform: PUBLIC TTReportProc ~ {
transform: Matrix ¬ NARROW[strobe];
MatrixResponse[object, transform, "transform"];
};
Test and Debug
DummyObject:     TYPE ~ REF DummyObjectRep;
DummyObjectRep:   TYPE ~ RECORD [
time:       REAL ¬ 1.0,
name:       ROPE ¬ "untitled",
real:       REAL ¬ 1.0,
color:       Triple ¬ [0.0, 0.0, 0.0],
transform:     Matrix ¬ NIL
];
RealResponse: PUBLIC PROC [object: REF ANY, data: REAL, dataName: ROPE] ~ {
dummy: DummyObject ¬ NARROW[object];
TerminalIO.PutRope[IO.PutFR["Object %g responding. Set value of %g to %g\n",
IO.rope[dummy.name], IO.rope[dataName], IO.real[data]]];
};
TripleResponse: PUBLIC PROC [object: REF ANY, data: Triple, dataName: ROPE] ~ {
dummy: DummyObject ¬ NARROW[object];
TerminalIO.PutRope[IO.PutFR["Object %g responding. Set value of %g to %g %g %g\n",
IO.rope[dummy.name], IO.rope[dataName], IO.real[data.x], IO.real[data.y], IO.real[data.z]]];
};
MatrixResponse: PUBLIC PROC [object: REF ANY, data: Matrix, dataName: ROPE] ~ {
PrintMatrix: PROC [m: Matrix] ~ {
FOR i: INT IN [0 .. 4) DO
TerminalIO.PutRope[IO.PutFR["[%5g %5g %5g %5g]\n",
IO.real[m[i][0]], IO.real[m[i][1]], IO.real[m[i][2]], IO.real[m[i][3]]]];
ENDLOOP;
};
dummy: DummyObject ¬ NARROW[object];
TerminalIO.PutRope[IO.PutFR["Object %g responding. Set value of %g to:\n",
IO.rope[dummy.name], IO.rope[dataName]]];
PrintMatrix[data];
};
dummyIndex: INT ¬ 0;
NewDummy: PROC RETURNS [DummyObject] ~ {
d: DummyObject ¬ NEW[DummyObjectRep ¬ []];
d.name ¬ IO.PutFR["Dummy %g", IO.int[dummyIndex]];
dummyIndex ¬ dummyIndex + 1;
RETURN[d];
};
PrintObjectName: PUBLIC PROC [ob: REF] ~ {
IF ob = NIL
THEN {
TerminalIO.PutRope["No object"];
}
ELSE {
d: DummyObject ¬ NARROW[ob];
TerminalIO.PutRope[IO.PutFR["<%g>", IO.rope[d.name]]];
};
};
TreeTestCmd: Commander.CommandProc ~ {
PlaceSet: PROC [time, v: REAL] ~ {
AssignDiffuse[tt, time, v];
AssignTransform[tt, time, G3dMatrix.MakeTranslate[[v, v, v]]];
};
tt: TimeTree ¬ G3dTimeTrees.CreateTimeTree[];
interpType: InterpolationType ¬ smooth;
IntializeGraphicsTimeTree[tt];
dummyIndex ¬ 0;
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, linear];
SetTransformInterpolationType[tt, linear];
PlaceSet[0.0, 0.0];   -- obj 0
PlaceSet[10.0, 10.0];
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, linear];
SetTransformInterpolationType[tt, linear];
PlaceSet[0.0, 10.0];   -- obj 1
PlaceSet[10.0, 20.0];
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, smooth];
AssignDiffuse[tt, 0.0, 3.0];
AssignDiffuse[tt, 10.0, 13.0];
G3dTimeTrees.PopTimeTree[tt];
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, smooth];
SetTransformInterpolationType[tt, smooth];
PlaceSet[0.0, 0.0];   -- obj 2
PlaceSet[10.0, 20.0];
G3dTimeTrees.PopTimeTree[tt];
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, smooth];
SetTransformInterpolationType[tt, smooth];
PlaceSet[0.0, -10.0];   -- obj 3
PlaceSet[10.0, 20.0];
G3dTimeTrees.PopTimeTree[tt];
G3dTimeTrees.PopTimeTree[tt];
G3dTimeTrees.PushTimeTree[tt];
[] ¬ G3dTimeTrees.SetNodeObject[tt, NewDummy[]];
SetDiffuseInterpolationType[tt, linear];
SetTransformInterpolationType[tt, linear];
PlaceSet[0.0, -20.0];   -- obj 4
PlaceSet[10.0, 0.0];
G3dTimeTrees.PopTimeTree[tt];
G3dTimeTrees.StrobeTimeTree[tt, 4.0];
};
Start Code
Commander.Register["treetest", TreeTestCmd, "treetest: test g3dTimeTrees stuff\n"];