Replaced all internal matrix data types and functions with the GLM library equivalents.

Also changed some vectors.
This commit is contained in:
Leon Styhre 2021-08-15 19:30:31 +02:00
parent ffc9814636
commit 722468129e
81 changed files with 445 additions and 423 deletions

View file

@ -196,6 +196,10 @@ if(DEFINED libCEC_FOUND)
add_definitions(-DHAVE_LIBCEC)
endif()
# GLM library options.
add_definitions(-DGLM_FORCE_CXX14)
add_definitions(-DGLM_FORCE_XYZW_ONLY)
# For Unix systems, assign the installation prefix. If it's not explicitly set,
# we use /usr on Linux, /usr/pkg on NetBSD and /usr/local on FreeBSD and OpenBSD.
if(NOT WIN32 AND NOT APPLE)

View file

@ -83,15 +83,15 @@ void MediaViewer::update(int deltaTime)
void MediaViewer::render()
{
Transform4x4f transform = Transform4x4f::Identity();
Renderer::setMatrix(transform);
glm::mat4 trans = Renderer::getIdentity();
Renderer::setMatrix(trans);
// Render a black background below the game media.
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
if (mVideo && !mDisplayingImage) {
mVideo->render(transform);
mVideo->render(trans);
#if defined(USE_OPENGL_21)
Renderer::shaderParameters videoParameters;
@ -122,7 +122,7 @@ void MediaViewer::render()
#endif
}
else if (mImage && mImage->hasImage() && mImage->getSize() != 0) {
mImage->render(transform);
mImage->render(trans);
#if defined(USE_OPENGL_21)
if (mCurrentImageIndex == mScreenShotIndex &&

View file

@ -248,19 +248,19 @@ void SystemScreensaver::renderScreensaver()
if (mVideoScreensaver && screensaverType == "video") {
// Render a black background below the video.
Renderer::setMatrix(Transform4x4f::Identity());
Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
// Only render the video if the state requires it.
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
Transform4x4f transform = Transform4x4f::Identity();
mVideoScreensaver->render(transform);
glm::mat4 trans = Renderer::getIdentity();
mVideoScreensaver->render(trans);
}
}
else if (mImageScreensaver && screensaverType == "slideshow") {
// Render a black background below the image.
Renderer::setMatrix(Transform4x4f::Identity());
Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
@ -268,15 +268,14 @@ void SystemScreensaver::renderScreensaver()
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
if (mImageScreensaver->hasImage()) {
mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255));
Transform4x4f transform = Transform4x4f::Identity();
mImageScreensaver->render(transform);
glm::mat4 trans = Renderer::getIdentity();
mImageScreensaver->render(trans);
}
}
}
if (isScreensaverActive()) {
Renderer::setMatrix(Transform4x4f::Identity());
Renderer::setMatrix(Renderer::getIdentity());
if (Settings::getInstance()->getString("ScreensaverType") == "slideshow") {
if (mHasMediaFiles) {
#if defined(USE_OPENGL_21)

View file

@ -10,14 +10,15 @@
#define ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H
#include "animations/Animation.h"
#include "math/Misc.h"
class MoveCameraAnimation : public Animation
{
public:
MoveCameraAnimation(Transform4x4f& camera, const Vector3f& target)
MoveCameraAnimation(glm::mat4& camera, const glm::vec3& target)
: mCameraStart(camera)
, mTarget(target)
, cameraOut(camera)
, cameraPosition(camera)
{
}
@ -25,17 +26,16 @@ public:
void apply(float t) override
{
// Cubic ease out.
t -= 1;
cameraOut.translation() =
-Vector3f().lerp(-mCameraStart.translation(), mTarget, t * t * t + 1);
cameraPosition[3].x = -Math::lerp(-mCameraStart[3].x, mTarget.x, t * t * t + 1);
cameraPosition[3].y = -Math::lerp(-mCameraStart[3].y, mTarget.y, t * t * t + 1);
cameraPosition[3].z = -Math::lerp(-mCameraStart[3].z, mTarget.z, t * t * t + 1);
}
private:
Transform4x4f mCameraStart;
Vector3f mTarget;
Transform4x4f& cameraOut;
glm::mat4 mCameraStart;
glm::mat4& cameraPosition;
glm::vec3 mTarget;
};
#endif // ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H

View file

@ -115,7 +115,7 @@ GuiGameScraper::GuiGameScraper(Window* window,
void GuiGameScraper::onSizeChanged()
{
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBox.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
mGrid.setRowHeightPerc(0, 0.04f, false);
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() / mSize.y(),

View file

@ -54,7 +54,7 @@ GuiInfoPopup::GuiInfoPopup(Window* window, std::string message, int duration)
setPosition(posX, posY, 0);
mFrame->setImagePath(":/graphics/frame.svg");
mFrame->fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mFrame->fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
addChild(mFrame);
// We only initialize the actual time when we first start to render.
@ -72,10 +72,10 @@ GuiInfoPopup::~GuiInfoPopup()
delete mFrame;
}
void GuiInfoPopup::render(const Transform4x4f& /*parentTrans*/)
void GuiInfoPopup::render(const glm::mat4& /*parentTrans*/)
{
// We use Identity() as we want to render on a specific window position, not on the view.
Transform4x4f trans = getTransform() * Transform4x4f::Identity();
// We use getIdentity() as we want to render on a specific window position, not on the view.
glm::mat4 trans = getTransform() * Renderer::getIdentity();
if (mRunning && updateState()) {
// If we're still supposed to be rendering it.
Renderer::setMatrix(trans);

View file

@ -21,7 +21,7 @@ public:
GuiInfoPopup(Window* window, std::string message, int duration);
~GuiInfoPopup();
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void stop() override { mRunning = false; }
private:

View file

@ -169,13 +169,13 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
mGrid->getRowHeight(3));
mMarquee->setOrigin(0.5f, 0.5f);
Vector3f currentPos = mMarquee->getPosition();
glm::vec3 currentPos = mMarquee->getPosition();
Vector2f currentSize = mMarquee->getSize();
// Position the image in the middle of row four.
currentPos.x() = mSize.x() / 2.0f;
currentPos.y() = mGrid->getRowHeight(0) + mGrid->getRowHeight(1) + mGrid->getRowHeight(2) +
mGrid->getRowHeight(3) / 2.0f;
currentPos.x = mSize.x() / 2.0f;
currentPos.y = mGrid->getRowHeight(0) + mGrid->getRowHeight(1) + mGrid->getRowHeight(2) +
mGrid->getRowHeight(3) / 2.0f;
mMarquee->setPosition(currentPos);
}
@ -185,7 +185,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
setPosition(static_cast<float>(Renderer::getScreenWidth()) / 2.0f,
static_cast<float>(Renderer::getScreenHeight()) / 2.25f);
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
mBackground.setEdgeColor(0xEEEEEEFF);
}
@ -228,7 +228,7 @@ void GuiLaunchScreen::render()
if (mScaleUp < 1.0f)
setScale(mScaleUp);
Transform4x4f trans = Transform4x4f::Identity() * getTransform();
glm::mat4 trans = Renderer::getIdentity() * getTransform();
Renderer::setMatrix(trans);
GuiComponent::renderChildren(trans);

View file

@ -388,11 +388,11 @@ void GuiMetaDataEd::onSizeChanged()
mList->setSize(mList->getSize().x(), listHeight);
Vector2f newWindowSize = mSize;
newWindowSize.y() -= heightAdjustment;
mBackground.fitTo(newWindowSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(newWindowSize, {}, Vector2f(-32.0f, -32.0f));
// Move the buttons up as well to make the layout align correctly after the resize.
Vector3f newButtonPos = mButtons->getPosition();
newButtonPos.y() -= heightAdjustment;
glm::vec3 newButtonPos = mButtons->getPosition();
newButtonPos.y -= heightAdjustment;
mButtons->setPosition(newButtonPos);
mHeaderGrid->setRowHeightPerc(1, titleHeight / mHeaderGrid->getSize().y());

View file

@ -203,7 +203,7 @@ GuiOfflineGenerator::~GuiOfflineGenerator()
void GuiOfflineGenerator::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
// Set row heights.
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false);

View file

@ -130,7 +130,7 @@ GuiScraperMulti::~GuiScraperMulti()
void GuiScraperMulti::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false);
mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2.0f) / mSize.y(), false);

View file

@ -565,9 +565,9 @@ bool GuiScraperSearch::input(InputConfig* config, Input input)
return GuiComponent::input(config, input);
}
void GuiScraperSearch::render(const Transform4x4f& parentTrans)
void GuiScraperSearch::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
renderChildren(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x00000009, 0x00000009);

View file

@ -75,7 +75,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
std::vector<HelpPrompt> getHelpPrompts() override;
HelpStyle getHelpStyle() override;
void onSizeChanged() override;

View file

