GIGA REFACTOR
This commit is contained in:
@@ -25,53 +25,53 @@ Renderer::~Renderer() {
|
||||
|
||||
}
|
||||
|
||||
void Renderer::updateIsometricView() {
|
||||
float isometricEased = utils::easeInOutExpo(m_IsometricShade);
|
||||
m_WorldShader->start();
|
||||
m_WorldShader->setIsometricView(isometricEased);
|
||||
m_EntityShader->start();
|
||||
m_EntityShader->setIsometricView(isometricEased);
|
||||
void Renderer::UpdateIsometricView() {
|
||||
float isometricEased = utils::EaseInOutExpo(m_IsometricShade);
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetIsometricView(isometricEased);
|
||||
m_EntityShader->Start();
|
||||
m_EntityShader->SetIsometricView(isometricEased);
|
||||
}
|
||||
|
||||
void Renderer::initShader() {
|
||||
m_WorldShader = std::make_unique<WorldShader>();
|
||||
m_WorldShader->loadShader();
|
||||
m_EntityShader = std::make_unique<EntityShader>();
|
||||
m_EntityShader->loadShader();
|
||||
setIsometricView(true);
|
||||
updateIsometricView();
|
||||
void Renderer::InitShaders() {
|
||||
m_WorldShader = std::make_unique<shader::WorldShader>();
|
||||
m_WorldShader->LoadShader();
|
||||
m_EntityShader = std::make_unique<shader::EntityShader>();
|
||||
m_EntityShader->LoadShader();
|
||||
SetIsometricView(true);
|
||||
UpdateIsometricView();
|
||||
}
|
||||
|
||||
bool Renderer::init() {
|
||||
bool Renderer::Init() {
|
||||
#ifndef ANDROID
|
||||
glbinding::Binding::initialize();
|
||||
#endif
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
initShader();
|
||||
InitShaders();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::renderVAO(const GL::VertexArray& vao) {
|
||||
m_WorldShader->start();
|
||||
vao.bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vao.getVertexCount()));
|
||||
vao.unbind();
|
||||
void Renderer::RenderVAO(const GL::VertexArray& vao) {
|
||||
m_WorldShader->Start();
|
||||
vao.Bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vao.GetVertexCount()));
|
||||
vao.Unbind();
|
||||
}
|
||||
|
||||
void Renderer::renderModel(const Model& model) {
|
||||
m_EntityShader->start();
|
||||
m_EntityShader->setModelPos(model.positon);
|
||||
model.vao->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(model.vao->getVertexCount()));
|
||||
model.vao->unbind();
|
||||
void Renderer::RenderModel(const Model& model) {
|
||||
m_EntityShader->Start();
|
||||
m_EntityShader->SetModelPos(model.positon);
|
||||
model.vao->Bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(model.vao->GetVertexCount()));
|
||||
model.vao->Unbind();
|
||||
}
|
||||
|
||||
void Renderer::updateIsometricFade() {
|
||||
static std::uint64_t lastTime = utils::getTime();
|
||||
void Renderer::UpdateIsometricFade() {
|
||||
static std::uint64_t lastTime = utils::GetTime();
|
||||
if (m_IsometricShade != static_cast<float>(m_IsometricView)) {
|
||||
float step = static_cast<float>(utils::getTime() - lastTime) / 1000.0f * m_AnimationSpeed;
|
||||
float step = static_cast<float>(utils::GetTime() - lastTime) / 1000.0f * m_AnimationSpeed;
|
||||
if (m_IsometricShade < m_IsometricView) {
|
||||
m_IsometricShade += step;
|
||||
} else {
|
||||
@@ -79,52 +79,52 @@ void Renderer::updateIsometricFade() {
|
||||
}
|
||||
m_IsometricShade = std::min(m_IsometricShade, 1.0f);
|
||||
m_IsometricShade = std::max(m_IsometricShade, 0.0f);
|
||||
updateIsometricView();
|
||||
UpdateIsometricView();
|
||||
}
|
||||
lastTime = utils::getTime();
|
||||
lastTime = utils::GetTime();
|
||||
}
|
||||
|
||||
void Renderer::prepare() {
|
||||
void Renderer::Prepare() {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(m_BackgroundColor.r, m_BackgroundColor.g, m_BackgroundColor.b, 0);
|
||||
updateIsometricFade();
|
||||
UpdateIsometricFade();
|
||||
}
|
||||
|
||||
void Renderer::resize(int width, int height) {
|
||||
m_WorldShader->start();
|
||||
m_WorldShader->setAspectRatio(static_cast<float>(width) / height);
|
||||
m_EntityShader->start();
|
||||
m_EntityShader->setAspectRatio(static_cast<float>(width) / height);
|
||||
void Renderer::Resize(int width, int height) {
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetAspectRatio(static_cast<float>(width) / height);
|
||||
m_EntityShader->Start();
|
||||
m_EntityShader->SetAspectRatio(static_cast<float>(width) / height);
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void Renderer::setZoom(float zoom) {
|
||||
m_WorldShader->start();
|
||||
m_WorldShader->setZoom(zoom);
|
||||
m_EntityShader->start();
|
||||
m_EntityShader->setZoom(zoom);
|
||||
void Renderer::SetZoom(float zoom) {
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetZoom(zoom);
|
||||
m_EntityShader->Start();
|
||||
m_EntityShader->SetZoom(zoom);
|
||||
}
|
||||
|
||||
void Renderer::setCamMovement(const glm::vec2& mov) {
|
||||
void Renderer::SetCamMovement(const glm::vec2& mov) {
|
||||
m_CamPos.x += mov.x * (1 - m_IsometricView) + (0.5 * mov.x - mov.y) * m_IsometricView;
|
||||
m_CamPos.y += -mov.y * (1 - m_IsometricView) + (-0.5 * mov.x - mov.y) * m_IsometricView;
|
||||
setCamPos(m_CamPos);
|
||||
SetCamPos(m_CamPos);
|
||||
}
|
||||
|
||||
void Renderer::setCamPos(const glm::vec2& newPos) {
|
||||
void Renderer::SetCamPos(const glm::vec2& newPos) {
|
||||
m_CamPos = newPos;
|
||||
m_WorldShader->start();
|
||||
m_WorldShader->setCamPos(newPos);
|
||||
m_EntityShader->start();
|
||||
m_EntityShader->setCamPos(newPos);
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetCamPos(newPos);
|
||||
m_EntityShader->Start();
|
||||
m_EntityShader->SetCamPos(newPos);
|
||||
}
|
||||
|
||||
void Renderer::setIsometricView(bool isometric) {
|
||||
void Renderer::SetIsometricView(bool isometric) {
|
||||
m_IsometricView = isometric;
|
||||
}
|
||||
|
||||
glm::vec2 Renderer::getCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight) {
|
||||
float isometricEased = utils::easeInOutExpo(m_IsometricShade);
|
||||
glm::vec2 Renderer::GetCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight) {
|
||||
float isometricEased = utils::EaseInOutExpo(m_IsometricShade);
|
||||
|
||||
float relativeX = (cursorPos.x / windowWidth * 2) - 1;
|
||||
float relativeY = (cursorPos.y / windowHeight * 2) - 1;
|
||||
|
||||
Reference in New Issue
Block a user