ObjectNode* genTree(int branching, int maxDepth, int density, float scaleFactor, float seasonProb, float height,
	const mat4& initTrans, const mat4& initSkew)
{
	ObjectNode* tree = new ObjectNode(nullptr,initTrans, initSkew);

	mat4 tempRotate = rX(M_PI/2.0);
	mat4 tempTrans = distort(1.0, 0.2, 1.0);
	mat4 tempSkew = distort(1.0, 5.0, 1.0);
	mat4 tempMove = translate(0.0, -2.0, 0.0);
	tree->addChild( *new ObjectNode(	Global::treeCone, tempMove * tempTrans * tempRotate,
									tempSkew * tempRotate)	);

	tempTrans = distort(0.3, height, 0.3);
	tempMove[1][3] = height - 2.0;
	tree->addChild( *new ObjectNode(Global::treeCylinder, tempMove * tempTrans * tempRotate, tempRotate) );

	tempMove[1][3] = height * 0.6 + 0.1;
	tree->addChild( *genBranch(branching, maxDepth, density, scaleFactor, seasonProb, tempMove) );

	mat4 rotMat = rY(2.0 * M_PI/4.0);
	tempSkew = rZ(M_PI/4.0);
	for (int i = 0; i < 4; ++i) {
		tempSkew = rotMat * tempSkew;
		tree->addChild( *genBranch(branching, maxDepth, density, scaleFactor, seasonProb,
			tempMove * tempSkew, tempSkew) );
	}

	tree->addChild( *genLeafBunch(M_PI/2.0, 3.0, 0.5, density,
		translate(0.0, height, 0.0) * scale(0.7)) );

	return tree;
}
ObjectNode* genBranch(int branching, int maxDepth, int density, float scaleFactor, float seasonProb,
	const mat4& initTrans, const mat4& initSkew, int currentDepth)
{
	mat4 tempTrans = distort(0.2, 1.0, 0.2);
	mat4 tempMove = translate(0.0, 1.0, 0.0);
	mat4 tempSkew = distort(5.0, 1.0, 5.0);
	mat4 tempRotate = rX(M_PI/2.0);
	ObjectNode* branch = new ObjectNode(nullptr, initTrans, initSkew);
	branch->addChild(*new ObjectNode(	Global::treeCone, tempMove * tempTrans * tempRotate,
										tempSkew * tempRotate )		);

	if (currentDepth < maxDepth) {
		const int branchFact = branching;
		mat4 tempRotate = rZ(M_PI/6.0);
		mat4 rotMat = rY(2.0 * M_PI / branchFact);
		tempTrans = scale(scaleFactor);
		tempMove = translate(0.0, 1.5, 0.0);
		mat4 twist = rY(M_PI / branchFact) * tempMove;
		mat4 loopTemp = rotMat * tempRotate;

		for (int i = 0; i < branchFact; ++i) {
			loopTemp = rotMat * loopTemp;
			branch->addChild( *genBranch( branching, maxDepth, density, scaleFactor, seasonProb,
				twist * loopTemp * tempTrans, loopTemp, currentDepth + 1 ) );
		}
	}
	
	return branch;
}
uint32_t handleBranch(Assembler *assembler, char **tokens) {
    CondCodes cond = mnemToCondCode(&tokens[0][1]);
    uint32_t address = isalpha(tokens[1][0]) ?
                       //address starts with a char so is a label
                       getLabelAddress(assembler, tokens[1]) :
                       //else it's a numeric value
                       getValue(tokens[1]);
    uint32_t offset = calcOffset(assembler, address, true);

    return genBranch(cond, offset);
}