(* JJ3D.def - A user friendly graphical 3D universe Definition module Copyright (c) 2010, Jan Lemeire & Joris Borms Last modified: november 2010 *) DEFINITION MODULE JJ3D; (* Deze constantes definieren de 3D wereld *) CONST SCHERM_BREEDTE = 800; SCHERM_HOOGTE = 600; TEXT_HOOGTE = 180; (* hoogte van het onderste paneel waar de text in komt *) GRAPHICS2D_BREEDTE = 250; (* breedte van graphics-schermpje waarin je kan tekenen in 2D *) (* this screen is down left of the text panel. the height of the panel is therefore TEXT_HOOGTE *) CONTROL_PANEL_X0 = 20; CONTROL_PANEL_Y0 = 0; (*SCHERM_HOOGTE;*) D = 150; (* afstand en hoogte van het perspectief *) H = SCHERM_HOOGTE/2; (* initiele plaats van de observer *) VIEWER_X0 = 300; (* de observer staat een beetje naar rechts *) VIEWER_Y0 = -D; VIEWER_Z0 = H; (* Observer coordinates and viewerAngle *) VAR viewerAngle : REAL; viewerX, viewerY, viewerZ: INTEGER; (* Call this procedure first to create the 3D window *) PROCEDURE StartMy3DWorld(title: ARRAY OF CHAR); (* Call this procedure first to create the 3D window *) PROCEDURE Start3DPhysicalWorld(title: ARRAY OF CHAR); (* Call this procedure at the end to wait for the user to press 'q' *) PROCEDURE WaitUntilQPressed(); (* Call this procedure to effectively draw your 3D-figures on the screen *) PROCEDURE DrawEverything(); (* Call this to erase all figures from the scene *) PROCEDURE ClearScreen(); (* Let the program wait a while (in milliseconds *) (* Same procedure as the one from SYSTEM, but this one also draws figures on screen by calling DrawEverything() *) PROCEDURE Delay(milliseconds: CARDINAL); (*set the color of the ground (default is GRAY) *) PROCEDURE SetGroundColor(color:CARDINAL); (* show the XYZ axes of the 3D world (on by default) *) PROCEDURE ShowAxes(show: BOOLEAN); (* show a grid in the 3D world (on by default) *) PROCEDURE ShowGrid(show: BOOLEAN); (* Standard color declarations -- *) CONST BLACK = 00000000H; BRIGHTWHITE = 00FFFFFFH; LIGHTRED = 000000FFH; LIGHTGREEN = 0000FF00H; LIGHTBLUE = 00FF0000H; LIGHTCYAN = 00FFFF00H; LIGHTMAGENTA = 00FF00FFH; LIGHTYELLOW = 0000FFFFH; RED = 000000B0H; GREEN = 0000B000H; BLUE = 00B00000H; CYAN = 00808000H; MAGENTA = 00800080H; BROWN = 000060B0H; WHITE = 00C0C0C0H; GRAY = 00808080H; (* Creates a color with red, green and blue components in the range 0 to 255 -- *) PROCEDURE RgbColor( r, g, b: CARDINAL ): CARDINAL; (* Creates a new color which is percentage% lighter than the given color. If negative, a darker color is returned *) PROCEDURE Lighter( color: CARDINAL; percentage: INTEGER ): CARDINAL; (* Creates a new color which is percentage% darker than the given color. If negative, a lighter color is returned *) PROCEDURE Darker( color: CARDINAL; percentage: INTEGER ): CARDINAL; (* ------ Drawing Functions ------ *) (* draws a single point *) PROCEDURE Plot(x, y, z: INTEGER; color: INTEGER); (* draws a line *) PROCEDURE Line(x1, y1, z1, x2, y2, z2: INTEGER; kleur:INTEGER); (* draws a line with a certain thickness *) PROCEDURE ThickLine(x1, y1, z1, x2, y2, z2: INTEGER; kleur, thickness:INTEGER); (* draws an arrow pointing from (x1,y1,z1) to (x2,y2,z2) *) PROCEDURE Arrow3D(x1, y1, z1, x2, y2, z2, color, thickness, arrowSize: INTEGER); (* plots text on a point in the 3D world *) PROCEDURE PlotText(text: ARRAY OF CHAR; x, y, z: INTEGER); (* draws a rectangle along the XY plane (constant z) *) PROCEDURE RectangleXY(x0, y0, x1, y1, z, kleur:INTEGER; fill: BOOLEAN); (* draws a rectangle along the YZ plane (constant x) *) PROCEDURE RectangleYZ(y0,z0,y1,z1,x,kleur:INTEGER; fill: BOOLEAN); (* draws a rectangle along the XZ plane (constant y) *) PROCEDURE RectangleXZ(x0,z0,x1,z1,y,kleur:INTEGER; fill: BOOLEAN); (* draws a triangle *) PROCEDURE Triangle(x1, y1, z1, x2, y2, z2, x3, y3, z3: INTEGER; kleur: INTEGER; fill: BOOLEAN); (* draws a quadrangle *) PROCEDURE Quadrangle(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4: INTEGER; kleur: INTEGER; fill: BOOLEAN); (* draws a polygon connecting all the points *) PROCEDURE Polygon(x, y, z: ARRAY OF INTEGER; kleur: INTEGER; fill: BOOLEAN); (* draws a cube with centre (x0, y0, z0) and given size & color *) PROCEDURE Cube(x0, y0, z0, size, color: INTEGER; fill: BOOLEAN); (* draws a cilinder with bottom centre (x0, y0, z0) and given size & color *) PROCEDURE Cilinder(x0, y0, z0, radius, height, color: INTEGER; fill: BOOLEAN); (* draws a block from point (x0, y0, z0) to (x0+xL, y0+yL, z0+zL) and color *) PROCEDURE Block(x0, y0, z0, xL, yL, zL, color: INTEGER; fill: BOOLEAN); (* ------ Text Printing Functions (on lower panel) ------ *) PROCEDURE WrChar(c: CHAR); PROCEDURE WrStr(str: ARRAY OF CHAR); PROCEDURE WrLn(); PROCEDURE WrCard(x: CARDINAL); PROCEDURE WrInt(x: INTEGER); PROCEDURE WrReal(x: REAL; precision: CARDINAL); PROCEDURE WrBool(x: BOOLEAN); PROCEDURE ClearText(); (* ------ Input functions (same headers as topspeed's IO functions) ------ *) PROCEDURE KeyPressed() :BOOLEAN; PROCEDURE RdKey() : CARDINAL; (* gives you the code of the key *) PROCEDURE RdChar() : CHAR; (* WARNING: doesn't always give correct character for special keys... *) PROCEDURE RdBool() : BOOLEAN; (* returns true if 't' or 'T' is pressed *) (* all following input functions wait for the user to press ENTER return 0 if invalid number is entered *) PROCEDURE RdInt() : INTEGER; PROCEDURE RdCard() : CARDINAL; PROCEDURE RdReal() : REAL; PROCEDURE RdStr(VAR string: ARRAY OF CHAR); (* ------ Control Panel ------- *) PROCEDURE SetControlValue(i: CARDINAL; value: INTEGER); PROCEDURE SetControlName(i: CARDINAL; name: ARRAY OF CHAR); (* ------ 2D Drawing Functions for minimap panel ------ *) PROCEDURE DrawMinimapFromNowOn(); PROCEDURE DontDrawMinimapAnymore(); (* Use this procedure to set the area shown in the 2D panel -- By default, the bottom left corresponds to (0,0) and the top right to (GRAPHICS2D_BREEDTE, SCHERM_HOOGTE) *) PROCEDURE Set2DArea(bottomLeftX, bottomLeftY, topRightX, topRightY: INTEGER); (* Clear all drawing -- *) PROCEDURE ClearGraphics2DPanel(); (* Draws a pixel -- *) PROCEDURE SetPixel2D( x, y: INTEGER; color: CARDINAL ); (* Draws a line -- *) PROCEDURE Line2D( x0, y0, x1, y1: INTEGER; color: CARDINAL ); (* Draws a line with a certain thickness -- *) PROCEDURE ThickLine2D( x0, y0, x1, y1: INTEGER; color, thickness: CARDINAL ); (* Draws a line with an arrow at the end point, angle is in degrees -- *) PROCEDURE Arrow2D(x0, y0, angle, length: INTEGER; color, lineThickness, arrowSize: CARDINAL); (* Draws a rectangle -- *) PROCEDURE Rectangle2D( x0, y0, x1, y1: INTEGER; color: CARDINAL; fill: BOOLEAN ); (* Draws a polygon with n points -- *) PROCEDURE Polygon2D( n: CARDINAL; x, y: ARRAY OF INTEGER; color: CARDINAL; fill: BOOLEAN ); (* Draws an ellipse -- *) PROCEDURE Ellipse2D( x0, y0, x1, y1: INTEGER; color: CARDINAL; fill: BOOLEAN ); (* Draws a circle -- *) PROCEDURE Circle2D( x0, y0: INTEGER; radius: CARDINAL; color: CARDINAL ); (* Draws a filled circle -- *) PROCEDURE Disc2D( x0, y0: INTEGER; radius: CARDINAL; color: CARDINAL ); END JJ3D.