ObjectNode* genLeafBunch(float rho, float radius, float prob, int numLeaves, const mat4& initTrans, const mat4& initSkew) { ObjectNode* bunch = new ObjectNode(nullptr, initTrans, initSkew); mat4 rotMat = MatMath::ID; mat4 tempTrans = translate(0.0, radius, 0.0); mat4 tempRotate = rY( randNum(0.0, 2.0 * M_PI) ) * rZ(randNum(0.0, rho) ); ObjectNode* temp = new ObjectNode(nullptr, tempRotate * tempTrans, tempRotate); temp->addChild(*genLeaf(prob)); bunch->addChild(*temp); for (int i = 1; i < numLeaves; ++i) { rotMat = rY( randNum(0.0, 2.0 * M_PI) ) * rX( randNum(0.0, M_PI/2.0) ); tempRotate = rY( randNum(0.0, 2.0 * M_PI) ) * rX( randNum(0.0, rho) ); temp = new ObjectNode(nullptr, tempRotate * tempTrans * rotMat, tempRotate * rotMat); temp->addChild(*genLeaf(prob)); bunch->addChild(*temp); } return bunch; }
NODE makenode(int op, NODE s1, NODE s2, NODE s3, int val, char *id) { NODE t; FILE *txt; t = (NODE)malloc(sizeof(struct node)); t->num_val.val = val; if (op == CASE) t->s1 = genLeaf(INTCONST, val, 0, NULL); else t->s1 = s1; t->s2 = s2; t->s3 = s3; t->name = (id != NULL) ? id : ""; // counting children t->children = 0; if (t->s1 != NULL) t->children++; if (t->s2 != NULL) t->children++; if (t->s3 != NULL) t->children++; t->op = op; switch (op) { case ADD: case MMIN: case MUL: case DIV: case AND: case OR: case NOT: case ASSIGN: if (t->s1->type == t->s2->type) t->type = t->s1->type; else { txt = fopen("outputParser.txt", "a"); printf("\nError at line %d: %s %s %s\n", line_number, print_op(t->s2->type), print_op(op), print_op(t->s1->type)); fprintf(txt, "\nError at line %d: %s %s %s\n", line_number, print_op(t->s2->type), print_op(op), print_op(t->s1->type)); fclose(txt); } break; case LES: case LEQ: case EQU: case NEQ: case GRE: case GEQ: if (t->s1->type == t->s2->type) t->type = BOOLEAN; else { txt = fopen("outputParser.txt", "a"); printf("\nError at line %d: %s %s %s\n", line_number, print_op(t->s2->type), print_op(op), print_op(t->s1->type)); fprintf(txt, "\nError at line %d: %s %s %s\n", line_number, print_op(t->s2->type), print_op(op), print_op(t->s1->type)); fclose(txt); } break; case CAST: if (is_legal_cast(t->s1->type, currentType)) t->type = currentType; } return(t); }