OpenGL "Free Aspect Ratio"就像在Unity中一样



我在Visual Studio中使用OpenGL和C++为android手机创建了自己的简单级别编辑器。但我偶然发现了一个问题,我放在编辑器中的一些对象在android上没有正确显示,有时甚至没有出现。我一直在四处寻找,但找不到解决方案。这是我的lLevel Editor的正交相机和屏幕分辨率:

相机对象正交矩阵:

GoldState::aspectRatio = m_AspectRatio = (float)width / (float)height;
float orthoLeft = 0.0f; //* m_AspectRatio;
float orthoRight = 100.0f; //* m_AspectRatio;
float orthoUp = 100.0f;
float orthoDown = 0.0f;
m_OrthoMatrix = glm::ortho(orthoLeft, orthoRight, orthoDown, orthoUp);

对于android来说也是一样的(使用ndk(。

宽高比之所以被注释掉,是因为我在做实验,如果不乘以宽高比,整个世界都会被拉伸。

现在到统一的自由纵横比,我有一种感觉,就像我的正交相机没有乘以纵横比。这到底是什么?当我选择"自由纵横比"时,我放置在单位上的每个对象如何保持1:1,并且它没有拉伸或其他什么?如果有人能向我解释这一点,那将对我有很大帮助。

还有一件事。我已经在安卓上使用opengl制作了几个游戏,但我专门将背景图像制作成了精确的宽度和高度,因为我一直在正交矩阵中乘以纵横比。但这一次,我只想提取背景和对象的位置和大小,并让它们保持它们的外观,而不会在不同的分辨率上拉伸。

如果有其他通用的解决方案,如果没有,那就太好了。我想我应该在级别编辑器上使用一些固定的分辨率,并对android使用相同的分辨率?

它应该做到这一点:

GoldState::aspectRatio = m_AspectRatio = (float)width / (float)height;
GoldState::orthoSize = m_OrthoSize = ((float)width / (float)height < 16f / 9f ? (float)width / (float)height : 16f / 9f) / (16f / 9f);
float srcAspectRatio = 1f / 1f; //* Original aspect, default: 1.0;
float orthoLeft = 0.0f;
float orthoRight = 100.0f;
float orthoUp = 100.0f;
float orthoDown = 0.0f;
m_OrthoMatrix = glm::ortho(((0.5f*(orthoright - orthoLeft) + ortholeft) * srcAspectRatio) - (0.5f*(orthoright - orthoLeft) * m_AspectRatio * m_OrthoSize), ((0.5f*(orthoright - orthoLeft) + ortholeft) * srcAspectRatio) + (0.5f*(orthoright - orthoLeft) * m_AspectRatio * m_OrthoSize),(0.5f*(orthoDown - orthoUp) + orthoUp) - (0.5f*(orthoDown - orthoUp) * m_OrthoSize),(0.5f*(orthoDown - orthoUp) + orthoUp) + (0.5f*(orthoDown - orthoUp) * m_OrthoSize));

相关内容

最新更新