Axes

Axes #

Axes draws three 3D orthogonal lines which can be used as a reference point when rotating or moving an object.

Params #

NamePropTypedescription
sizenumberAxes size, each axis has the same length
bitsnumberBitmask that can be used to indicate which axis to show

Bitmask #

The bits parameter which axis to show. Even though this param is a number, it works as a Bitmask (Similar chmod’s numerical permissions in GNU/Linux). This bitmask allows different options to be chosen in a sigle parameter. p5.treegl adds the Tree object which allows easy access to all the necesary bits to mark different options. Each option is ordered as follows:

DescriptionValue in TreeBinary
Draws the X axisTree.X0000001
Draws the Y axisTree.Y0000010
Draws the Z axisTree.Z0000100
Draws the -X axisTree._X0001000
Draws the -Y axisTree._Y0010000
Draws the -Z axisTree._Z0100000
Draws labels that help identify each axisTree.LABELS1000000

Showcase #

Click and drag to move the camera arround!

code #

sketch.js
var easycam;

var size = 200;
var LABELS = true;
var bits = ['default', 'X Y Z', '-X -Y -Z', 'everything'];

var gui;

function setup() {
	createCanvas(400, 400, WEBGL);
	setAttributes('antialias', true);

	easycam = createEasyCam();
	easycam.setZoomScale(false);

	gui = createGui('Double click to close');
	gui.addGlobals('size', 'bits');
}

function draw() {
	rotateX(-0.5);
	rotateY(-0.5);

	background(255);

	let selectedBits = 0;

	switch (bits) {
		case 'X Y Z':
			selectedBits = Tree.X | Tree.Y | Tree.Z;
			break;

		case '-X -Y -Z':
			selectedBits = Tree._X | Tree._Y | Tree._Z;
			break;

		case 'everything':
			selectedBits = Tree.X | Tree.Y | Tree.Z | Tree.LABELS | Tree._X | Tree._Y | Tree._Z;
			break;

		default:
			selectedBits = Tree.X | Tree.Y | Tree.Z | Tree.LABELS;
			break;
	}

	push();
	axes({ size: size, bits: selectedBits });
	pop();
}