void Bvh::ParseFrame(const char* frameStr, char* p, BONE_ID parentFrameId) { while(p) { std::string name; char* child = _searchChildTag(p, frameStr, &name); if (child) { if (name == "Site") { name = std::string("End of ") + m_frames[parentFrameId].name; } BONE_ID frameId = _getFrameIdByName(name.c_str()); BvhFrame& frame = m_frames[frameId]; _getToken(child); // "OFFSET" frame.offset.x = _getF(child); frame.offset.y = _getF(child); frame.offset.z = -_getF(child); frame.offsetCombined = Vec3(); if (parentFrameId >= 0) { _linkFrame(parentFrameId, frameId); } CalcBoneOffsetMatrix(frameId); if ("CHANNELS" == _getToken(child)) { int nChannels = _getI(child); for (int i = 0; i < nChannels; i++) { std::string t = _getToken(child); if (t == "Xposition") { frame.posIndices.x = channels++; } else if (t == "Yposition") { frame.posIndices.y = channels++; } else if (t == "Zposition") { frame.posIndices.z = channels++; } else if (t == "Xrotation") { frame.rotIndices.x = channels++; } else if (t == "Yrotation") { frame.rotIndices.y = channels++; } else if (t == "Zrotation") { frame.rotIndices.z = channels++; } } } ParseFrame("JOINT", child, frameId); ParseFrame("End", child, frameId); } p = _leaveBrace(child); } }
/* Given should become * OperatorToken * OperatorToken * * -------------- -------------- * type: TOKEN_OPERATOR_TYPE TOKEN_OPERATOR_TYPE * symbol: '!' '!' * arity: 0 PREFIX * assoc: 0 RIGHT_TO_LEFT * precedence: 0 12 * */ void test__getToken_given_logicalNegation_then_called_table_should_give_correct_attributes(void) { OperatorToken *opPlus = (OperatorToken*)createOperatorToken("!"); getToken_ExpectAndReturn((Token *)opPlus); opPlus = (OperatorToken *)_getToken(); TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(PREFIX, RIGHT_TO_LEFT, 12, "!", opPlus); }
/* Given should become * OperatorToken * OperatorToken * * -------------- -------------- * type: TOKEN_OPERATOR_TYPE TOKEN_OPERATOR_TYPE * symbol: '^' '^' * arity: 0 INFIX * assoc: 0 LEFT_TO_RIGHT * precedence: 0 5 * */ void test__getToken_given_bitwiseXor_then_called_table_should_give_correct_attributes(void) { OperatorToken *opPlus = (OperatorToken*)createOperatorToken("^"); getToken_ExpectAndReturn((Token *)opPlus); opPlus = (OperatorToken *)_getToken(); TEST_ASSERT_EQUAL_ATTRIBUTE_OPERATOR(INFIX, LEFT_TO_RIGHT, 5, "^", opPlus); }
int getToken(){ int x; do{ prerow = row; precol = col; x = _getToken(); } while (x == singlenote || x == mulnote); return x; }
static char* _searchChildTag(char* from, const char *tag, std::string* name = nullptr) { if (*tag == '\0') { return _searchNoNameChildTag(from); } char* p = from; if (!p) return nullptr; int tagLen = strlen(tag); int depth = 0; while (p && *p) { if (*p == '#') { p = strchr(p, '\n'); if (!p) { return nullptr; } } else if (*p == '{') { depth++; } else if (*p == '}') { if (--depth < 0) { return nullptr; } } else if (depth == 0 && isalpha(*p)) { if (!strncmp(p, tag, tagLen) && !isalpha(p[tagLen])) { p += tagLen + 1; if (name) { *name = _getToken(p); } _enterBrace(p); return p; } _getToken(p); continue; } p++; } return nullptr; }
int obj_load(char *filename, entity_t *e) { if((fp = fopen(filename, "r")) == NULL) { fprintf(stderr, "Error loading file: %s\n", filename); return -1; } Vertex vertices[100]; int faces[100][3]; int nPolygons = 0; int vertex_num = 0; while((token = _getToken(fp)) != NULL_T) // NULL_T is EOF { if(token == VERTEX_T) { printf("v "); _getVertex(&vertices[vertex_num]); vertex_num++; } else if(token == VERTEX_NORM_T) { //Vertex *test; //printf("vn "); //test = _getVertex(); } else if(token == FACE_T) { printf("f "); int v1, v2, v3; _getFace(&v1, &v2, &v3); faces[nPolygons][0] = v1; faces[nPolygons][1] = v2; faces[nPolygons][2] = v3; printf("%i %i %i\n", faces[nPolygons][0], v2, v3); nPolygons++; (e->nPolygons)++; } else ; } fclose(fp); e->nPolygons = nPolygons; e->pList = (polygon_t *)malloc(nPolygons * sizeof(polygon_t)); memset(e->pList, 0x0, sizeof(polygon_t)); for(int i = 0; i < nPolygons; i++) { for(int j = 0; j < 3; j++) { e->pList[i].v[j].x = vertices[faces[i][j]-1].x; e->pList[i].v[j].y = vertices[faces[i][j]-1].y; e->pList[i].v[j].z = vertices[faces[i][j]-1].z; } } for(int i = 0; i < nPolygons; i++) { for(int j = 0; j < 3; j++) { printf("poly%i %f %f %f\n", i, e->pList[i].v[j].x,e->pList[i].v[i].y,e->pList[i].v[j].z); } } return 0; }