@ -396,12 +396,12 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
setAnimation(anim, 0, nullptr, false, 0);
}
void SystemView::render(const Transform4x4f& parentTrans)
void SystemView::render(const glm::mat4& parentTrans)
{
if (size() == 0)
return; // Nothing to render.
Transform4x4f trans = getTransform() * parentTrans;
glm::mat4 trans = getTransform() * parentTrans;
renderExtras(trans, INT16_MIN, INT16_MAX);
@ -449,7 +449,6 @@ void SystemView::onThemeChanged(const std::shared_ptr<ThemeData>& /*theme*/)
populate();
}
// Get the ThemeElements that make up the SystemView.
void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
{
LOG(LogDebug) << "SystemView::getViewElements()";
@ -473,18 +472,20 @@ void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
mViewNeedsReload = false;
}
// Render system carousel.
void SystemView::renderCarousel(const Transform4x4f& trans)
void SystemView::renderCarousel(const glm::mat4& trans)
{
// Background box behind logos.
Transform4x4f carouselTrans = trans;
carouselTrans.translate(Vector3f(mCarousel.pos.x(), mCarousel.pos.y(), 0.0));
carouselTrans.translate(Vector3f(mCarousel.origin.x() * mCarousel.size.x() * -1.0f,
mCarousel.origin.y() * mCarousel.size.y() * -1.0f, 0.0f));
Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y());
// Background box behind logos.
glm::mat4 carouselTrans = trans;
carouselTrans =
glm::translate(carouselTrans, glm::vec3(mCarousel.pos.x(), mCarousel.pos.y(), 0.0f));
carouselTrans = glm::translate(
carouselTrans, glm::vec3(mCarousel.origin.x() * mCarousel.size.x() * -1.0f,
mCarousel.origin.y() * mCarousel.size.y() * -1.0f, 0.0f));
glm::vec2 clipPos(carouselTrans[3].x, carouselTrans[3].y);
Renderer::pushClipRect(
Vector2i(static_cast<int>(clipPos.x()), static_cast<int>(clipPos.y())),
Vector2i(static_cast<int>(clipPos.x), static_cast<int>(clipPos.y)),
Vector2i(static_cast<int>(mCarousel.size.x()), static_cast<int>(mCarousel.size.y())));
Renderer::setMatrix(carouselTrans);
@ -575,8 +576,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
while (index >= static_cast<int>(mEntries.size()))
index -= static_cast<int>(mEntries.size());
Transform4x4f logoTrans = carouselTrans;
logoTrans.translate(Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0));
glm::mat4 logoTrans = carouselTrans;
logoTrans = glm::translate(
logoTrans, glm::vec3(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0.0f));
float distance = i - mCamOffset;
@ -600,8 +602,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
Renderer::popClipRect();
}
// Draw background extras.
void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upper)
void SystemView::renderExtras(const glm::mat4& trans, float lower, float upper)
{
int extrasCenter = static_cast<int>(mExtrasCamOffset);
@ -621,15 +622,16 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
// Only render selected system when not showing.
if (mShowing || index == mCursor) {
Transform4x4f extrasTrans = trans;
glm::mat4 extrasTrans = trans;
if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL)
extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0));
extrasTrans = glm::translate(
extrasTrans, glm::vec3((i - mExtrasCamOffset) * mSize.x(), 0.0f, 0.0f));
else
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
extrasTrans = glm::translate(
extrasTrans, glm::vec3(0.0f, (i - mExtrasCamOffset) * mSize.y(), 0.0f));
Renderer::pushClipRect(
Vector2i(static_cast<int>(extrasTrans.translation()[0]),
static_cast<int>(extrasTrans.translation()[1])),
Vector2i(static_cast<int>(extrasTrans[3].x), static_cast<int>(extrasTrans[3].y)),
Vector2i(static_cast<int>(mSize.x()), static_cast<int>(mSize.y())));
SystemViewData data = mEntries.at(index).data;
for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) {
@ -644,14 +646,13 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
Renderer::popClipRect();
}
void SystemView::renderFade(const Transform4x4f& trans)
void SystemView::renderFade(const glm::mat4& trans)
{
unsigned int fadeColor = 0x00000000 | static_cast<unsigned char>(mExtrasFadeOpacity * 255.0f);
Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), fadeColor, fadeColor);
}
// Populate the system carousel with the legacy values.
void SystemView::getDefaultElements(void)
{
// Carousel.

View file

@ -62,7 +62,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onThemeChanged(const std::shared_ptr<ThemeData>& theme);
@ -81,13 +81,17 @@ protected:
private:
void populate();
void updateGameCount();
// Get the ThemeElements that make up the SystemView.
void getViewElements(const std::shared_ptr<ThemeData>& theme);
// Populate the system carousel with the legacy values.
void getDefaultElements(void);
void getCarouselFromTheme(const ThemeData::ThemeElement* elem);
void renderCarousel(const Transform4x4f& parentTrans);
void renderExtras(const Transform4x4f& parentTrans, float lower, float upper);
void renderFade(const Transform4x4f& trans);
// Render system carousel.
void renderCarousel(const glm::mat4& parentTrans);
// Draw background extras.
void renderExtras(const glm::mat4& parentTrans, float lower, float upper);
void renderFade(const glm::mat4& trans);
SystemViewCarousel mCarousel;
TextComponent mSystemInfo;

View file

@ -66,7 +66,7 @@ ViewController::ViewController(Window* window)
, mCurrentView(nullptr)
, mPreviousView(nullptr)
, mSkipView(nullptr)
, mCamera(Transform4x4f::Identity())
, mCamera(Renderer::getIdentity())
, mSystemViewTransition(false)
, mWrappedViews(false)
, mFadeOpacity(0)
@ -234,8 +234,8 @@ void ViewController::ReloadAndGoToStart()
bool ViewController::isCameraMoving()
{
if (mCurrentView) {
if (mCamera.r3().x() - -mCurrentView->getPosition().x() != 0 ||
mCamera.r3().y() - -mCurrentView->getPosition().y() != 0)
if (mCamera[3].x - -mCurrentView->getPosition().x != 0.0f ||
mCamera[3].y - -mCurrentView->getPosition().y != 0.0f)
return true;
}
return false;
@ -245,8 +245,8 @@ void ViewController::cancelViewTransitions()
{
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
if (isCameraMoving()) {
mCamera.r3().x() = -mCurrentView->getPosition().x();
mCamera.r3().y() = -mCurrentView->getPosition().y();
mCamera[3].x = -mCurrentView->getPosition().x;
mCamera[3].y = -mCurrentView->getPosition().y;
stopAllAnimations();
}
// mSkipView is used when skipping through the gamelists in quick succession.
@ -285,8 +285,8 @@ int ViewController::getSystemId(SystemData* system)
void ViewController::restoreViewPosition()
{
if (mPreviousView) {
Vector3f restorePosition = mPreviousView->getPosition();
restorePosition.x() = mWrapPreviousPositionX;
glm::vec3 restorePosition = mPreviousView->getPosition();
restorePosition.x = mWrapPreviousPositionX;
mPreviousView->setPosition(restorePosition);
mWrapPreviousPositionX = 0;
mWrappedViews = false;
@ -320,7 +320,7 @@ void ViewController::goToSystemView(SystemData* system, bool playTransition)
auto systemList = getSystemListView();
systemList->setPosition(getSystemId(system) * static_cast<float>(Renderer::getScreenWidth()),
systemList->getPosition().y());
systemList->getPosition().y);
systemList->goToSystem(system, false);
mCurrentView = systemList;
@ -328,21 +328,21 @@ void ViewController::goToSystemView(SystemData* system, bool playTransition)
// Application startup animation.
if (applicationStartup) {
mCamera.translation() = -mCurrentView->getPosition();
mCamera = glm::translate(mCamera, -mCurrentView->getPosition());
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
mCamera.translation().y() += Renderer::getScreenHeight();
mCamera[3].y += static_cast<float>(Renderer::getScreenHeight());
else
mCamera.translation().x() -= Renderer::getScreenWidth();
mCamera[3].x -= static_cast<float>(Renderer::getScreenWidth());
updateHelpPrompts();
}
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
mCamera.translation().y() += Renderer::getScreenHeight();
mCamera[3].y += static_cast<float>(Renderer::getScreenHeight());
else
mCamera.translation().x() += Renderer::getScreenWidth();
mCamera[3].x += static_cast<float>(Renderer::getScreenWidth());
}
else {
updateHelpPrompts();
@ -444,13 +444,13 @@ void ViewController::goToGameList(SystemData* system)
if (mState.viewing == SYSTEM_SELECT) {
// Move the system list.
auto sysList = getSystemListView();
float offsetX = sysList->getPosition().x();
float offsetX = sysList->getPosition().x;
int sysId = getSystemId(system);
sysList->setPosition(sysId * static_cast<float>(Renderer::getScreenWidth()),
sysList->getPosition().y());
offsetX = sysList->getPosition().x() - offsetX;
mCamera.translation().x() -= offsetX;
sysList->getPosition().y);
offsetX = sysList->getPosition().x - offsetX;
mCamera[3].x -= offsetX;
}
// If we are wrapping around, either from the first to last system, or the other way
@ -458,30 +458,30 @@ void ViewController::goToGameList(SystemData* system)
// movements will be correct. This is accomplished by simply offsetting the X position
// with the position of the first or last system plus the screen width.
if (wrapFirstToLast) {
Vector3f currentPosition = mCurrentView->getPosition();
mWrapPreviousPositionX = currentPosition.x();
float offsetX = getGameListView(system)->getPosition().x();
glm::vec3 currentPosition = mCurrentView->getPosition();
mWrapPreviousPositionX = currentPosition.x;
float offsetX = getGameListView(system)->getPosition().x;
// This is needed to move the camera in the correct direction if there are only two systems.
if (SystemData::sSystemVector.size() == 2 && mNextSystem)
offsetX -= Renderer::getScreenWidth();
else
offsetX += Renderer::getScreenWidth();
currentPosition.x() = offsetX;
currentPosition.x = offsetX;
mCurrentView->setPosition(currentPosition);
mCamera.translation().x() -= offsetX;
mCamera[3].x -= offsetX;
mWrappedViews = true;
}
else if (wrapLastToFirst) {
Vector3f currentPosition = mCurrentView->getPosition();
mWrapPreviousPositionX = currentPosition.x();
float offsetX = getGameListView(system)->getPosition().x();
glm::vec3 currentPosition = mCurrentView->getPosition();
mWrapPreviousPositionX = currentPosition.x;
float offsetX = getGameListView(system)->getPosition().x;
if (SystemData::sSystemVector.size() == 2 && !mNextSystem)
offsetX += Renderer::getScreenWidth();
else
offsetX -= Renderer::getScreenWidth();
currentPosition.x() = offsetX;
currentPosition.x = offsetX;
mCurrentView->setPosition(currentPosition);
mCamera.translation().x() = -offsetX;
mCamera[3].x = -offsetX;
mWrappedViews = true;
}
@ -489,13 +489,13 @@ void ViewController::goToGameList(SystemData* system)
// Application startup animation, if starting in a gamelist rather than in the system view.
if (mState.viewing == NOTHING) {
mCamera.translation() = -mCurrentView->getPosition();
mCamera = glm::translate(mCamera, -mCurrentView->getPosition());
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
mCamera.translation().y() -= Renderer::getScreenHeight();
mCamera[3].y -= static_cast<float>(Renderer::getScreenHeight());
updateHelpPrompts();
}
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
mCamera.translation().y() += Renderer::getScreenHeight() * 2;
mCamera[3].y += static_cast<float>(Renderer::getScreenHeight() * 2);
}
else {
updateHelpPrompts();
@ -528,13 +528,13 @@ void ViewController::playViewTransition(bool instant)
{
mCancelledTransition = false;
Vector3f target(Vector3f::Zero());
glm::vec3 target {};
if (mCurrentView)
target = mCurrentView->getPosition();
// No need to animate, we're not going anywhere (probably due to goToNextGamelist()
// or goToPrevGamelist() being called when there's only 1 system).
if (target == -mCamera.translation() && !isAnimationPlaying(0))
if (target == static_cast<glm::vec3>(-mCamera[3]) && !isAnimationPlaying(0))
return;
std::string transition_style = Settings::getInstance()->getString("TransitionStyle");
@ -542,7 +542,9 @@ void ViewController::playViewTransition(bool instant)
if (instant || transition_style == "instant") {
setAnimation(new LambdaAnimation(
[this, target](float /*t*/) {
this->mCamera.translation() = -target;
this->mCamera[3].x = -target.x;
this->mCamera[3].y = -target.y;
this->mCamera[3].z = -target.z;
if (mPreviousView)
mPreviousView->onHide();
},
@ -571,14 +573,16 @@ void ViewController::playViewTransition(bool instant)
const static int FADE_WAIT = 200; // Time to wait between in/out.
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0,
[this, fadeFunc, fadeCallback, target] {
this->mCamera.translation() = -target;
this->mCamera[3].x = -target.x;
this->mCamera[3].y = -target.y;
this->mCamera[3].z = -target.z;
updateHelpPrompts();
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), FADE_WAIT,
fadeCallback, true);
});
// Fast-forward animation if we're partway faded.
if (target == -mCamera.translation()) {
if (target == static_cast<glm::vec3>(-mCamera[3])) {
// Not changing screens, so cancel the first half entirely.
advanceAnimation(0, FADE_DURATION);
advanceAnimation(0, FADE_WAIT);
@ -848,16 +852,17 @@ void ViewController::update(int deltaTime)
}
}
void ViewController::render(const Transform4x4f& parentTrans)
void ViewController::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = mCamera * parentTrans;
Transform4x4f transInverse;
transInverse.invert(trans);
glm::mat4 trans = mCamera * parentTrans;
glm::mat4 transInverse;
transInverse = glm::inverse(trans);
// Camera position, position + size.
Vector3f viewStart = transInverse.translation();
Vector3f viewEnd = transInverse * Vector3f(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight(), 0));
glm::vec3 viewStart = transInverse[3];
glm::vec3 viewEnd = { std::fabs(trans[3].x) + static_cast<float>(Renderer::getScreenWidth()),
std::fabs(trans[3].y) + static_cast<float>(Renderer::getScreenHeight()),
0.0f };
// Keep track of UI mode changes.
UIModeController::getInstance()->monitorUIMode();
@ -872,12 +877,13 @@ void ViewController::render(const Transform4x4f& parentTrans)
// Same thing as for the system view, limit the rendering only to what needs to be drawn.
if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) {
// Clipping.
Vector3f guiStart = it->second->getPosition();
Vector3f guiEnd = it->second->getPosition() +
Vector3f(it->second->getSize().x(), it->second->getSize().y(), 0);
glm::vec3 guiStart = it->second->getPosition();
glm::vec3 guiEnd =
it->second->getPosition() +
glm::vec3(it->second->getSize().x(), it->second->getSize().y(), 0.0f);
if (guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() &&
guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y())
if (guiEnd.x >= viewStart.x && guiEnd.y >= viewStart.y && guiStart.x <= viewEnd.x &&
guiStart.y <= viewEnd.y)
it->second->render(trans);
}
}
@ -1000,7 +1006,7 @@ void ViewController::reloadAll()
SystemData* system = mState.getSystem();
mSystemListView->goToSystem(system, false);
mCurrentView = mSystemListView;
mCamera.r3().x() = 0;
mCamera[3].x = 0.0f;
}
else {
goToSystemView(SystemData::sSystemVector.front(), false);

View file

@ -78,7 +78,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
enum ViewMode {
NOTHING, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
@ -152,7 +152,7 @@ private:
FileData* mGameToLaunch;
State mState;
Transform4x4f mCamera;
glm::mat4 mCamera;
bool mSystemViewTransition;
bool mWrappedViews;
float mWrapPreviousPositionX;

View file

@ -45,7 +45,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
{
const float padding = 0.01f;
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y());
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y);
mList.setSize(mSize.x() * (0.50f - padding), mList.getSize().y());
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); });
@ -69,7 +69,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
// Image.
mImage.setOrigin(0.5f, 0.5f);
mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y() + mSize.y() * 0.2125f);
mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y + mSize.y() * 0.2125f);
mImage.setMaxSize(mSize.x() * (0.50f - 2 * padding), mSize.y() * 0.4f);
mImage.setDefaultZIndex(30);
addChild(&mImage);
@ -110,7 +110,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40);
addChild(&mDescContainer);
@ -172,7 +172,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0)
if (mGamelistInfo.getPosition() == glm::vec3 {})
mGamelistInfo.setVisible(false);
else
mGamelistInfo.setVisible(true);
@ -187,21 +187,21 @@ void DetailedGameListView::initMDLabels()
const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
glm::vec3 start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
const float colSize = (mSize.x() * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y();
for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f);
glm::vec3 pos {};
if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0);
pos = start + glm::vec3(colSize * (i / rowCount), 0.0f, 0.0f);
}
else {
// Work from the last component.
GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0);
pos = lc->getPosition() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f);
}
components[i]->setFont(Font::get(FONT_SIZE_SMALL));
@ -231,19 +231,19 @@ void DetailedGameListView::initMDValues()
for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0));
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f));
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y());
values[i]->setDefaultZIndex(40.0f);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y();
float testBot = values[i]->getPosition().y + values[i]->getSize().y();
if (testBot > bottom)
bottom = testBot;
}
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f);
mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y() * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
}
void DetailedGameListView::updateInfoPanel()

