daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::fstream jsonData;
  2.  
  3.     Json::Value root;
  4.     Json::Reader reader;
  5.  
  6.     jsonData.open(levelFile.c_str());
  7.     // check for errors
  8.     if (!reader.parse(jsonData, root))
  9.     {
  10.         std::cout << "Failed to parse data from: "
  11.             << levelFile
  12.             << reader.getFormattedErrorMessages();
  13.         return false;
  14.     }
  15.  
  16.     const Json::Value gameObjects = root["GameObjects"];
  17.  
  18.  
  19.     v_playerCubes.resize(gameObjects.size());
  20.  
  21.  
  22.     // size() tells us how large the array is
  23.     for (int i = 0; i < gameObjects.size(); i++)
  24.     {
  25.         // get string
  26.         std::cout << gameObjects[i]["name"].asString() << " loaded\n";
  27.         float x, y, z;
  28.         // get the position node
  29.         const Json::Value posNode = gameObjects[i]["position"];
  30.         x = posNode[0].asFloat(); // get float
  31.         y = posNode[1].asFloat();
  32.         z = posNode[2].asFloat();
  33.         glm::vec3 pos(x, y, z);
  34.  
  35.  
  36.         float ow, ox, oy, oz;
  37.  
  38.         const Json::Value orientNode = gameObjects[i]["orientation"];
  39.         // check if the node exists
  40.         if (orientNode.type() != Json::nullValue)
  41.         {
  42.  
  43.  
  44.         }
  45.         else
  46.         {
  47.             ow = 1;
  48.             ox = 0;
  49.             oy = 0;
  50.             oz = 0;
  51.         }
  52.  
  53.         glm::quat orientation = glm::quat(ow, ox, oy, oz);
  54.        
  55.         TransformComponent* tc = new TransformComponent(pos, orientation);  /// , scale);
  56.  
  57.         v_playerCubes[i].addComponent(tc);
  58.     }
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