Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //uses 3 vectors to store x,y,z then combines them at the end to make the full PxVec3
- void ModelLoader::LoadVertex(std::string fileLocation)
- {
- //clears vector so it doesnt break when loading multiple models
- vertexArray.clear();
- std::ifstream file2;
- file2.open(fileLocation);
- if (!file2.is_open())
- std::cout << "Failed to load vertex data" << std::endl;
- //individual x,y,z values for the vertex arrays
- std::vector<float> x;
- std::vector<float> y;
- std::vector<float> z;
- int counter = 0;
- //grabs each line add places them into a vector to be used later
- while (!file2.eof())
- {
- if (counter == 3)
- counter = 0;
- std::string num;
- file2 >> num;
- switch (counter)
- {
- case 0:
- x.push_back(stof(num)); //converts string to float
- break;
- case 1:
- y.push_back(stof(num));
- break;
- case 2:
- z.push_back(stof(num));
- break;
- default:
- break;
- }
- counter++;
- }
- //adds x,y,z values to the vector to complete to full PxVec3
- for (int i = 0; i < x.size(); i++)
- vertexArray.push_back(PhysicsEngine::PxVec3(x[i], y[i], z[i]));
- file2.close();
- }
- //uses a char array to grab all values within the filelocation selected
- void ModelLoader::LoadTriangles(std::string fileLocation)
- {
- //clears vector so it doesnt break when loading multiple models
- triangleArray.clear();
- std::ifstream file;
- file.open(fileLocation);
- if (!file.is_open())
- std::cout << "Failed to load triangle data" << std::endl;
- //creates char array
- char* fileNumber = new char[2];
- int arrayCounter = 0;
- while (!file.eof())
- {
- //grabs next char
- char num;
- file >> num;
- //stops last char being repeated
- if (file.eof())
- break;
- if (num != ',')
- {
- fileNumber[arrayCounter] = num;
- arrayCounter++;
- }
- else
- {
- //converts the char array to an int
- int fullNumber = atoi(fileNumber);
- //adds number to triangles vector
- //std::cout << fullNumber << std::endl;
- triangleArray.push_back((PhysicsEngine::PxU32)fullNumber);
- //resets array for next number
- fileNumber = new char[2];
- arrayCounter = 0;
- }
- }
- //adds the last number to the vector
- int fullNumber = atoi(fileNumber);
- triangleArray.push_back((PhysicsEngine::PxU32)fullNumber);
- delete[] fileNumber;
- file.close();
- }
Add Comment
Please, Sign In to add comment