Functions

axes(alpha) Draw xyz axes
circle(n) Draw a circle
cone(apex, dir, r, n) Draw a cone
disc(pos, dir, r, n) Draw a disc
enter_ortho(...) Enter orthographic drawing mode
leave_ortho() Leave orthographic drawing mode
pixquad(...) Draw a quad with texture coordinates in pixel mode
quad(...) Draw a quad with texture coordinates in normalized mode
viewalign() Set the current matrix to be view-aligned

Functions

axes(alpha)

The axes have unit length, identity rotation and are centered at the origin.

Parameters:

alpha The alpha (default 1)
circle(n)

Draw a circle of radius 1. The circle function only specifies the vertices, not the primitive used to actually draw the circle. circle should be wrapped in glBegin/glEnd calls.

     gl.Begin(GL.LINE_LOOP)
        sketch.circle(30)
     gl.End()
 

Parameters:

n Optional number of divisions in the circle (default 20)
cone(apex, dir, r, n)

Draw a cone with a specified radius and direction. The cone function

     -- cone at the origin pointing along the y-axis
     -- with radius 0.5 and 30 divisions
     gl.Begin(GL.TRIANGLES)
        sketch.cone({0, 0, 0}, {0, 1, 0}, 0.5, 30)
     gl.End()
 

Parameters:

apex The apex
dir The direction
r The radius
n The number of divisions (default 20)
disc(pos, dir, r, n)

Draw a disc in 3D with a specified radius and direction. The circle function could be used to achieve the same result, but it requires calculating the correct rotation and applying it with glRotate. This function explicitly calculates the vertices in 3D

     -- disc at the origin pointing along the y-axis
     -- with radius 0.5 and 30 divisions
     gl.Begin(GL.POLYGON)
        gl.Normal(0, 1, 0)
        sketch.disc({0, 0, 0}, {0, 1, 0}, 0.5, 30)
     gl.End()
 

Parameters:

pos The position
dir The direction
r The radius (default 1)
n The number of divisions (default 20)
enter_ortho(...)

Orthographic modes can be descibed as normalized, pixel, or arbitrary. The two most common are noramlized and pixel. In the sketch module, normalized is defined as a view that spans [-1, -1] x [1, 1] with [-1, -1] in the lower left corner. Pixel is defined as a view that spans [0, 0] x [w, h] with [0, 0] in the upper left corner.

     -- no arguments, uses the default (-1, -1, 2, 2) normalized mode
     -- glOrtho(-1, 1, -1, 1, -100, 100)
     enter_ortho()
     
     -- 2 arguments, sets up a pixel mode (0, 0, w, h)
     -- glOrtho(0, w, h, 0, -100, 100);
     enter_ortho(w, h)
     
     -- 4 arguments, sets an arbitrary mode (x, y, w, h)
     -- glOrtho(x, x+w, y, y+h, -100, 100)
     enter_ortho(x, y, w, h)
 

Parameters:

... Either a table or unpacked list of up to 4 values. If 2 values are given, they set the width of the orthographic drawing area with the upper left corner being (0, 0). If 4 values are given, they set the (x, y, w, h) of the orthographic view. If no values are given, the view is set to a normalized drawing area of (-1, -1, 2, 2) with a drawing area of [-1, -1] x [1, 1].
leave_ortho()

Pop the GL_MODELVIEW and GL_PROJECTION matrices set when entering orthographic drawing. The glMatrixMode will be GL_MODELVIEW after the function is called.

pixquad(...)

Draw a quad in pixel orthographic mode. Depending on the number of arguments, different parameters of the quad's position and dimension will be set:

     -- no arguments, uses (0, 0, 512, 512) for coordinates [0, 0] x [512, 512]
     quad() 
     
     -- 2 arguments, uses (0, 0, w, h) for coordinates [0, 0] x [w/2, h/2]
     -- The quad will be centered on (0, 0)
     quad(w, h) 
     
     -- 4 arguments, uses (x, y, w, h) for coordinates [x, y] x [x+w, y+h]
     quad(x, y, w, h)
 

Parameters:

... Either a table or list of up to 4 unpacked values. If 2 arguments are given, they set the width and height of the quad. If 4 arguments are given, they set the (x, y, w, h) of the quad. No arguments uses the default (0, 0, 512, 512).
quad(...)

Draw a quad in normalized orthographic mode. Depending on the number of arguments, different parameters of the quad's position and dimension will be set:

     -- no arguments, uses (-1, -1, 2, 2) for coordinates [-1, -1] x [1, 1]
     quad() 
     
     -- 2 arguments, uses (-w/2, -h/2, w, h) for coordinates [-w/2, -h/2] x [w/2, h/2]
     -- The quad will be centered on (0, 0)
     quad(w, h) 
     
     -- 4 arguments, uses (x, y, w, h) for coordinates [x, y] x [x+w, y+h]
     quad(x, y, w, h)
 

Parameters:

... Either a table or list of up to 4 unpacked values. If 2 arguments are given, they set the width and height of the quad. If 4 arguments are given, they set the (x, y, w, h) of the quad. No arguments uses the default (-1, -1, 2, 2).
viewalign()

Setting a view-aligned matrix only works when glMatrixMode is set to GL_MODELVIEW and the matrix has unit scale (i.e. no glScale functions have been called).

After this function has been called, any 3D drawing confined to the xy-plane will be orthogonal to the viewport.

View-alignment is useful when drawing sprites or 2D shapes associated with a 3D rotation frame.