charcoal/OpenGLEngine/Util.cpp
elipzer f57c972be0 Working on Model-to-World Matrices
Currently, this feature breaks a bunch of stuff :(. Have to get
poseable to work with the objects.
2018-09-10 11:35:02 -04:00

83 lines
2.3 KiB
C++

#include "Util.h"
#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
#include "Exception.h"
std::string Util::load_file(const std::string& path)
{
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);
}
}
void Util::set_console_position(short x, short y)
{
COORD pos = { x, y };
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output, pos);
}
void Util::print_matrix(const mat4& matrix)
{
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;
}
void Util::print_vec(const vec2& v)
{
std::cout << std::showpos << std::fixed << std::setprecision(5)
<< "[" << v.x << "]" << std::endl
<< "[" << v.y << "]" << std::endl;
}
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;
}
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;
}
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);
}