3
所以我有一個轉變的發車位置到全球空間的方法:四元數反轉?
public Vector3 GridToGlobal(IVector3 gridPos)
{
Vector3 globalPos = new Vector3(gridPos.x, gridPos.y, gridPos.z);
globalPos *= Scale;
globalPos = Container.transform.rotation * globalPos;
return globalPos;
}
現在,當我想要做的相反,我將如何去矢量旋轉到電網空間?
public IVector3 GlobalToGrid(Vector3 globalPos)
{
globalPos -= Container.transform.position;
globalPos = Container.transform.rotation * globalPos; //this will obviously rotate in the wrong direction
globalPos /= Scale;
return new IVector3((int)Mathf.Round(globalPos.x), (int)Mathf.Round(globalPos.y), (int)Mathf.Round(globalPos.z));
}
任何想法?