Esempio n. 1
0
std::string Shader::loadShader(const GLchar* shaderPath)
{
	// Load the contents of the specified file into a string
	std::ifstream inFileStream(shaderPath);
	std::string shaderCode((std::istreambuf_iterator<char>(inFileStream)),
		(std::istreambuf_iterator<char>()));
	inFileStream.close();
	return shaderCode;

}
std::vector<char> loadShaderSourceFromFile(std::string filePath)
{
    std::vector<char> fileContents;
    std::ifstream inFileStream(filePath, std::ios::binary);

    if (!inFileStream) {
        std::cout << "Failed to load " << filePath << std::endl;
        return fileContents;
    }

    inFileStream.seekg(0, std::ios::end);
    std::streampos fileLength = inFileStream.tellg();
    inFileStream.seekg(0, std::ios::beg);

    fileContents.resize(fileLength);
    inFileStream.read(fileContents.data(), fileLength);

    return fileContents;
}
Esempio n. 3
0
//------------------------------------------------------------------------------
GmatFM::GravityFileType GravityFile::GetFileType(const wxString &filename)
{
   #ifdef DEBUG_GRAVITY_FILE
   MessageInterface::ShowMessage
      (wxT("GravityFile::GetFileType() entered\n   filename = \"%s\"\n"),
       filename.c_str());
   #endif

   wxFileInputStream inFileStream(filename);
   wxTextInputStream inStream(inFileStream);
   if (!inFileStream.IsOk())
      throw GravityFileException(wxT("Cannot open gravity file \"") + filename + wxT("\""));

   wxString line;
   GmatFM::GravityFileType gft = GmatFM::GFT_UNKNOWN;

   while (!inFileStream.Eof())
   {
      line = inStream.ReadLine();

      // Make upper case, so we can check for certain keyword
      line = GmatStringUtil::ToUpper(line);

      #ifdef DEBUG_GRAVITY_FILE
      MessageInterface::ShowMessage(wxT("   => line=<%s>\n"), line.c_str());
      #endif

      // Get first non-comment line
      if (line[0] != wxT('C') && line[0] != wxT('#'))
      {
         if (line.find(wxT("POTFIELD")) != line.npos)
         {
            gft = GmatFM::GFT_COF;
            break;
         }
         else if (line.find(wxT("STK.V.")) != line.npos)
         {
            gft = GmatFM::GFT_GRV;
            break;
         }
         else
         {
            Real rval;
            if (GmatStringUtil::ToReal(line, rval))
               gft = GmatFM::GFT_DAT;

            break;
         }
      }
   }


   #ifdef DEBUG_GRAVITY_FILE
   MessageInterface::ShowMessage(wxT("GravityFile::GetFileType() returning %d\n"), gft);
   #endif

   if (gft == GmatFM::GFT_UNKNOWN)
      throw GravityFileException
         (wxT("Gravity file \"") + filename + wxT(" is of unknown format"));

   return gft;
}
Esempio n. 4
0
//------------------------------------------------------------------------------
// bool ReadCofFile(const wxString &filename, Integer& degree, Integer& order,
//                  Real &mu, Real &radius, bool readCoeff, Real cbar[][361],
//                  Real sbar[][DEG_DIM], Integer maxDegree, Integer maxOrder,
//                  Integer maxDriftDegree)
//------------------------------------------------------------------------------
bool GravityFile::ReadCofFile(const wxString &filename, Integer& degree,
                              Integer& order, Real &mu, Real &radius, bool readCoeff,
                              Real cbar[][361], Real sbar[][DEG_DIM], Integer maxDegree,
                              Integer maxOrder, Integer maxDriftDegree)
{
   wxFileInputStream inFileStream(filename);
   wxTextInputStream inStream(inFileStream);
   if (!inFileStream.IsOk())
      throw GravityFileException(wxT("Cannot open COF gravity file \"") + filename + wxT("\""));

   Integer       n = -1, m = -1;
   Integer       fileOrder = -1, fileDegree = -1;
   Real          Cnm=0.0, Snm=0.0;
   Integer       noIdea; //wth??
   Real          noClue;  //huh??
   Real          tmpMu;
   Real          tmpA;

   #ifdef DEBUG_GRAVITY_COF_FILE
   MessageInterface::ShowMessage(wxT("Entered GravityFile::ReadCofFile\n"));
   #endif

   wxString line;
   wxString firstStr;
   wxString degStr, ordStr;
   wxString nStr, mStr, cnmStr, snmStr;

   while (!inFileStream.Eof())
   {
      line = inStream.ReadLine();
      wxString lineInputStream;
      wxStringInputStream lineInputStringStream(lineInputStream);
      wxTextInputStream lineStream(lineInputStringStream);

      // ignore comment lines
      if (line[0] != wxT('C'))
      {
         firstStr = line.substr(0, 8);
         firstStr = GmatStringUtil::Trim(firstStr);

         if (firstStr == wxT("END")) break;
         if (firstStr == wxT("POTFIELD"))
         {
            degStr = line.substr(8, 3);
            ordStr = line.substr(11, 3);

            if ((GmatStringUtil::ToInteger(degStr, fileDegree)) &&
                (GmatStringUtil::ToInteger(ordStr, fileOrder)))
            {
               lineInputStream = line.substr(14);
               lineStream >> noIdea >> tmpMu >> tmpA >> noClue;
               if (tmpMu != 0.0)
                  mu = tmpMu / 1.0e09;     // -> km^3/sec^2
               if (tmpA  != 0.0)
                  radius = tmpA / GmatMathConstants::KM_TO_M;  // -> km

               // if not reading coefficients, stop after reading the mu and a
               if (!readCoeff)
                  break;
            }
            else
            {
               throw GravityFileException