根据雷达的中心X,Y的角度移动X,Y位置 [英] Move X,Y Position based on an angle of center X,Y for a Radar

查看:105
本文介绍了根据雷达的中心X,Y的角度移动X,Y位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏中有雷达。现在,雷达使用静态X,Y图形,根据你在游戏中的表现不会旋转。



我希望X,Y位置在雷达根据你所面对的方向旋转。你面前的怪物将始终出现在雷达顶部。



现在,雷达是静止的,你北方的怪物将始终出现在北方雷达。



目前,我有这样的数学:



I have a radar in my game. Right now the radar works using a static X,Y graph that does not rotate based on how you are facing in my game.

I want the X, Y positions on the radar to rotate based on the direction you are facing. Monsters in the front of you will always appear at the top of the radar.

Right now, the radar is static and monsters north of you will always appear north on the radar.

Currently, I have math like this:

int x = (int)(x * Math.Cos(Math.PI * angle / 180) + y * Math.Sin(Math.PI * angle / 180));
int y = (int)(y * Math.Cos(Math.PI * angle / 180) - x * Math.Sin(Math.PI * angle / 180));





然后我将中心X和中心Y添加到上面的整数,但图形很奇怪,似乎只能从359度角度工作。我尝试在计算之前添加我的中心X和中心Y,但它总是关闭。



我在网上找到的其他代码根据度数/角度区分。





Then I add the center X and center Y to the integers above, but the graph is weird and only seems to work from 359~ degree angle. I have tried adding my center X and center Y before calculating it, but it is always off.

Other code I found online differentiated based on the degrees/angle.

if (angle >= 0 && angle <= 180)
{
x = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
}
else
{
x = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
}





我需要乘坐中心X(cX),中心Y(cY)的正确公式是什么,我面对的角度和目标X(tX),目标Y(tY)重新定位目标X& Y.



What is the correct formula I need to take the Center X(cX), center Y(cY), the angle I am facing and the target X(tX), target Y(tY) to relocate the targets X & Y.

推荐答案

x2 = (int)((x) * Math.Cos(Math.PI * angle / 180) - (y - player_y) * Math.Sin(Math.PI * angle / 180));
y2 = (int)((x) * Math.Sin(Math.PI * angle / 180) + (y - player_y) * Math.Cos(Math.PI * angle / 180));
x2 = x2 + centerX;
y2 = y2 + centerY;


这篇关于根据雷达的中心X,Y的角度移动X,Y位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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