旋转后的Libgdx坐标

旋转后的Libgdx坐标

本文介绍了旋转后的Libgdx坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旋转相机后,坐标使我感到困惑.

After the camera rotation, the coordinates were confusing to me.

我有一个照相机,一个角色和一张地图.该玩家只能朝以下方向行走:北(90°),南(270°),东(0°),西(180°).

I have a camera a character and a map.This player walks only in the directions: north (90 °), south (270 °), east (0 °), west (180 °).

从播放器"camera.rotateAround(...,...,...)"的位置旋转了相机之后,由于旋转,播放器开始朝新的方向移动.

After rotating the camera from the position of the player 'camera.rotateAround (..., ..., ...)' the player starts to move in new directions as a result of rotation.

有没有一种方法可以将原始位置重新定位到坐标,而无需将地图移动到原始位置?

Is there a way to reposition the original back to the coordinates without moving the map to the original position?

  • 注意:轨迹图是临时的,因此具有这些松散粘合的边缘.

感谢您的帮助.

推荐答案

首先,您需要存储地图的旋转角度.然后,当玩家移动时,您需要考虑地图的旋转角度.

First you need to store rotation angle of map.Then when player moves you need to take account rotation angle of map.

camera.rotatearound(...)//I guess you rotating +90 or -90 in this game
maprotation+=... //+90 or -90 depends on side you turn.
//i ll assume rotation direction is counter clock wise.

现在您知道旋转了,因此可以使用三角函数设置播放器的运动.

Now you know rotation so you can set player movement with a trigonometry.

在player.moveup(float maprotation)方法中或您编写用于向北移动的代码的任何地方.

in player.moveup(float maprotation) method or whereever you wrote codes for moving to north.

x+=MathUtils.cosDeg(90-maprotation)*speed;//90 degree for moving up
y+=MathUtils.sinDeg(90-maprotation)*speed;// - maprotation for correction

如您所见,当相机旋转时,方向也会旋转.因此,您只需要减去地图旋转即可进行校正.

As you can see when camera rotating also directions rotating. So you just need to subtract map rotation to correct.

这篇关于旋转后的Libgdx坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 18:02