View file

@ -90,7 +90,7 @@ GridGameListView::GridGameListView(Window* window, FileData* root)
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40);
addChild(&mDescContainer);
@ -277,7 +277,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0)
if (mGamelistInfo.getPosition() == glm::vec3 {})
mGamelistInfo.setVisible(false);
else
mGamelistInfo.setVisible(true);
@ -298,21 +298,21 @@ void GridGameListView::initMDLabels()
const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
glm::vec3 start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
const float colSize = (mSize.x() * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y();
for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f);
glm::vec3 pos {};
if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0);
pos = start + glm::vec3(colSize * (i / rowCount), 0.0f, 0.0f);
}
else {
// Work from the last component.
GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0);
pos = lc->getPosition() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f);
}
components[i]->setFont(Font::get(FONT_SIZE_SMALL));
@ -342,18 +342,18 @@ void GridGameListView::initMDValues()
for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0));
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f));
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y());
values[i]->setDefaultZIndex(40);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y();
float testBot = values[i]->getPosition().y + values[i]->getSize().y();
if (testBot > bottom)
bottom = testBot;
}
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f);
mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y() * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
}
void GridGameListView::updateInfoPanel()

View file

@ -60,15 +60,15 @@ HelpStyle IGameListView::getHelpStyle()
return style;
}
void IGameListView::render(const Transform4x4f& parentTrans)
void IGameListView::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
float scaleX = trans.r0().x();
float scaleY = trans.r1().y();
float scaleX = trans[0].x;
float scaleY = trans[1].y;
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])),
static_cast<int>(std::round(trans.translation()[1])));
Vector2i pos(static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans[3].y)));
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)),
static_cast<int>(std::round(mSize.y() * scaleY)));

View file

@ -54,7 +54,7 @@ public:
virtual HelpStyle getHelpStyle() override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
protected:
FileData* mRoot;

View file

@ -64,7 +64,7 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root)
mVideo = new VideoFFmpegComponent(window);
#endif
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y());
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y);
mList.setSize(mSize.x() * (0.50f - padding), mList.getSize().y());
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); });
@ -127,7 +127,7 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root)
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40);
addChild(&mDescContainer);
@ -194,7 +194,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0)
if (mGamelistInfo.getPosition() == glm::vec3 {})
mGamelistInfo.setVisible(false);
else
mGamelistInfo.setVisible(true);
@ -209,21 +209,21 @@ void VideoGameListView::initMDLabels()
const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
glm::vec3 start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f);
const float colSize = (mSize.x() * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y();
for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f);
glm::vec3 pos {};
if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0);
pos = start + glm::vec3(colSize * (i / rowCount), 0.0f, 0.0f);
}
else {
// Work from the last component.
GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0);
pos = lc->getPosition() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f);
}
components[i]->setFont(Font::get(FONT_SIZE_SMALL));
@ -253,19 +253,19 @@ void VideoGameListView::initMDValues()
for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0));
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f));
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y());
values[i]->setDefaultZIndex(40);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y();
float testBot = values[i]->getPosition().y + values[i]->getSize().y();
if (testBot > bottom)
bottom = testBot;
}
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f);
mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y() * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(),
mSize.y() - mDescContainer.getPosition().y());
mSize.y() - mDescContainer.getPosition().y);
}
void VideoGameListView::updateInfoPanel()

View file

@ -24,11 +24,11 @@ GuiComponent::GuiComponent(Window* window)
, mColorShiftEnd(0)
, mOpacity(255)
, mSaturation(1.0f)
, mPosition(Vector3f::Zero())
, mPosition({})
, mOrigin(Vector2f::Zero())
, mRotationOrigin(0.5f, 0.5f)
, mSize(Vector2f::Zero())
, mTransform(Transform4x4f::Identity())
, mTransform(Renderer::getIdentity())
, mIsProcessing(false)
, mVisible(true)
, mEnabled(true)
@ -78,16 +78,16 @@ void GuiComponent::update(int deltaTime)
updateChildren(deltaTime);
}
void GuiComponent::render(const Transform4x4f& parentTrans)
void GuiComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
renderChildren(trans);
}
void GuiComponent::renderChildren(const Transform4x4f& transform) const
void GuiComponent::renderChildren(const glm::mat4& transform) const
{
for (unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->render(transform);
@ -95,7 +95,7 @@ void GuiComponent::renderChildren(const Transform4x4f& transform) const
void GuiComponent::setPosition(float x, float y, float z)
{
mPosition = Vector3f(x, y, z);
mPosition = glm::vec3(x, y, z);
onPositionChanged();
}
@ -113,8 +113,8 @@ void GuiComponent::setSize(float w, float h)
Vector2f GuiComponent::getCenter() const
{
return Vector2f(mPosition.x() - (getSize().x() * mOrigin.x()) + getSize().x() / 2.0f,
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2.0f);
return Vector2f(mPosition.x - (getSize().x() * mOrigin.x()) + getSize().x() / 2.0f,
mPosition.y - (getSize().y() * mOrigin.y()) + getSize().y() / 2.0f);
}
void GuiComponent::addChild(GuiComponent* cmp)
@ -171,13 +171,13 @@ void GuiComponent::setOpacity(unsigned char opacity)
(*it)->setOpacity(opacity);
}
const Transform4x4f& GuiComponent::getTransform()
const glm::mat4& GuiComponent::getTransform()
{
mTransform = Transform4x4f::Identity();
mTransform.translate(mPosition);
mTransform = Renderer::getIdentity();
mTransform = glm::translate(mTransform, mPosition);
if (mScale != 1.0f)
mTransform.scale(mScale);
mTransform = glm::scale(mTransform, glm::vec3(mScale));
if (mRotation != 0.0f) {
// Calculate offset as difference between origin and rotation origin.
@ -187,17 +187,18 @@ const Transform4x4f& GuiComponent::getTransform()
// Transform to offset point.
if (xOff != 0.0f || yOff != 0.0f)
mTransform.translate(Vector3f(xOff * -1.0f, yOff * -1.0f, 0.0f));
mTransform = glm::translate(mTransform, glm::vec3(xOff * -1.0f, yOff * -1.0f, 0.0f));
// Apply rotation transform.
mTransform.rotateZ(mRotation);
mTransform = glm::rotate(mTransform, mRotation, glm::vec3(0.0f, 0.0f, 1.0f));
// Transform back to original point.
if (xOff != 0.0f || yOff != 0.0f)
mTransform.translate(Vector3f(xOff, yOff, 0.0f));
mTransform = glm::translate(mTransform, glm::vec3(xOff, yOff, 0.0f));
}
mTransform.translate(
Vector3f(mOrigin.x() * mSize.x() * -1.0f, mOrigin.y() * mSize.y() * -1.0f, 0.0f));
mTransform = glm::translate(mTransform, glm::vec3(mOrigin.x() * mSize.x() * -1.0f,
mOrigin.y() * mSize.y() * -1.0f, 0.0f));
return mTransform;
}
@ -312,7 +313,7 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
using namespace ThemeFlags;
if (properties & POSITION && elem->has("pos")) {
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
setPosition(glm::vec3(denormalized.x(), denormalized.y(), 0.0f));
}
if (properties & ThemeFlags::SIZE && elem->has("size"))

View file

@ -14,7 +14,6 @@
#include "InputConfig.h"
#include "animations/AnimationController.h"
#include "math/Misc.h"
#include "math/Transform4x4f.h"
#include <functional>
#include <memory>
@ -45,8 +44,8 @@ public:
virtual void textInput(const std::string& text);
// Called when input is received.
// Return true if the input is consumed, false if
// it should continue to be passed to other children.
// Return true if the input is consumed, false if it should continue to be passed
// to other children.
virtual bool input(InputConfig* config, Input input);
// Called when time passes.
@ -56,18 +55,19 @@ public:
virtual void update(int deltaTime);
// Called when it's time to render.
// By default, just calls renderChildren(parentTrans * getTransform()).
// You probably want to override this like so:
// 1. Calculate the new transform that your control will draw at with
// Transform4x4f t = parentTrans * getTransform().
// By default, just calls renderChildren(parentTrans * getTransform())
// Normally the following steps are required:
// 1. Calculate the new transform that your component will draw at
// glm::mat4 trans = parentTrans * getTransform();
// 2. Set the renderer to use that new transform as the model matrix
// Renderer::setMatrix(t);
// 3. Draw your component.
// 4. Tell your children to render, based on your component's transform - renderChildren(t).
virtual void render(const Transform4x4f& parentTrans);
// Renderer::setMatrix(trans);
// 3. Draw your component
// 4. Tell your children to render, based on your component's transform
// renderChildren(trans);
virtual void render(const glm::mat4& parentTrans);
Vector3f getPosition() const { return mPosition; }
void setPosition(const Vector3f& offset) { setPosition(offset.x(), offset.y(), offset.z()); }
glm::vec3 getPosition() const { return mPosition; }
void setPosition(const glm::vec3& offset) { setPosition(offset.x, offset.y, offset.z); }
void setPosition(float x, float y, float z = 0.0f);
virtual void onPositionChanged() {}
@ -98,7 +98,7 @@ public:
void setRotation(float rotation) { mRotation = rotation; }
void setRotationDegrees(float rotation)
{
setRotation(static_cast<float>(ES_DEG_TO_RAD(rotation)));
setRotation(static_cast<float>(glm::radians(rotation)));
}
float getScale() const { return mScale; }
@ -183,7 +183,7 @@ public:
virtual std::shared_ptr<Font> getFont() const { return nullptr; }
const Transform4x4f& getTransform();
const glm::mat4& getTransform();
virtual std::string getValue() const { return ""; }
virtual void setValue(const std::string& value) {}
@ -231,7 +231,7 @@ public:
const static unsigned char MAX_ANIMATIONS = 4;
protected:
void renderChildren(const Transform4x4f& transform) const;
void renderChildren(const glm::mat4& transform) const;
void updateSelf(int deltaTime); // Updates animations.
void updateChildren(int deltaTime); // Updates animations.
@ -249,7 +249,7 @@ protected:
GuiComponent* mParent;
std::vector<GuiComponent*> mChildren;
Vector3f mPosition;
glm::vec3 mPosition;
Vector2f mOrigin;
Vector2f mRotationOrigin;
Vector2f mSize;
@ -265,8 +265,8 @@ protected:
bool mEnabled;
private:
// Don't access this directly! Use getTransform()!
Transform4x4f mTransform;
// Don't access this directly, instead use getTransform().
glm::mat4 mTransform;
AnimationController* mAnimationMap[MAX_ANIMATIONS];
};

View file

@ -18,6 +18,7 @@
#include "InputManager.h"
#include "Log.h"
#include "Sound.h"
#include "math/Misc.h"
#include "resources/Font.h"
#include <algorithm>
@ -348,7 +349,7 @@ void Window::update(int deltaTime)
void Window::render()
{
Transform4x4f transform = Transform4x4f::Identity();
glm::mat4 trans = Renderer::getIdentity();
mRenderedHelpPrompts = false;
@ -378,7 +379,7 @@ void Window::render()
renderBottom = false;
if (renderBottom)
bottom->render(transform);
bottom->render(trans);
if (bottom != top || mRenderLaunchScreen) {
#if defined(USE_OPENGL_21)
@ -468,7 +469,7 @@ void Window::render()
}
#endif // USE_OPENGL_21
mBackgroundOverlay->render(transform);
mBackgroundOverlay->render(trans);
// Scale-up menu opening effect.
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") {
@ -482,7 +483,7 @@ void Window::render()
}
if (!mRenderLaunchScreen)
top->render(transform);
top->render(trans);
}
else {
mCachedBackground = false;
@ -493,7 +494,7 @@ void Window::render()
// Render the quick list scrolling overlay, which is triggered in IList.
if (mListScrollOpacity != 0) {
Renderer::setMatrix(Transform4x4f::Identity());
Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()),
0x00000000 | mListScrollOpacity, 0x00000000 | mListScrollOpacity);
@ -509,7 +510,7 @@ void Window::render()
}
if (!mRenderedHelpPrompts)
mHelp->render(transform);
mHelp->render(trans);
unsigned int screensaverTimer =
static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer"));
@ -531,7 +532,7 @@ void Window::render()
renderScreensaver();
if (!mRenderScreensaver && mInfoPopup)
mInfoPopup->render(transform);
mInfoPopup->render(trans);
if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) {
if (!isProcessing() && mAllowSleep && (!mScreensaver)) {
@ -550,14 +551,14 @@ void Window::render()
mLaunchScreen->render();
if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) {
Renderer::setMatrix(Transform4x4f::Identity());
Renderer::setMatrix(Renderer::getIdentity());
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
}
}
void Window::renderLoadingScreen(std::string text)
{
Transform4x4f trans = Transform4x4f::Identity();
glm::mat4 trans = Renderer::getIdentity();
Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
@ -574,7 +575,7 @@ void Window::renderLoadingScreen(std::string text)
float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f);
float y = std::round(Renderer::getScreenHeight() * 0.835f);
trans = trans.translate(Vector3f(x, y, 0.0f));
trans = glm::translate(trans, glm::vec3(x, y, 0.0f));
Renderer::setMatrix(trans);
font->renderTextCache(cache);
delete cache;
@ -590,7 +591,7 @@ void Window::renderListScrollOverlay(unsigned char opacity, const std::string& t
void Window::renderHelpPromptsEarly()
{
mHelp->render(Transform4x4f::Identity());
mHelp->render(Renderer::getIdentity());
mRenderedHelpPrompts = true;
}

View file

@ -26,7 +26,6 @@ class HelpComponent;
class ImageComponent;
class InputConfig;
class TextCache;
class Transform4x4f;
struct HelpStyle;
class Window
@ -77,7 +76,7 @@ public:
class InfoPopup
{
public:
virtual void render(const Transform4x4f& parentTrans) = 0;
virtual void render(const glm::mat4& parentTrans) = 0;
virtual void stop() = 0;
virtual ~InfoPopup() {}
};

View file

@ -86,7 +86,7 @@ void AnimatedImageComponent::update(int deltaTime)
}
}
void AnimatedImageComponent::render(const Transform4x4f& trans)
void AnimatedImageComponent::render(const glm::mat4& trans)
{
if (mFrames.size())
mFrames.at(mCurrentFrame).first->render(getTransform() * trans);

View file

@ -34,7 +34,7 @@ public:
void reset(); // Set to frame 0.
void update(int deltaTime) override;
void render(const Transform4x4f& trans) override;
void render(const glm::mat4& trans) override;
void onSizeChanged() override;

View file

@ -32,7 +32,7 @@ ButtonComponent::ButtonComponent(Window* window,
void ButtonComponent::onSizeChanged()
{
// Fit to mBox.
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBox.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
}
bool ButtonComponent::input(InputConfig* config, Input input)
@ -93,21 +93,21 @@ void ButtonComponent::updateImage()
mBox.setImagePath(mFocused ? ":/graphics/button_filled.svg" : ":/graphics/button.svg");
}
void ButtonComponent::render(const Transform4x4f& parentTrans)
void ButtonComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
mBox.render(trans);
if (mTextCache) {
Vector3f centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2.0f,
(mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0);
trans = trans.translate(centerOffset);
glm::vec3 centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2.0f,
(mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0.0f);
trans = glm::translate(trans, centerOffset);
if (Settings::getInstance()->getBool("DebugText")) {
Renderer::drawRect(centerOffset.x(), 0.0f, mTextCache->metrics.size.x(), mSize.y(),
Renderer::drawRect(centerOffset.x, 0.0f, mTextCache->metrics.size.x(), mSize.y(),
0x00000033, 0x00000033);
Renderer::drawRect(mBox.getPosition().x(), 0.0f, mBox.getSize().x(), mSize.y(),
Renderer::drawRect(mBox.getPosition().x, 0.0f, mBox.getSize().x(), mSize.y(),
0x0000FF33, 0x0000FF33);
}
@ -115,7 +115,7 @@ void ButtonComponent::render(const Transform4x4f& parentTrans)
mTextCache->setColor(getCurTextColor());
mFont->renderTextCache(mTextCache.get());
trans = trans.translate(-centerOffset);
trans = glm::translate(trans, -centerOffset);
}
renderChildren(trans);

View file

@ -26,7 +26,7 @@ public:
void setEnabled(bool state) override;
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void setText(const std::string& text, const std::string& helpText);

View file

@ -141,17 +141,16 @@ void ComponentGrid::updateCellComponent(const GridEntry& cell)
if (cell.resize)
cell.component->setSize(size);
// Position.
// Find top left corner.
Vector3f pos(0, 0, 0);
glm::vec3 pos {};
for (int x = 0; x < cell.pos.x(); x++)
pos[0] += getColWidth(x);
for (int y = 0; y < cell.pos.y(); y++)
pos[1] += getRowHeight(y);
// Center component.
pos[0] = pos.x() + (size.x() - cell.component->getSize().x()) / 2;
pos[1] = pos.y() + (size.y() - cell.component->getSize().y()) / 2;
pos[0] = pos.x + (size.x() - cell.component->getSize().x()) / 2.0f;
pos[1] = pos.y + (size.y() - cell.component->getSize().y()) / 2.0f;
cell.component->setPosition(pos);
}
@ -360,9 +359,9 @@ void ComponentGrid::update(int deltaTime)
}
}
void ComponentGrid::render(const Transform4x4f& parentTrans)
void ComponentGrid::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
renderChildren(trans);

View file

@ -50,7 +50,7 @@ public:
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override;
void resetCursor();

View file

@ -167,23 +167,25 @@ void ComponentList::updateCameraOffset()
}
}
void ComponentList::render(const Transform4x4f& parentTrans)
void ComponentList::render(const glm::mat4& parentTrans)
{
if (!size())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
// Clip everything to be inside our bounds.
Vector3f dim(mSize.x(), mSize.y(), 0.0f);
dim = trans * dim - trans.translation();
glm::vec3 dim(mSize.x(), mSize.y(), 0.0f);
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
Renderer::pushClipRect(
Vector2i(static_cast<int>(std::round(trans.translation().x())),
static_cast<int>(std::round(trans.translation().y()))),
Vector2i(static_cast<int>(std::round(dim.x())), static_cast<int>(std::round(dim.y()))));
Vector2i(static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans[3].y))),
Vector2i(static_cast<int>(std::round(dim.x)), static_cast<int>(std::round(dim.y))));
// Scroll the camera.
trans.translate(Vector3f(0.0f, -std::round(mCameraOffset), 0.0f));
trans = glm::translate(trans, glm::vec3(0.0f, -std::round(mCameraOffset), 0.0f));
// Draw our entries.
std::vector<GuiComponent*> drawAfterCursor;
@ -243,11 +245,6 @@ void ComponentList::render(const Transform4x4f& parentTrans)
// Draw selector bar.
if (mFocused) {
// Inversion: src * (1 - dst) + dst * 0 = where src = 1
// Need a function that goes roughly 0x777777 -> 0xFFFFFF
// and 0xFFFFFF -> 0x777777
// (1 - dst) + 0x77
const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data);
if (opacity == 1) {

View file

@ -66,7 +66,7 @@ public:
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
void onSizeChanged() override;

View file

@ -101,8 +101,9 @@ std::string DateTimeComponent::getDisplayString() const
return Utils::Time::timeToString(mTime.getTime(), mFormat);
}
void DateTimeComponent::render(const Transform4x4f& parentTrans)
void DateTimeComponent::render(const glm::mat4& parentTrans)
{
// Render the component.
TextComponent::render(parentTrans);
}

View file

@ -30,7 +30,7 @@ public:
Vector2f size = Vector2f::Zero(),
unsigned int bgcolor = 0x00000000);
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void setValue(const std::string& val) override;
std::string getValue() const override;

View file

@ -154,9 +154,9 @@ void DateTimeEditComponent::update(int deltaTime)
GuiComponent::update(deltaTime);
}
void DateTimeEditComponent::render(const Transform4x4f& parentTrans)
void DateTimeEditComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
if (mTextCache) {
std::shared_ptr<Font> font = getFont();
@ -170,18 +170,18 @@ void DateTimeEditComponent::render(const Transform4x4f& parentTrans)
}
// Vertically center.
Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0.0f);
glm::vec3 off(0.0f, (mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0.0f);
if (mAlignRight)
off.x() += referenceSize - mTextCache->metrics.size.x();
trans.translate(off);
off.x += referenceSize - mTextCache->metrics.size.x();
trans = glm::translate(trans, off);
Renderer::setMatrix(trans);
if (Settings::getInstance()->getBool("DebugText")) {
Renderer::setMatrix(trans);
if (mTextCache->metrics.size.x() > 0) {
Renderer::drawRect(0.0f, 0.0f - off.y(), mSize.x() - off.x(), mSize.y(), 0x0000FF33,
Renderer::drawRect(0.0f, 0.0f - off.y, mSize.x() - off.x, mSize.y(), 0x0000FF33,
0x0000FF33);
}
Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x(),

View file

@ -34,7 +34,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
unsigned int getColor() const override { return mColor; }
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override;
// Set how the point in time will be displayed:

View file

@ -50,9 +50,9 @@ GridTileComponent::GridTileComponent(Window* window)
setVisible(true);
}
void GridTileComponent::render(const Transform4x4f& parentTrans)
void GridTileComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = getTransform() * parentTrans;
glm::mat4 trans = getTransform() * parentTrans;
if (mVisible)
renderChildren(trans);
@ -171,7 +171,7 @@ void GridTileComponent::setImage(const std::shared_ptr<TextureResource>& texture
void GridTileComponent::setSelected(bool selected,
bool allowAnimation,
Vector3f* pPosition,
glm::vec3* pPosition,
bool force)
{
if (mSelected == selected && !force)
@ -189,7 +189,7 @@ void GridTileComponent::setSelected(bool selected,
resize();
}
else {
mAnimPosition = Vector3f(pPosition->x(), pPosition->y(), pPosition->z());
mAnimPosition = Vector3f(pPosition->x, pPosition->y, pPosition->z);
auto func = [this](float t) {
t -= 1; // Cubic ease out.
@ -307,7 +307,7 @@ void GridTileComponent::calcCurrentProperties()
}
}
Vector3f GridTileComponent::getBackgroundPosition()
glm::vec3 GridTileComponent::getBackgroundPosition()
{
return mBackground.getPosition() + mPosition;
}

View file

@ -27,7 +27,7 @@ class GridTileComponent : public GuiComponent
public:
GridTileComponent(Window* window);
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
@ -45,13 +45,13 @@ public:
void setImage(const std::shared_ptr<TextureResource>& texture);
void setSelected(bool selected,
bool allowAnimation = true,
Vector3f* pPosition = nullptr,
glm::vec3* pPosition = nullptr,
bool force = false);
void setVisible(bool visible);
void forceSize(Vector2f size, float selectedZoom);
Vector3f getBackgroundPosition();
glm::vec3 getBackgroundPosition();
virtual void update(int deltaTime) override;

View file

@ -152,7 +152,7 @@ void HelpComponent::updateGrid()
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
}
mGrid->setPosition(Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f));
mGrid->setPosition({ mStyle.position.x(), mStyle.position.y(), 0.0f });
mGrid->setOrigin(mStyle.origin);
}
@ -187,9 +187,9 @@ void HelpComponent::setOpacity(unsigned char opacity)
mGrid->getChild(i)->setOpacity(opacity);
}
void HelpComponent::render(const Transform4x4f& parentTrans)
void HelpComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
if (mGrid)
mGrid->render(trans);

View file

@ -26,7 +26,7 @@ public:
void clearPrompts();
void setPrompts(const std::vector<HelpPrompt>& prompts);
void render(const Transform4x4f& parent) override;
void render(const glm::mat4& parent) override;
void setOpacity(unsigned char opacity) override;
void setStyle(const HelpStyle& style);

View file

@ -282,7 +282,7 @@ protected:
scroll(mScrollVelocity);
}
void listRenderTitleOverlay(const Transform4x4f& /*trans*/)
void listRenderTitleOverlay(const glm::mat4& /*trans*/)
{
if (!Settings::getInstance()->getBool("ListScrollOverlay"))
return;

View file

@ -387,12 +387,12 @@ void ImageComponent::updateColors()
mVertices[3].col = colorEnd;
}
void ImageComponent::render(const Transform4x4f& parentTrans)
void ImageComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
Renderer::setMatrix(trans);
if (mTexture && mOpacity > 0) {

View file

@ -90,7 +90,7 @@ public:
bool hasImage() { return static_cast<bool>(mTexture); }
std::shared_ptr<TextureResource> getTexture() { return mTexture; }
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,

View file

@ -61,7 +61,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
@ -208,17 +208,17 @@ template <typename T> void ImageGridComponent<T>::update(int deltaTime)
(*it)->update(deltaTime);
}
template <typename T> void ImageGridComponent<T>::render(const Transform4x4f& parentTrans)
template <typename T> void ImageGridComponent<T>::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = getTransform() * parentTrans;
Transform4x4f tileTrans = trans;
glm::mat4 trans = getTransform() * parentTrans;
glm::mat4 tileTrans = trans;
float offsetX =
isVertical() ? 0.0f : mCamera * mCameraDirection * (mTileSize.x() + mMargin.x());
float offsetY =
isVertical() ? mCamera * mCameraDirection * (mTileSize.y() + mMargin.y()) : 0.0f;
tileTrans.translate(Vector3f(offsetX, offsetY, 0.0));
tileTrans = glm::translate(tileTrans, glm::vec3(offsetX, offsetY, 0.0f));
if (mEntriesDirty) {
updateTiles();
@ -226,11 +226,11 @@ template <typename T> void ImageGridComponent<T>::render(const Transform4x4f& pa
}
// Create a clipRect to hide tiles used to buffer texture loading.
float scaleX = trans.r0().x();
float scaleY = trans.r1().y();
float scaleX = trans[0].x;
float scaleY = trans[1].y;
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])),
static_cast<int>(std::round(trans.translation()[1])));
Vector2i pos(static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans[3].y)));
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)),
static_cast<int>(std::round(mSize.y() * scaleY)));
@ -449,7 +449,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
}
}
Vector3f oldPos = Vector3f::Zero();
glm::vec3 oldPos {};
if (oldTile != nullptr && oldTile != newTile) {
oldPos = oldTile->getBackgroundPosition();
@ -457,7 +457,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
}
if (newTile != nullptr)
newTile->setSelected(true, true, oldPos == Vector3f::Zero() ? nullptr : &oldPos, true);
newTile->setSelected(true, true, oldPos == glm::vec3 {} ? nullptr : &oldPos, true);
}
int firstVisibleCol = mStartPosition / dimOpposite;
@ -677,7 +677,7 @@ void ImageGridComponent<T>::updateTileAtPos(int tilePos,
if (idx < 0 || idx >= mTiles.size())
idx = 0;
Vector3f pos = mTiles.at(idx)->getBackgroundPosition();
glm::vec3 pos = mTiles.at(idx)->getBackgroundPosition();
tile->setSelected(true, allowAnimation, &pos);
}
else {

View file

@ -106,7 +106,7 @@ void MenuComponent::updateSize()
void MenuComponent::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
// Update grid row/column sizes.
mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y());

View file

@ -118,12 +118,12 @@ void NinePatchComponent::buildVertices()
updateColors();
}
void NinePatchComponent::render(const Transform4x4f& parentTrans)
void NinePatchComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
if (mTexture && mVertices != nullptr) {
Renderer::setMatrix(trans);
@ -146,15 +146,15 @@ void NinePatchComponent::render(const Transform4x4f& parentTrans)
void NinePatchComponent::onSizeChanged() { buildVertices(); }
void NinePatchComponent::fitTo(Vector2f size, Vector3f position, Vector2f padding)
void NinePatchComponent::fitTo(Vector2f size, glm::vec3 position, Vector2f padding)
{
size += padding;
position[0] -= padding.x() / 2.0f;
position[1] -= padding.y() / 2.0f;
setSize(size + mCornerSize * 2.0f);
setPosition(position.x() + Math::lerp(-mCornerSize.x(), mCornerSize.x(), mOrigin.x()),
position.y() + Math::lerp(-mCornerSize.y(), mCornerSize.y(), mOrigin.y()));
setPosition(position.x + Math::lerp(-mCornerSize.x(), mCornerSize.x(), mOrigin.x()),
position.y + Math::lerp(-mCornerSize.y(), mCornerSize.y(), mOrigin.y()));
}
void NinePatchComponent::setImagePath(const std::string& path)

View file

@ -35,13 +35,11 @@ public:
unsigned int centerColor = 0xFFFFFFFF);
virtual ~NinePatchComponent();
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override;
void fitTo(Vector2f size,
Vector3f position = Vector3f::Zero(),
Vector2f padding = Vector2f::Zero());
void fitTo(Vector2f size, glm::vec3 position = {}, Vector2f padding = Vector2f::Zero());
void setImagePath(const std::string& path);
// Apply a color shift to the "edge" parts of the ninepatch.

View file

@ -75,11 +75,11 @@ public:
mText.getFont()->getHeight());
// Position.
mLeftArrow.setPosition(0, (mSize.y() - mLeftArrow.getSize().y()) / 2);
mText.setPosition(mLeftArrow.getPosition().x() + mLeftArrow.getSize().x(),
(mSize.y() - mText.getSize().y()) / 2);
mRightArrow.setPosition(mText.getPosition().x() + mText.getSize().x(),
(mSize.y() - mRightArrow.getSize().y()) / 2);
mLeftArrow.setPosition(0.0f, (mSize.y() - mLeftArrow.getSize().y()) / 2.0f);
mText.setPosition(mLeftArrow.getPosition().x + mLeftArrow.getSize().x(),
(mSize.y() - mText.getSize().y()) / 2.0f);
mRightArrow.setPosition(mText.getPosition().x + mText.getSize().x(),
(mSize.y() - mRightArrow.getSize().y()) / 2.0f);
}
bool input(InputConfig* config, Input input) override

View file

@ -141,12 +141,12 @@ void RatingComponent::updateColors()
mVertices[i].col = color;
}
void RatingComponent::render(const Transform4x4f& parentTrans)
void RatingComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible() || mFilledTexture == nullptr || mUnfilledTexture == nullptr)
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
Renderer::setMatrix(trans);

View file

@ -27,7 +27,7 @@ public:
void setValue(const std::string& value) override;
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override;

View file

@ -148,23 +148,26 @@ void ScrollableContainer::update(int deltaTime)
GuiComponent::update(deltaTime);
}
void ScrollableContainer::render(const Transform4x4f& parentTrans)
void ScrollableContainer::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
Vector2i clipPos(static_cast<int>(trans.translation().x()),
static_cast<int>(trans.translation().y()));
Vector2i clipPos(static_cast<int>(trans[3].x), static_cast<int>(trans[3].y));
Vector3f dimScaled = trans * Vector3f(mSize.x(), mSize.y(), 0);
Vector2i clipDim(static_cast<int>((dimScaled.x()) - trans.translation().x()),
static_cast<int>((dimScaled.y()) - trans.translation().y()));
glm::vec3 dimScaled {};
dimScaled.x = std::fabs(trans[3].x + mSize.x());
dimScaled.y = std::fabs(trans[3].y + mSize.y());
Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y));
Renderer::pushClipRect(clipPos, clipDim);
trans.translate(-Vector3f(mScrollPos.x(), mScrollPos.y(), 0));
trans = glm::translate(trans, -glm::vec3(mScrollPos.x(), mScrollPos.y(), 0.0f));
Renderer::setMatrix(trans);
GuiComponent::renderChildren(trans);

View file

@ -34,7 +34,7 @@ public:
void reset();
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
private:
Vector2f getContentSize();

View file

@ -74,9 +74,9 @@ void SliderComponent::update(int deltaTime)
GuiComponent::update(deltaTime);
}
void SliderComponent::render(const Transform4x4f& parentTrans)
void SliderComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
Renderer::setMatrix(trans);
// Render suffix.

View file

@ -29,7 +29,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override;

View file

@ -42,9 +42,9 @@ bool SwitchComponent::input(InputConfig* config, Input input)
return false;
}
void SwitchComponent::render(const Transform4x4f& parentTrans)
void SwitchComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
mImage.render(trans);
renderChildren(trans);
}

View file

@ -19,7 +19,7 @@ public:
SwitchComponent(Window* window, bool state = false);
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override { mImage.setSize(mSize); }
void setResize(float width, float height) override { mImage.setResize(width, height); }

View file

@ -54,7 +54,11 @@ TextComponent::TextComponent(Window* window,
setColor(color);
setBackgroundColor(bgcolor);
setText(text);
setPosition(pos);
// TEMPORARY
glm::vec3 tempvec = { pos.x(), pos.y(), pos.z() };
setPosition(tempvec);
setSize(size);
}
@ -115,12 +119,12 @@ void TextComponent::setUppercase(bool uppercase)
onTextChanged();
}
void TextComponent::render(const Transform4x4f& parentTrans)
void TextComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
if (mRenderBackground) {
Renderer::setMatrix(trans);
@ -147,7 +151,7 @@ void TextComponent::render(const Transform4x4f& parentTrans)
break;
}
}
Vector3f off(0, yOff, 0);
glm::vec3 off(0.0f, yOff, 0.0f);
if (Settings::getInstance()->getBool("DebugText")) {
// Draw the "textbox" area, what we are aligned within.
@ -155,7 +159,7 @@ void TextComponent::render(const Transform4x4f& parentTrans)
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x0000FF33, 0x0000FF33);
}
trans.translate(off);
trans = glm::translate(trans, off);
Renderer::setMatrix(trans);
// Draw the text area, where the text actually is located.

View file

@ -48,7 +48,7 @@ public:
void setBackgroundColor(unsigned int color);
void setRenderBackground(bool render) { mRenderBackground = render; }
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
std::string getValue() const override { return mText; }
void setValue(const std::string& value) override { setText(value); }

View file

@ -46,7 +46,7 @@ void TextEditComponent::onFocusLost()
void TextEditComponent::onSizeChanged()
{
mBox.fitTo(mSize, Vector3f::Zero(),
mBox.fitTo(mSize, {},
Vector2f(-34 + mResolutionAdjustment,
-32 - (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())));
onTextChanged(); // Wrap point probably changed.
@ -271,24 +271,26 @@ void TextEditComponent::onCursorChanged()
}
}
void TextEditComponent::render(const Transform4x4f& parentTrans)
void TextEditComponent::render(const glm::mat4& parentTrans)
{
Transform4x4f trans = getTransform() * parentTrans;
glm::mat4 trans = getTransform() * parentTrans;
renderChildren(trans);
// Text + cursor rendering.
// Offset into our "text area" (padding).
trans.translation() += Vector3f(getTextAreaPos().x(), getTextAreaPos().y(), 0);
trans = glm::translate(trans, glm::vec3(getTextAreaPos().x(), getTextAreaPos().y(), 0.0f));
Vector2i clipPos(static_cast<int>(trans.translation().x()),
static_cast<int>(trans.translation().y()));
Vector2i clipPos(static_cast<int>(trans[3].x), static_cast<int>(trans[3].y));
// Use "text area" size for clipping.
Vector3f dimScaled = trans * Vector3f(getTextAreaSize().x(), getTextAreaSize().y(), 0);
Vector2i clipDim(static_cast<int>((dimScaled.x()) - trans.translation().x()),
static_cast<int>((dimScaled.y()) - trans.translation().y()));
glm::vec3 dimScaled {};
dimScaled.x = std::fabs(trans[3].x + getTextAreaSize().x());
dimScaled.y = std::fabs(trans[3].y + getTextAreaSize().y());
Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y));
Renderer::pushClipRect(clipPos, clipDim);
trans.translate(Vector3f(-mScrollOffset.x(), -mScrollOffset.y(), 0));
trans = glm::translate(trans, glm::vec3(-mScrollOffset.x(), -mScrollOffset.y(), 0.0f));
Renderer::setMatrix(trans);
if (mTextCache)

View file

@ -25,7 +25,7 @@ public:
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void onFocusGained() override;
void onFocusLost() override;

View file

