Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<std::string> Object::split(std::string str, char splitter){
- char charText[1000];
- int number = 0;
- int numberOfWords = 0;
- char current[10][100];
- std::vector<std::string> tokens;
- strcpy(charText, str.c_str());
- int size = sizeof(charText) / sizeof(*charText);
- //std::cout << size << " size\n";
- for (int i = 0; i < splitter; i++){
- if (charText[i] == splitter){
- tokens.push_back(current[numberOfWords]);
- numberOfWords++;
- number = 0;
- }
- else{
- current[numberOfWords][number] = charText[i];
- number++;
- }
- }
- return tokens;
- }
- Object::Object(std::string fileName, Vector3f pos, Vector3f rot, float Size, Vector3f color){
- Position = pos;
- Rotation = rot;
- size = Size;
- colors = color;
- std::string data;
- std::ifstream file(fileName);
- std::string line;
- Vector3f _verts[1024];
- int noVerts = 0;
- unsigned int _inds[1024];
- int noIndices = 0;
- while (getline(file, line)) // same as: while (getline( myfile, line ).good())
- {
- char charText[1024];
- strcpy(charText, line.c_str());
- if (charText[0] == 'v' && charText[1] != 'n' && charText[1] != 't'){
- std::vector<std::string> splitLine = split(line, ' ');
- _verts[noVerts] = Vector3f(atoi(splitLine[1].c_str()), atoi(splitLine[2].c_str()), atoi(splitLine[3].c_str()));
- //std::cout << "Vertices Number:" << noVerts << " x:" << _verts[noVerts].getX() << " y:" << _verts[noVerts].getY() << " z:" << _verts[noVerts].getZ() << "\n";
- noVerts++;
- }
- if (charText[0] == 'f'){
- std::vector<std::string> splitLine = split(line, ' ');
- for (int i = 0; i < 3; i++){
- std::vector<std::string> ssl = split(splitLine[i+1], '/');
- //std::cout << atoi(splitLine[i].c_str()) << "\n";
- std::cout << i << ": " << atoi(ssl[0].c_str()) << " " << atoi(ssl[1].c_str()) << " " << atoi(ssl[2].c_str()) << "\n";
- _inds[noIndices] = atoi(ssl[0].c_str());
- noIndices++;
- _inds[noIndices] = atoi(ssl[1].c_str());
- noIndices++;
- _inds[noIndices] = atoi(ssl[2].c_str());
- noIndices++;
- //std::cout << "number of indices:" << noIndices<< "\n";
- }
- }
- }
- verts = _verts;
- inds = _inds;
- SizeV = sizeof(verts);
- SizeI = sizeof(inds);
- noPoints = SizeI / sizeof(*inds);
- length = SizeV / sizeof(*verts);
- Matrix4f posM, rotM, sizeM;
- sizeM.InitScaleTransform(size, size, size);
- rotM.InitRotateTransform(rot.getX(), rot.getY(), rot.getZ());
- posM.InitTranslationTransform(pos.getX(), pos.getY(), pos.getZ());
- M = posM * rotM * sizeM;
- for (unsigned int i = 0; i < length; i++){
- verts[i] = _verts[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement