DIRECTORY CSG, GraphicsColor, Rope, SVBoundBox; CSGImpl: PROGRAM IMPORTS SVBoundBox EXPORTS CSG = BEGIN BoundBox: TYPE = REF BoundBoxObj; BoundBoxObj: TYPE = SVBoundBox.BoundBoxObj; Classification: TYPE = REF ClassificationObj; ClassificationObj: TYPE = CSG.ClassificationObj; Color: TYPE = GraphicsColor.Color; Primitive: TYPE = REF PrimitiveObj; PrimitiveObj: TYPE = CSG.PrimitiveObj; PointSetOp: TYPE = CSG.PointSetOp;-- {union, intersection, difference}; Composite: TYPE = REF CompositeObj; CompositeObj: TYPE = CSG.CompositeObj; CSGTree: TYPE = REF CSGTreeObj; CSGTreeObj: TYPE = CSG.CSGTreeObj; CopyClass: PUBLIC PROC [class: Classification] RETURNS [copy: Classification] = { copy _ NEW[ClassificationObj]; copy.count _ class.count; copy.params _ class.params; copy.surfaces _ class.surfaces; copy.primitives _ class.primitives; copy.classifs _ class.classifs; copy.normals _ class.normals; }; MakeCompositeCell: PUBLIC PROC [name: Rope.ROPE, operation: PointSetOp, LeftSolidPtr: REF ANY, RightSolidPtr: REF ANY] RETURNS [c: Composite] = { c _ NEW[CompositeObj _ [name, operation, LeftSolidPtr, RightSolidPtr]]; }; MakeCSGTree: PUBLIC PROC [son: REF ANY, backgroundColor: Color, shadows: BOOL] RETURNS [tree: CSGTree] = { name: Rope.ROPE; IF son = NIL THEN name _ "Empty Scene" ELSE { WITH son SELECT FROM prim: Primitive => name _ prim.name; comp: Composite => name _ comp.name; ENDCASE => ERROR; }; tree _ NEW[CSGTreeObj _ [name, son, backgroundColor, shadows]]; }; CombineBoundBoxes: PUBLIC PROC [bb1, bb2: BoundBox, op: PointSetOp] RETURNS [newBB: BoundBox] = { SELECT op FROM union => newBB _ SVBoundBox.UnionCombineBoundBoxes[bb1, bb2]; intersection => newBB _ SVBoundBox.IntersectionCombineBoundBoxes[bb1, bb2]; difference => newBB _ SVBoundBox.DifferenceCombineBoundBoxes[bb1, bb2]; ENDCASE => ERROR; }; END. ZFile: CSGImpl.mesa Last edited by Bier on July 5, 1983 5:01 pm Contents: The csg Solids Interface. Essentially maintains a database of csg trees each of which contains one or more combined primitives. Maintaining a tree involves creating primitives and adding them to trees with the csg operations, intersection, union, and difference. In my current plan, all of the instances of each surface type will refer to the same underlying csg surface expressed in the instance (unit dimensions) coordinate system. Hence, I will build these primitve shapes into the code (this more or less must be done anyway because the formulas - x^2 + y^2 = R^2; z = constant, etc. - are hard to enter symbolically in Mesa). However, for rapid rendering, I will have a line-drawing approximation to each world surface. These will involve a sweep-based representation with a finite mesh (translational sweep for blocks, rotational for cylinders and spheres). I will create one such representation for each of the primitive solid types in the same instance coordinate system in which the exact csg reps are defined. Rendering line-drawings with the sweep reps will then involve, using the same matrix transforms as are used to place the csg shapes, followed by a perspective transform and a call to 2d graphics routines. Dispatches to the appropriate one of the three procs below. Κώ– "cedar" style˜Iheadšœ™Iprocšœ+™+Lšœ’™’L˜šΟk ˜ Lšœ˜Lšœ˜Lšœ˜Lšœ ˜ —L˜šœ ˜Lšœ ˜Lšœœ˜ —L˜Lš˜˜Lšœ œœ ˜!Lšœ œ˜+Lšœœœ˜-Lšœœœ˜0Lšœœ˜"Lšœ œœ˜#Lšœœœ˜&L˜Lšœ œœ Οc%˜GL˜Lšœ œœ˜#Lšœœœ˜&L˜Lšœ œœ ˜Lšœ œœ ˜"L˜Lšœπ™πLšœΤ™ΤL˜šΟn œœœœ˜QLšœœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ#˜#Lšœ˜Lšœ˜Lšœ˜—L˜šŸœœœ œ'œœœœœ˜‘Lšœœ@˜GLšœ˜—L˜šŸ œœœœœ#œœ˜jLšœ œ˜Lšœœœ˜&šœ˜šœœ˜Lšœ$˜$Lšœ$˜$Lšœœ˜—Lšœ˜—Lšœœ5˜?Lšœ˜—L˜šŸœœœ&œ˜aLšœ;™;šœ˜Lšœ=˜=LšœK˜KLšœG˜GLšœœ˜—Lšœ˜——L˜Lšœ˜L˜L˜—…—0ˆ