charcoal/OpenGLEngine/Util.cpp

76 lines
2.1 KiB
C++
Raw Normal View History

2018-09-05 06:49:02 +00:00
#include "Util.h"
#include "stdafx.h"
2018-09-05 06:49:02 +00:00
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
2018-09-05 06:49:02 +00:00
#include "Exception.h"
std::string Util::load_file(const std::string& path)
2018-09-05 06:49:02 +00:00
{
std::ifstream input_stream;
try
{
input_stream.open(path);
}
catch (std::ios::failure& e)
2018-09-05 06:49:02 +00:00
{
throw Exception(std::string("Error Opening File: ") + e.what(), "class Util");
}
if (input_stream.is_open())
{
input_stream.seekg(0, std::ios::end);
std::size_t size = input_stream.tellg();
std::string buffer(size, ' ');
2018-09-05 06:49:02 +00:00
input_stream.seekg(std::ios::beg);
input_stream.read(&buffer[0], size);
return buffer;
}
else
{
throw Exception("Unable to access file: " + path, "class Util");
2018-09-05 06:49:02 +00:00
}
}
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;
2018-09-05 06:49:02 +00:00
}