将2种不同的程序从右手软件镜像到左手软件

时间:2016-04-03 10:17:59

标签: c# math unity3d

我正在尝试为基于右手系统参考的左侧系统参考(Unity 3D)的软件镜像一些几何形状。我在两个系统中用C#开发它,一方面是在Visual Studio中开发的程序,另一方面是在Unity3D中开发的程序。下图说明了2种不同的参考系统:

enter image description here

我的代码如下:

右手系统是:

 private  List<Geometry> GetCADFromStation()
    {
        #region GetCADFromStationStep1
        List<Geometry> PartCollection = new List<Geometry>();


        foreach (GraphicComponent component in _ActiveStation.GraphicComponents)
        {
            if (component is Part)
            {
                Geometry p = new Geometry();
                p.Name = component.Name;
                p.TransX = component.Transform.X;
                p.TransY = component.Transform.Y;
                p.TransZ = component.Transform.Z;
                p.RotX = -component.Transform.RX;
                p.RotY = -component.Transform.RY;
                p.RotZ = -component.Transform.RZ;
                PartCollection.Add((Geometry)p);
            }
        }
        #endregion

        return PartCollection;
    }

Unity 3D中的代码是:

 foreach (SerializeSocketUtils.Geometry geo in Pack.geometries)

        {

            float DegreesConverter = (float)(180 / Math.PI);
            Quaternion n;
            n = new Quaternion();


            GameObject value = GameObjectsInScene.Find(item => item.name == geo.Name );
            if (value != null)
            {
                n = ChangeRotationToUnity(new Vector3(((float)geo.RotX * DegreesConverter), ((float)geo.RotY * DegreesConverter), ((float)geo.RotZ * DegreesConverter)));

                value.transform.position = new Vector3(-(float)geo.TransX, (float)geo.TransY, (float)geo.TransZ);
                value.transform.rotation = n;

            }

我在统一方面的重要功能是ChangeRotationToUnity(),如下所示:

  Quaternion ChangeRotationToUnity(Vector3 rotation)
{
    Vector3 flippedRotation = new Vector3(rotation.x, -rotation.y, -rotation.z);
    Quaternion qx = new Quaternion();
    Quaternion qy = new Quaternion();
    Quaternion qz = new Quaternion();
    Quaternion qq = new Quaternion();
    qx = Quaternion.AngleAxis(flippedRotation.x, Vector3.right);
    qy = Quaternion.AngleAxis(flippedRotation.y, Vector3.up);
    qz = Quaternion.AngleAxis(flippedRotation.z, Vector3.forward);
    qq = qz * qy * qx;
    return qq;
}

此功能基于此post和此post

尽管它似乎是合乎逻辑的答案,但它不能正常工作。任何人都可以帮助我吗?

0 个答案:

没有答案