@ -48,7 +48,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
@ -155,12 +155,12 @@ TextListComponent<T>::TextListComponent(Window* window)
mColors[1] = 0x00FF00FF;
}
template <typename T> void TextListComponent<T>::render(const Transform4x4f& parentTrans)
template <typename T> void TextListComponent<T>::render(const glm::mat4& parentTrans)
{
if (size() == 0)
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
std::shared_ptr<Font>& font = mFont;
int startEntry = 0;
@ -206,12 +206,13 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
}
// Clip to inside margins.
Vector3f dim(mSize.x(), mSize.y(), 0.0f);
dim = trans * dim - trans.translation();
glm::vec3 dim(mSize.x(), mSize.y(), 0.0f);
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
Renderer::pushClipRect(
Vector2i(static_cast<int>(trans.translation().x() + mHorizontalMargin),
static_cast<int>(trans.translation().y())),
Vector2i(static_cast<int>(dim.x() - mHorizontalMargin * 2.0f), static_cast<int>(dim.y())));
Vector2i(static_cast<int>(trans[3].x + mHorizontalMargin), static_cast<int>(trans[3].y)),
Vector2i(static_cast<int>(dim.x - mHorizontalMargin * 2.0f), static_cast<int>(dim.y)));
for (int i = startEntry; i < listCutoff; i++) {
typename IList<TextListData, T>::Entry& entry = mEntries.at(static_cast<unsigned int>(i));
@ -235,34 +236,35 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
else
entry.data.textCache->setColor(color);
Vector3f offset(0.0f, y, 0.0f);
glm::vec3 offset(0.0f, y, 0.0f);
switch (mAlignment) {
case ALIGN_LEFT:
offset[0] = mHorizontalMargin;
offset.x = mHorizontalMargin;
break;
case ALIGN_CENTER:
offset[0] =
offset.x =
static_cast<float>((mSize.x() - entry.data.textCache->metrics.size.x()) / 2.0f);
if (offset[0] < mHorizontalMargin)
offset[0] = mHorizontalMargin;
if (offset.x < mHorizontalMargin)
offset.x = mHorizontalMargin;
break;
case ALIGN_RIGHT:
offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x());
offset[0] -= mHorizontalMargin;
if (offset[0] < mHorizontalMargin)
offset[0] = mHorizontalMargin;
offset.x = (mSize.x() - entry.data.textCache->metrics.size.x());
offset.x -= mHorizontalMargin;
if (offset.x < mHorizontalMargin)
offset.x = mHorizontalMargin;
break;
}
// Render text.
Transform4x4f drawTrans = trans;
glm::mat4 drawTrans = trans;
// Currently selected item text might be scrolling.
if (mCursor == i && mMarqueeOffset > 0)
drawTrans.translate(offset - Vector3f(static_cast<float>(mMarqueeOffset), 0.0f, 0.0f));
drawTrans = glm::translate(
drawTrans, offset - glm::vec3(static_cast<float>(mMarqueeOffset), 0.0f, 0.0f));
else
drawTrans.translate(offset);
drawTrans = glm::translate(drawTrans, offset);
// Needed to avoid flickering when returning to the start position.
if (mMarqueeOffset == 0 && mMarqueeOffset2 == 0)
@ -275,13 +277,13 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
if ((mCursor == i && mMarqueeOffset2 < 0) || (mCursor == i && mMarqueeScroll)) {
mMarqueeScroll = true;
drawTrans = trans;
drawTrans.translate(offset - Vector3f(static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f));
drawTrans = glm::translate(
drawTrans, offset - glm::vec3(static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f));
Renderer::setMatrix(drawTrans);
font->renderTextCache(entry.data.textCache.get());
}
y += entrySize;
}
Renderer::popClipRect();
listRenderTitleOverlay(trans);
GuiComponent::renderChildren(trans);

View file

@ -171,12 +171,12 @@ void VideoComponent::topWindow(bool isTop)
manageState();
}
void VideoComponent::render(const Transform4x4f& parentTrans)
void VideoComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible())
return;
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
GuiComponent::renderChildren(trans);
Renderer::setMatrix(trans);
@ -191,7 +191,7 @@ void VideoComponent::render(const Transform4x4f& parentTrans)
pauseVideo();
}
void VideoComponent::renderSnapshot(const Transform4x4f& parentTrans)
void VideoComponent::renderSnapshot(const glm::mat4& parentTrans)
{
// This function is called when the video is not currently being played. We need to
// work out if we should display a static image. If the menu is open, then always render

View file

@ -61,8 +61,8 @@ public:
void onPositionChanged() override { mStaticImage.setPosition(mPosition); }
void onSizeChanged() override { mStaticImage.onSizeChanged(); }
void render(const Transform4x4f& parentTrans) override;
void renderSnapshot(const Transform4x4f& parentTrans);
void render(const glm::mat4& parentTrans) override;
void renderSnapshot(const glm::mat4& parentTrans);
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,

View file

@ -119,10 +119,10 @@ void VideoFFmpegComponent::resize()
onSizeChanged();
}
void VideoFFmpegComponent::render(const Transform4x4f& parentTrans)
void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
{
VideoComponent::render(parentTrans);
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
GuiComponent::renderChildren(trans);
if (mIsPlaying && mFormatContext) {
@ -839,8 +839,8 @@ void VideoFFmpegComponent::calculateBlackRectangle()
// If the option to display pillarboxes is disabled, then make the rectangle equivalent
// to the size of the video.
else {
mVideoRectangleCoords.push_back(std::round(mPosition.x() - mSize.x() * mOrigin.x()));
mVideoRectangleCoords.push_back(std::round(mPosition.y() - mSize.y() * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(mPosition.x - mSize.x() * mOrigin.x()));
mVideoRectangleCoords.push_back(std::round(mPosition.y - mSize.y() * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(mSize.x()));
mVideoRectangleCoords.push_back(std::round(mSize.y()));
}

View file

@ -50,7 +50,7 @@ private:
// Used internally whenever the resizing parameters or texture change.
void resize();
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
virtual void updatePlayer() override;
// This will run the frame processing in a separate thread.

View file

@ -168,7 +168,7 @@ void VideoVlcComponent::resize()
onSizeChanged();
}
void VideoVlcComponent::render(const Transform4x4f& parentTrans)
void VideoVlcComponent::render(const glm::mat4& parentTrans)
{
// Set the audio volume. As libVLC is very unreliable we need to make an additional
// attempt here in the render loop in addition to the initialization in startVideo().
@ -179,7 +179,7 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans)
setAudioVolume();
VideoComponent::render(parentTrans);
Transform4x4f trans = parentTrans * getTransform();
glm::mat4 trans = parentTrans * getTransform();
GuiComponent::renderChildren(trans);
// Check the actual VLC state, i.e. if the video is really playing rather than
@ -296,8 +296,8 @@ void VideoVlcComponent::calculateBlackRectangle()
// If the option to display pillarboxes is disabled, then make the rectangle equivalent
// to the size of the video.
else {
mVideoRectangleCoords.push_back(std::round(mPosition.x() - mSize.x() * mOrigin.x()));
mVideoRectangleCoords.push_back(std::round(mPosition.y() - mSize.y() * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(mPosition.x - mSize.x() * mOrigin.x()));
mVideoRectangleCoords.push_back(std::round(mPosition.y - mSize.y() * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(mSize.x()));
mVideoRectangleCoords.push_back(std::round(mSize.y()));
}

View file

@ -53,7 +53,7 @@ private:
// Used internally whenever the resizing parameters or texture change.
void resize();
void render(const Transform4x4f& parentTrans) override;
void render(const glm::mat4& parentTrans) override;
void calculateBlackRectangle();
void setAudioVolume();

View file

@ -106,7 +106,7 @@ GuiComplexTextEditPopup::GuiComplexTextEditPopup(
void GuiComplexTextEditPopup::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
mText->setSize(mSize.x() - 40.0f, mText->getSize().y());
// Update grid.

View file

@ -93,7 +93,7 @@ GuiDetectDevice::GuiDetectDevice(Window* window,
void GuiDetectDevice::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
// Grid.
mGrid.setSize(mSize);

View file

@ -293,7 +293,7 @@ void GuiInputConfig::update(int deltaTime)
void GuiInputConfig::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
// Update grid.
mGrid.setSize(mSize);

View file

@ -160,7 +160,7 @@ void GuiMsgBox::onSizeChanged()
mGrid.getRowHeight(0));
mGrid.onSizeChanged();
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
}
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)

View file

@ -78,7 +78,7 @@ GuiTextEditPopup::GuiTextEditPopup(Window* window,
void GuiTextEditPopup::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f));
mText->setSize(mSize.x() - 40, mText->getSize().y());

View file

@ -10,10 +10,11 @@
#define ES_CORE_MATH_MISC_H
#include <algorithm>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/trigonometric.hpp>
#define ES_PI (3.1415926535897932384626433832795028841971693993751058209749445923)
#define ES_RAD_TO_DEG(_x) ((_x) * (180.0 / ES_PI))
#define ES_DEG_TO_RAD(_x) ((_x) * (ES_PI / 180.0))
#include <glm/gtc/round.hpp>
namespace Math
{

View file

@ -12,7 +12,6 @@
#include "Log.h"
#include "Settings.h"
#include "Shader_GL21.h"
#include "math/Transform4x4f.h"
#include "math/Vector2i.h"
#include "resources/ResourceManager.h"
@ -326,28 +325,19 @@ namespace Renderer
if (!createWindow())
return false;
Transform4x4f projection = Transform4x4f::Identity();
glm::mat4 projection = getIdentity();
Rect viewport = Rect(0, 0, 0, 0);
switch (screenRotate) {
case 0: {
viewport.x = screenOffsetX;
viewport.y = screenOffsetY;
viewport.w = screenWidth;
viewport.h = screenHeight;
projection.orthoProjection(0.0f, static_cast<float>(screenWidth),
static_cast<float>(screenHeight), 0.0f, -1.0f, 1.0f);
break;
}
case 1: {
viewport.x = windowWidth - screenOffsetY - screenHeight;
viewport.y = screenOffsetX;
viewport.w = screenHeight;
viewport.h = screenWidth;
projection.orthoProjection(0.0f, static_cast<float>(screenHeight),
static_cast<float>(screenWidth), 0.0f, -1.0f, 1.0f);
projection.rotate(static_cast<float>(ES_DEG_TO_RAD(90)), { 0, 0, 1 });
projection.translate({ 0, screenHeight * -1.0f, 0 });
projection = glm::ortho(0.0f, static_cast<float>(screenHeight),
static_cast<float>(screenWidth), 0.0f, -1.0f, 1.0f);
projection = glm::rotate(projection, glm::radians(90.0f), { 0.0f, 0.0f, 1.0f });
projection = glm::translate(projection, { 0.0f, screenHeight * -1.0f, 0.0f });
break;
}
case 2: {
@ -355,10 +345,11 @@ namespace Renderer
viewport.y = windowHeight - screenOffsetY - screenHeight;
viewport.w = screenWidth;
viewport.h = screenHeight;
projection.orthoProjection(0.0f, static_cast<float>(screenWidth),
static_cast<float>(screenHeight), 0.0f, -1.0f, 1.0f);
projection.rotate(static_cast<float>(ES_DEG_TO_RAD(180)), { 0, 0, 1 });
projection.translate({ screenWidth * -1.0f, screenHeight * -1.0f, 0 });
projection = glm::ortho(0.0f, static_cast<float>(screenWidth),
static_cast<float>(screenHeight), 0.0f, -1.0f, 1.0f);
projection = glm::rotate(projection, glm::radians(180.0f), { 0.0f, 0.0f, 1.0f });
projection =
glm::translate(projection, { screenWidth * -1.0f, screenHeight * -1.0f, 0.0f });
break;
}
case 3: {
@ -366,10 +357,19 @@ namespace Renderer
viewport.y = windowHeight - screenOffsetX - screenWidth;
viewport.w = screenHeight;
viewport.h = screenWidth;
projection.orthoProjection(0.0f, static_cast<float>(screenHeight),
static_cast<float>(screenWidth), 0.0f, -1.0f, 1.0f);
projection.rotate(static_cast<float>(ES_DEG_TO_RAD(270)), { 0, 0, 1 });
projection.translate({ screenWidth * -1.0f, 0, 0 });
projection = glm::ortho(0.0f, static_cast<float>(screenHeight),
static_cast<float>(screenWidth), 0.0f, -1.0f, 1.0f);
projection = glm::rotate(projection, glm::radians(270.0f), { 0.0f, 0.0f, 1.0f });
projection = glm::translate(projection, { screenWidth * -1.0f, 0.0f, 0.0f });
break;
}
default: {
viewport.x = screenOffsetX;
viewport.y = screenOffsetY;
viewport.w = screenWidth;
viewport.h = screenHeight;
projection = glm::ortho(0.0f, static_cast<float>(screenWidth),
static_cast<float>(screenHeight), 0.0f, -1.0f, 1.0f);
break;
}
}
@ -466,7 +466,7 @@ namespace Renderer
const unsigned int _colorEnd,
bool horizontalGradient,
const float _opacity,
const Transform4x4f& _trans,
const glm::mat4& _trans,
const Blend::Factor _srcBlendFactor,
const Blend::Factor _dstBlendFactor)
{
@ -542,7 +542,7 @@ namespace Renderer
return nullptr;
};
const Transform4x4f getProjectionMatrix() { return mProjectionMatrix; }
const glm::mat4 getProjectionMatrix() { return mProjectionMatrix; }
SDL_Window* getSDLWindow() { return sdlWindow; }
int getWindowWidth() { return windowWidth; }
int getWindowHeight() { return windowHeight; }

View file

@ -11,7 +11,7 @@
#include "Log.h"
#include "Shader_GL21.h"
#include "math/Transform4x4f.h"
#include "math/Misc.h"
#include "math/Vector2f.h"
#include <string>
@ -19,7 +19,6 @@
struct SDL_Window;
class Transform4x4f;
class Vector2i;
namespace Renderer
@ -52,7 +51,8 @@ namespace Renderer
static std::vector<Shader*> sShaderProgramVector;
static GLuint shaderFBO;
static Transform4x4f mProjectionMatrix;
static glm::mat4 mProjectionMatrix;
static constexpr glm::mat4 getIdentity() { return glm::mat4(1.0f); }
#if !defined(NDEBUG)
#define GL_CHECK_ERROR(Function) (Function, _GLCheckError(#Function))
@ -141,7 +141,7 @@ namespace Renderer
const unsigned int _colorEnd,
bool horizontalGradient = false,
const float _opacity = 1.0,
const Transform4x4f& _trans = Transform4x4f::Identity(),
const glm::mat4& _trans = getIdentity(),
const Blend::Factor _srcBlendFactor = Blend::SRC_ALPHA,
const Blend::Factor _dstBlendFactor = Blend::ONE_MINUS_SRC_ALPHA);
SDL_Window* getSDLWindow();
@ -160,7 +160,7 @@ namespace Renderer
unsigned int convertABGRToRGBA(unsigned int color);
Shader* getShaderProgram(unsigned int shaderID);
const Transform4x4f getProjectionMatrix();
const glm::mat4 getProjectionMatrix();
void shaderPostprocessing(unsigned int shaders,
const Renderer::shaderParameters& parameters = shaderParameters(),
unsigned char* textureRGBA = nullptr);
@ -191,12 +191,12 @@ namespace Renderer
const Blend::Factor _dstBlendFactor = Blend::ONE_MINUS_SRC_ALPHA);
void drawTriangleStrips(const Vertex* _vertices,
const unsigned int _numVertices,
const Transform4x4f& _trans = Transform4x4f::Identity(),
const glm::mat4& _trans = getIdentity(),
const Blend::Factor _srcBlendFactor = Blend::SRC_ALPHA,
const Blend::Factor _dstBlendFactor = Blend::ONE_MINUS_SRC_ALPHA,
const shaderParameters& _parameters = shaderParameters());
void setProjection(const Transform4x4f& _projection);
void setMatrix(const Transform4x4f& _matrix);
void setProjection(const glm::mat4& _projection);
void setMatrix(const glm::mat4& _matrix);
void setViewport(const Rect& _viewport);
void setScissor(const Rect& _scissor);
void setSwapInterval();

View file

@ -10,7 +10,6 @@
#include "Settings.h"
#include "Shader_GL21.h"
#include "math/Transform4x4f.h"
#include "renderers/Renderer.h"
namespace Renderer
@ -239,7 +238,7 @@ namespace Renderer
void drawTriangleStrips(const Vertex* _vertices,
const unsigned int _numVertices,
const Transform4x4f& _trans,
const glm::mat4& _trans,
const Blend::Factor _srcBlendFactor,
const Blend::Factor _dstBlendFactor,
const shaderParameters& _parameters)
@ -353,16 +352,16 @@ namespace Renderer
#endif
}
void setProjection(const Transform4x4f& _projection)
void setProjection(const glm::mat4& _projection)
{
GL_CHECK_ERROR(glMatrixMode(GL_PROJECTION));
GL_CHECK_ERROR(glLoadMatrixf(reinterpret_cast<const GLfloat*>(&_projection)));
}
void setMatrix(const Transform4x4f& _matrix)
void setMatrix(const glm::mat4& _matrix)
{
Transform4x4f matrix = _matrix;
matrix.round();
glm::mat4 matrix = _matrix;
matrix[3] = glm::round(matrix[3]);
GL_CHECK_ERROR(glMatrixMode(GL_MODELVIEW));
GL_CHECK_ERROR(glLoadMatrixf(reinterpret_cast<const GLfloat*>(&matrix)));
@ -448,7 +447,7 @@ namespace Renderer
if (parameters.fragmentSaturation < 1.0)
vertices[0].saturation = parameters.fragmentSaturation;
setMatrix(Transform4x4f::Identity());
setMatrix(getIdentity());
GLuint screenTexture = createTexture(Texture::RGBA, false, false, width, height, nullptr);
GL_CHECK_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER, 0));
@ -475,7 +474,7 @@ namespace Renderer
GL_COLOR_BUFFER_BIT, GL_NEAREST));
// Apply/render the shaders.
drawTriangleStrips(vertices, 4, Transform4x4f::Identity(), Blend::SRC_ALPHA,
drawTriangleStrips(vertices, 4, getIdentity(), Blend::SRC_ALPHA,
Blend::ONE_MINUS_SRC_ALPHA, parameters);
// If textureRGBA has an address, it means that the output should go to this

View file

@ -10,7 +10,6 @@
#include "Log.h"
#include "Settings.h"
#include "math/Transform4x4f.h"
#include "renderers/Renderer.h"
#include <SDL2/SDL.h>
@ -185,7 +184,7 @@ namespace Renderer
void drawTriangleStrips(const Vertex* _vertices,
const unsigned int _numVertices,
const Transform4x4f& _trans,
const glm::mat4& _trans,
const Blend::Factor _srcBlendFactor,
const Blend::Factor _dstBlendFactor,
const shaderParameters& _parameters)
@ -200,16 +199,16 @@ namespace Renderer
GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, _numVertices));
}
void setProjection(const Transform4x4f& _projection)
void setProjection(const glm::mat4& _projection)
{
GL_CHECK_ERROR(glMatrixMode(GL_PROJECTION));
GL_CHECK_ERROR(glLoadMatrixf((GLfloat*)&_projection));
}
void setMatrix(const Transform4x4f& _matrix)
void setMatrix(const glm::mat4& _matrix)
{
Transform4x4f matrix = _matrix;
matrix.round();
glm::mat4 matrix = _matrix;
matrix[3] = glm::round(matrix[3]);
GL_CHECK_ERROR(glMatrixMode(GL_MODELVIEW));
GL_CHECK_ERROR(glLoadMatrixf((GLfloat*)&matrix));

View file

@ -114,7 +114,7 @@ namespace Renderer
shaderDimValue = glGetUniformLocation(mProgramID, "dimValue");
}
void Renderer::Shader::setModelViewProjectionMatrix(Transform4x4f mvpMatrix)
void Renderer::Shader::setModelViewProjectionMatrix(glm::mat4 mvpMatrix)
{
if (shaderMVPMatrix != -1)
GL_CHECK_ERROR(glUniformMatrix4fv(shaderMVPMatrix, 1, GL_FALSE,

View file

@ -11,7 +11,8 @@
#define GL_GLEXT_PROTOTYPES
#include "math/Transform4x4f.h"
#include "math/Misc.h"
#include "math/Vector3f.h"
#if defined(_WIN64)
#include <GL/glew.h>
@ -45,7 +46,8 @@ namespace Renderer
// Get references to the variables inside the compiled shaders.
void getVariableLocations(GLuint programID);
// One-way communication with the compiled shaders.
void setModelViewProjectionMatrix(Transform4x4f mvpMatrix);
void setModelViewProjectionMatrix(glm::mat4 mvpMatrix);
void setTextureSize(std::array<GLfloat, 2> shaderVec2);
void setTextureCoordinates(std::array<GLfloat, 4> shaderVec4);
void setColor(std::array<GLfloat, 4> shaderVec4);