Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Renderer::initializeSOSI(QString filePath)
- {
- // Open a file from filepath
- QFile mFile(filePath);
- if (!mFile.open(QFile::ReadOnly | QFile::Text))
- {
- qDebug() << "Could not read SOSI file.";
- return;
- }
- int currentRow = 0;
- int vertexCounter = 0;
- int curveCounter = 0;
- QTextStream in(&mFile);
- std::string text;
- Vector2* subtract {nullptr};
- Vector3 divide(10000, 100, 10000);
- Vector3 color = Vector3(0.5f, 0.5f, 0.5f);
- while (!in.atEnd())
- {
- std::stringstream sStream;
- text = in.readLine().toStdString();
- sStream << text;
- std::string lineHeader;
- sStream >> lineHeader;
- currentRow++;
- if (lineHeader == ".PUNKT")
- {
- float y;
- vertexCounter = 0;
- curveCounter = mTriangles.size();
- while (true)
- {
- std::stringstream pointStream;
- text = in.readLine().toStdString();
- pointStream << text;
- lineHeader = "";
- pointStream >> lineHeader;
- currentRow++;
- if (lineHeader == "..HØYDE")
- {
- pointStream >> y;
- if ((int)y % 100 == 0)
- color = Vector3(1.0f, 0.0f, 0.0f);
- else
- color = Vector3(0.5f, 0.5f, 0.5f);
- y = y / divide.y;
- }
- else if (lineHeader == "..NØ")
- {
- text = in.readLine().toStdString();
- std::stringstream points;
- points << text;
- // Get coordinate
- float x, z;
- points >> x >> z;
- if (subtract == nullptr)
- {
- subtract = new Vector2(x, z);
- }
- x = (x - subtract->x) / divide.x;
- z = (z - subtract->y) / divide.z;
- // Add vertex to vertex array
- mVertices.push_back(Vertex(Vector3(x, y, z), color, Vector2(0, 0)));
- mTriangles.push_back(vertexCounter + curveCounter);
- mTriangles.push_back(++vertexCounter + curveCounter);
- // Points only have one line of coordinates, so we break out of the loop
- break;
- }
- }
- }
- else if (lineHeader == ".KURVE")
- {
- float y = 0;
- vertexCounter = 0;
- curveCounter = mTriangles.size();
- // End of SOSI-file has a ".SLUTT"
- while (lineHeader != ".SLUTT")
- {
- std::stringstream pointStream;
- text = in.readLine().toStdString();
- pointStream << text;
- lineHeader = "";
- pointStream >> lineHeader;
- currentRow++;
- if (lineHeader == "..HØYDE")
- {
- pointStream >> y;
- if ((int)y % 100 == 0)
- color = Vector3(1.0f, 0.0f, 0.0f);
- else
- color = Vector3(0.5f, 0.5f, 0.5f);
- y = y / divide.y;
- }
- else if (lineHeader == "..NØ")
- {
- while (true)
- {
- text = in.readLine().toStdString();
- std::stringstream points;
- points << text;
- lineHeader = "";
- points >> lineHeader;
- currentRow++;
- //First point in a curve is always separate, so a ..NØ will show up before the second curve point
- if(lineHeader == "..NØ")
- {
- continue; //Skip this loop
- }
- else if(lineHeader == ".KURVE" || lineHeader == ".SLUTT")
- {
- break; //New curve starts
- }
- // Get coordinate
- float x, z;
- x = stof(lineHeader);
- points >> z;
- if(subtract == nullptr)
- {
- subtract = new Vector2(x, z);
- }
- x = (x - subtract->x)/divide.x;
- z = (z - subtract->y)/divide.z;
- //qDebug() << x/divide << ", " << z/divide;
- // Add vertex to vertices array
- mVertices.push_back(Vertex(Vector3(x, y, z), color, Vector2(0,0)));
- mTriangles.push_back(vertexCounter + curveCounter);
- mTriangles.push_back(++vertexCounter + curveCounter);
- }
- }
- }
- }
- else
- continue;
- }
- // Buffers
- initializeBuffers();
- // Draw mode
- setDrawMode(GL_POINTS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement