2018-09-05 06:49:02 +00:00
|
|
|
#include "Util.h"
|
|
|
|
|
2018-10-10 21:44:15 +00:00
|
|
|
#include "deps.h"
|
2018-09-10 01:20:56 +00:00
|
|
|
|
2018-09-05 06:49:02 +00:00
|
|
|
#include <fstream>
|
2018-09-05 15:47:09 +00:00
|
|
|
#include <string>
|
2018-09-10 01:20:56 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-05 15:47:09 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
namespace charcoal
|
2018-09-05 06:49:02 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
std::string Util::load_file(const std::string& path)
|
2018-09-05 15:47:09 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
std::ifstream input_stream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
input_stream.open(path);
|
|
|
|
}
|
|
|
|
catch (std::ios::failure& e)
|
|
|
|
{
|
|
|
|
throw EXCEPTION(std::string("Error Opening File: ") + e.what());
|
|
|
|
}
|
|
|
|
if (input_stream.is_open())
|
|
|
|
{
|
|
|
|
input_stream.seekg(0, std::ios::end);
|
|
|
|
std::size_t size = input_stream.tellg();
|
|
|
|
std::string buffer(size, ' ');
|
|
|
|
input_stream.seekg(std::ios::beg);
|
|
|
|
input_stream.read(&buffer[0], size);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw EXCEPTION("Unable to access file: " + path);
|
|
|
|
}
|
2018-09-05 15:47:09 +00:00
|
|
|
}
|
2018-09-12 21:03:46 +00:00
|
|
|
|
|
|
|
void Util::set_console_position(short x, short y)
|
2018-09-05 06:49:02 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
COORD pos = { x, y };
|
|
|
|
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
SetConsoleCursorPosition(output, pos);
|
2018-09-05 15:47:09 +00:00
|
|
|
}
|
2018-09-12 21:03:46 +00:00
|
|
|
|
|
|
|
void Util::print_matrix(const mat4& matrix)
|
2018-09-05 15:47:09 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
std::cout << std::showpos << std::scientific << std::setprecision(5)
|
|
|
|
<< "[ " << matrix[0][0] << " " << matrix[1][0] << " " << matrix[2][0] << " " << matrix[3][0] << " ]" << std::endl
|
|
|
|
<< "[ " << matrix[0][1] << " " << matrix[1][1] << " " << matrix[2][1] << " " << matrix[3][1] << " ]" << std::endl
|
|
|
|
<< "[ " << matrix[0][2] << " " << matrix[1][2] << " " << matrix[2][2] << " " << matrix[3][2] << " ]" << std::endl
|
|
|
|
<< "[ " << matrix[0][3] << " " << matrix[1][3] << " " << matrix[2][3] << " " << matrix[3][3] << " ]" << std::endl;
|
2018-09-05 15:47:09 +00:00
|
|
|
}
|
2018-09-12 21:03:46 +00:00
|
|
|
|
|
|
|
void Util::print_vec(const vec2& v)
|
2018-09-05 15:47:09 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
std::cout << std::showpos << std::fixed << std::setprecision(5)
|
|
|
|
<< "[" << v.x << "]" << std::endl
|
|
|
|
<< "[" << v.y << "]" << std::endl;
|
2018-09-05 06:49:02 +00:00
|
|
|
}
|
2018-09-10 01:20:56 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void Util::print_vec(const vec3& v)
|
|
|
|
{
|
|
|
|
std::cout << std::showpos << std::fixed << std::setprecision(5)
|
|
|
|
<< "[" << v.x << "]" << std::endl
|
|
|
|
<< "[" << v.y << "]" << std::endl
|
|
|
|
<< "[" << v.z << "]" << std::endl;
|
|
|
|
}
|
2018-09-10 01:20:56 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void Util::print_vec(const vec4& v)
|
|
|
|
{
|
|
|
|
std::cout << std::showpos << std::fixed << std::setprecision(5)
|
|
|
|
<< "[" << v.x << "]" << std::endl
|
|
|
|
<< "[" << v.y << "]" << std::endl
|
|
|
|
<< "[" << v.z << "]" << std::endl
|
|
|
|
<< "[" << v.w << "]" << std::endl;
|
|
|
|
}
|
2018-09-10 15:35:02 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void Util::_check_gl_err(const char* file_name, int line)
|
|
|
|
{
|
|
|
|
GLenum gl_err = glGetError();
|
|
|
|
if (gl_err != GL_NO_ERROR)
|
|
|
|
throw Exception(("Caught OpenGL Error: " + std::string((const char*)gluErrorString(gl_err)) + " (" + std::to_string(gl_err) + ")").c_str(), file_name, line);
|
|
|
|
}
|
2018-09-05 06:49:02 +00:00
|
|
|
}
|