daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //uses 3 vectors to store x,y,z then combines them at the end to make the full PxVec3
  2. void ModelLoader::LoadVertex(std::string fileLocation)
  3. {
  4.     //clears vector so it doesnt break when loading multiple models
  5.     vertexArray.clear();
  6.  
  7.     std::ifstream file2;
  8.     file2.open(fileLocation);
  9.  
  10.  
  11.     if (!file2.is_open())
  12.         std::cout << "Failed to load vertex data" << std::endl;
  13.  
  14.     //individual x,y,z values for the vertex arrays
  15.     std::vector<float> x;
  16.     std::vector<float> y;
  17.     std::vector<float> z;
  18.  
  19.     int counter = 0;
  20.  
  21.     //grabs each line add places them into a vector to be used later
  22.     while (!file2.eof())
  23.     {
  24.         if (counter == 3)
  25.             counter = 0;
  26.  
  27.         std::string num;
  28.         file2 >> num;
  29.  
  30.         switch (counter)
  31.         {
  32.         case 0:
  33.             x.push_back(stof(num));  //converts string to float
  34.             break;
  35.         case 1:
  36.             y.push_back(stof(num));
  37.             break;
  38.         case 2:
  39.             z.push_back(stof(num));
  40.             break;
  41.         default:
  42.             break;
  43.         }
  44.         counter++;
  45.     }
  46.     //adds x,y,z values to the vector to complete to full PxVec3
  47.     for (int i = 0; i < x.size(); i++)
  48.         vertexArray.push_back(PhysicsEngine::PxVec3(x[i], y[i], z[i]));
  49.  
  50.     file2.close();
  51. }
  52.  
  53. //uses a char array to grab all values within the filelocation selected
  54. void ModelLoader::LoadTriangles(std::string fileLocation)
  55. {
  56.     //clears vector so it doesnt break when loading multiple models
  57.     triangleArray.clear();
  58.  
  59.     std::ifstream file;
  60.     file.open(fileLocation);
  61.  
  62.     if (!file.is_open())
  63.         std::cout << "Failed to load triangle data" << std::endl;
  64.  
  65.  
  66.     //creates char array
  67.     char* fileNumber = new char[2];
  68.     int arrayCounter = 0;
  69.  
  70.     while (!file.eof())
  71.     {
  72.         //grabs next char
  73.         char num;
  74.         file >> num;
  75.  
  76.         //stops last char being repeated
  77.         if (file.eof())
  78.             break;
  79.  
  80.         if (num != ',')
  81.         {
  82.             fileNumber[arrayCounter] = num;
  83.             arrayCounter++;
  84.         }
  85.         else
  86.         {
  87.             //converts the char array to an int
  88.             int fullNumber = atoi(fileNumber);
  89.             //adds number to triangles vector
  90.             //std::cout << fullNumber << std::endl;
  91.             triangleArray.push_back((PhysicsEngine::PxU32)fullNumber);
  92.             //resets array for next number
  93.             fileNumber = new char[2];
  94.             arrayCounter = 0;
  95.         }
  96.  
  97.     }
  98.  
  99.     //adds the last number to the vector
  100.     int fullNumber = atoi(fileNumber);
  101.     triangleArray.push_back((PhysicsEngine::PxU32)fullNumber);
  102.  
  103.     delete[] fileNumber;
  104.     file.close();
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top