Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::fstream jsonData;
- Json::Value root;
- Json::Reader reader;
- jsonData.open(levelFile.c_str());
- // check for errors
- if (!reader.parse(jsonData, root))
- {
- std::cout << "Failed to parse data from: "
- << levelFile
- << reader.getFormattedErrorMessages();
- return false;
- }
- const Json::Value gameObjects = root["GameObjects"];
- v_playerCubes.resize(gameObjects.size());
- // size() tells us how large the array is
- for (int i = 0; i < gameObjects.size(); i++)
- {
- // get string
- std::cout << gameObjects[i]["name"].asString() << " loaded\n";
- float x, y, z;
- // get the position node
- const Json::Value posNode = gameObjects[i]["position"];
- x = posNode[0].asFloat(); // get float
- y = posNode[1].asFloat();
- z = posNode[2].asFloat();
- glm::vec3 pos(x, y, z);
- float ow, ox, oy, oz;
- const Json::Value orientNode = gameObjects[i]["orientation"];
- // check if the node exists
- if (orientNode.type() != Json::nullValue)
- {
- }
- else
- {
- ow = 1;
- ox = 0;
- oy = 0;
- oz = 0;
- }
- glm::quat orientation = glm::quat(ow, ox, oy, oz);
- TransformComponent* tc = new TransformComponent(pos, orientation); /// , scale);
- v_playerCubes[i].addComponent(tc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement