我已经在Visual中使用OpenGL和C++为安卓手机创建了自己的简单级别编辑器。但我偶然发现了一个问题,我在编辑器中放置的一些对象在android上没有正确显示,有时甚至没有出现。我一直在四处寻找,却找不到解决办法。这是我的lLevel编辑器的正射相机和屏幕分辨率:
相机对象正交矩阵:
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上做了几个游戏,但我具体地制作了背景图像,使其精确的宽度和高度,因为我一直在我的正交矩阵中乘以纵横比。但这一次,我只想提取背景和物体的位置和大小,让他们保持他们的方面,而不是延伸到不同的分辨率。
如果没有其他通用解决方案,如果没有,我想我应该在级别编辑器上使用一些固定的分辨率,并在android上使用相同的分辨率?
发布于 2022-06-25 04:22:08
它应该能起作用:
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));https://stackoverflow.com/questions/67460921
复制相似问题