Libgdx Coordinates after rotateAround camera

℡╲_俬逩灬. 提交于 2019-12-24 02:18:35

问题


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

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

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?

  • Note: The track map is temporary then have these loosely glued edges.

I appreciate the help.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/38975166/libgdx-coordinates-after-rotatearound-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!