【发布时间】:2016-02-21 19:22:55
【问题描述】:
问题
我想计算从不在炮塔中心的炮塔枪管中射出的子弹的来源。
现状
我有一个带有中心枪管的炮塔,可以从中发射子弹。炮塔位于矢量location 和变化的angle,即。 e.它一直在旋转。为了让中心炮塔从枪管末端发射子弹,我这样计算它的末端:
double speed = 1;
double angle = turret.angle;
// start at the end of the barrel
double x = turret.location.x + Math.cos( angle) * turret.centerCannonLength;
double y = turret.location.y + Math.sin( angle) * turret.centerCannonLength;
// calculate angle and velocity of bullets
double dx = Math.cos(angle) * speed;
double dy = Math.sin(angle) * speed;
从中我可以设置子弹的初始位置和速度:
Bullet bullet = new Bullet();
bullet.setLocation( x, y);
bullet.setVelocity( dx, dy);
bullet.setAngle( angle);
任务
现在我想要另外 2 个枪管,炮塔可以从这些枪管中开火。枪管不在中心,左右偏移。
问题
如何计算左右枪管子弹的来源?
这是一个演示截图:
蓝色圆圈描述炮塔的旋转。黄色部分是炮塔和中心枪管。红色部分是我要计算子弹原点位置的附加左右枪管。
非常感谢您的帮助!
【问题讨论】: