坦克履带需要在坦克的两侧,坦克可以面对360度旋转。这里有一张图片来解释这一点:
http://imgur.com/ySFTk
坦克履带目前只是水平偏移,我正试着沿着坦克的核心垂直偏移它们(不起作用)。
以下是我到目前为止所做的工作:
private void tracksPosition()
{
_DegreeToRadien = Math.toRadians(_degrees);
_ObjectXCenter = (int) (_object_x + ((_itemAnimation.getWidth() / 2)) - _trackAnimationLeft.getWidth() / 2);
_ObjectYCenter = (int) (_object_y + ((_itemAnimation.getHeight() / 2)) - _trackAnimationLeft.getHeight() / 2);
//For left track
_xOffset = -1 * (_itemAnimation.getHeight() / 2);
_trackLeftPosition.set
(
(int)(((_xOffset) * Math.cos(_DegreeToRadien / 2)) + _ObjectXCenter),
(int)(((_xOffset) * Math.sin(_DegreeToRadien / 2)) + _ObjectYCenter)
);它使用X偏移量工作,但由于某些原因,我无法计算出Y偏移量,否则它会变得奇怪。
//-答案-/对于那些想知道我是如何做到这一点的人,这里是答案:
//For left track
//Decide how far away the track is from the tank
_xOffset = _itemAnimation.getHeight() / 1.5;
//Decide where the track is horizontally to the tank (Ie front, back)
_DegreeToRadien = Math.toRadians(_degrees + 110);
//Set the point of the track, takes the centre of the tank and adds the current position, cos and sin basically divide (though multiplication) the current position according to the direction the tank is facing.
_trackLeftPosition.set
(
_ObjectXCenter + (int)(_xOffset * Math.cos(_DegreeToRadien))
,
_ObjectYCenter + (int)(_xOffset * Math.sin(_DegreeToRadien))
);发布于 2012-04-24 03:01:14
对于那些想知道我是如何做到这一点的人,这里有一个答案:
//For left track
//Decide how far away the track is from the tank
_xOffset = _itemAnimation.getHeight() / 1.5;
//Decide where the track is horizontally to the tank (Ie front, back)
_DegreeToRadien = Math.toRadians(_degrees + 110);
//Set the point of the track, takes the centre of the tank and adds the current position, cos and sin basically divide (though multiplication) the current position according to the direction the tank is facing.
_trackLeftPosition.set
(
_ObjectXCenter + (int)(_xOffset * Math.cos(_DegreeToRadien))
,
_ObjectYCenter + (int)(_xOffset * Math.sin(_DegreeToRadien))
);发布于 2012-04-22 22:12:39
我需要更多的信息来帮助我,但是:
,
,
编辑:
此链接显示如何绕原点旋转点。http://en.wikipedia.org/wiki/Rotation_matrix
如果将坦克的组件表示为相对于原点的一系列顶点,则可以系统地对每个点应用旋转。然后,在这些点之间绘制直线以形成旋转的形状是一件很小的事情。例如,如果您的坦克是方形的,则可以确定其顶点位于(1,1)、(-1,1)、(-1,-1)和(1,-1)。您的轨迹可能是相似的,但左边的轨迹可能是(-1,1.25),(-1.25,1.25),(-1.25,-1.25),(-1,-1.25)。相同的旋转矩阵可以正确地旋转它们。这将使它们围绕原点旋转。这不是你想要的,但这是一个开始。
然后,要获得x-y轴上的平移,只需将X和Y坐标添加到坦克的整体X-Y坐标。
我没有时间刷新我的记忆,但机会是稍微大一点的矩阵也可以做翻译。所以输入基坐标、旋转和所需的(x,y),最后的点坐标就出来了。
这可能看起来更复杂,但你的代码会更小,更不容易出错。
https://stackoverflow.com/questions/10268425
复制相似问题