FREESCAPE: correctly scale mouse position in opengl renderers

This commit is contained in:
neuromancer 2023-06-04 13:57:00 +02:00
parent 7d3fc01cd1
commit 4486477a93
6 changed files with 26 additions and 5 deletions

View file

@ -468,22 +468,25 @@ void FreescapeEngine::processInput() {
if (_shootMode) {
{
bool shouldWarp = false;
_crossairPosition = mousePos;
if (mousePos.x < _viewArea.left) {
Common::Point resolution = _gfx->nativeResolution();
_crossairPosition.x = _screenW * mousePos.x / resolution.x;
_crossairPosition.y = _screenH * mousePos.y / resolution.y;
if (_crossairPosition.x < _viewArea.left) {
_crossairPosition.x = _viewArea.left + 1;
shouldWarp = true;
}
if (mousePos.x > _viewArea.right) {
if (_crossairPosition.x > _viewArea.right) {
_crossairPosition.x = _viewArea.right - 1;
shouldWarp = true;
}
if (mousePos.y < _viewArea.top) {
if (_crossairPosition.y < _viewArea.top) {
_crossairPosition.y = _viewArea.top + 1;
shouldWarp = true;
}
if (mousePos.y > _viewArea.bottom) {
if (_crossairPosition.y > _viewArea.bottom) {
_crossairPosition.y = _viewArea.bottom - 1;
shouldWarp = true;
}
@ -508,6 +511,9 @@ void FreescapeEngine::processInput() {
bool touchedScreenControls = false;
#if defined(__ANDROID__) || defined(IPHONE)
Common::Point resolution = _gfx->nativeResolution();
mousPos.x = _screenW * mousePos.x / resolution.x;
mousPos.y = _screenH * mousePos.y / resolution.y;
touchedScreenControls = onScreenControls(mousePos);
#endif

View file

@ -96,6 +96,7 @@ public:
virtual void drawBackground(uint8 color);
Common::Rect viewport() const;
virtual Common::Point nativeResolution() { return Common::Point(_screenW, _screenH); }
// palette
void readFromPalette(uint8 index, uint8 &r, uint8 &g, uint8 &b);

View file

@ -58,6 +58,12 @@ void OpenGLRenderer::freeTexture(Texture *texture) {
delete texture;
}
Common::Point OpenGLRenderer::nativeResolution() {
GLint vect[4];
glGetIntegerv(GL_VIEWPORT, vect);
return Common::Point(vect[2], vect[3]);
}
void OpenGLRenderer::init() {
computeScreenViewport();

View file

@ -84,6 +84,7 @@ public:
virtual void init() override;
virtual void clear(uint8 r, uint8 g, uint8 b) override;
virtual void setViewport(const Common::Rect &rect) override;
virtual Common::Point nativeResolution() override;
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest) override;
virtual void updateProjectionMatrix(float fov, float nearClipPlane, float farClipPlane) override;

View file

@ -73,6 +73,12 @@ void OpenGLShaderRenderer::freeTexture(Texture *texture) {
delete texture;
}
Common::Point OpenGLShaderRenderer::nativeResolution() {
GLint vect[4];
glGetIntegerv(GL_VIEWPORT, vect);
return Common::Point(vect[2], vect[3]);
}
void OpenGLShaderRenderer::init() {
computeScreenViewport();

View file

@ -67,6 +67,7 @@ public:
virtual void init() override;
virtual void clear(uint8 r, uint8 g, uint8 b) override;
virtual void setViewport(const Common::Rect &rect) override;
virtual Common::Point nativeResolution() override;
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest) override;
virtual void updateProjectionMatrix(float fov, float nearClipPlane, float farClipPlane) override;