在 LibGDX (Java) 中更改坐标系 [英] Changing the Coordinate System in LibGDX (Java)

查看:25
本文介绍了在 LibGDX (Java) 中更改坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LibGDX 有一个坐标系,其中 (0,0) 位于左下角.(像这张图片:http://i.stack.imgur.com/jVrJ0.png)

LibGDX has a coordinate system where (0,0) is at the bottom-left. (like this image: http://i.stack.imgur.com/jVrJ0.png)

这让我头撞墙,主要是因为我正在移植一个我已经用通常的坐标系(其中 0,0 位于左上角)制作的游戏.

This has me beating my head against a wall, mainly because I'm porting a game I had already made with the usual coordinate system (where 0,0 is in the Top Left Corner).

我的问题:有什么简单的方法可以改变这个坐标系吗?

推荐答案

如果你使用相机(你应该这样做),改变坐标系非常简单:

If you use a Camera (which you should) changing the coordinate system is pretty simple:

camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

如果您使用 TextureRegions 和/或 TextureAtlas,除此之外您需要做的就是调用 region.flip(false, true).

If you use TextureRegions and/or a TextureAtlas, all you need to do in addition to that is call region.flip(false, true).

我们默认使用 y-up 的原因(您可以如上所示轻松更改)如下:

The reasons we use y-up by default (which you can easily change as illustrated above) are as follows:

  • 您的模拟代码很可能使用带有 y-up 的标准欧几里得坐标系
  • 如果你使用 3D 技术,你就可以了
  • 默认坐标系是 OpenGL 中的右手坐标系,y 向上.您当然可以使用一些矩阵魔法轻松更改它.

libgdx 中我们使用 y-down 的唯一两个地方是:

The only two places in libgdx where we use y-down are:

  • 像素图坐标(左上角原点,y-down)
  • 在窗口坐标中给出的触摸事件坐标(左上角原点,y-down)

同样,您可以使用相机或一点点矩阵数学轻松地将使用的坐标系更改为您想要的任何坐标系.

Again, you can easily change the used coordinate system to whatever you want using either Camera or a tiny bit of matrix math.

这篇关于在 LibGDX (Java) 中更改坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