当前位置: 首页>>代码示例>>C#>>正文


C# global.GetTransform方法代码示例

本文整理汇总了C#中global.GetTransform方法的典型用法代码示例。如果您正苦于以下问题:C# global.GetTransform方法的具体用法?C# global.GetTransform怎么用?C# global.GetTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在global的用法示例。


在下文中一共展示了global.GetTransform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: updateState

 public void updateState(global::Vessel vessel)
 {
     _rootRotation = new Quaternion(vessel.GetTransform().rotation);
 }
开发者ID:sopindm,项目名称:bjeb,代码行数:4,代码来源:Vessel.cs

示例2: update

        public void update(global::Vessel vessel)
        {
            centerOfMass = new Vector3(vessel.findWorldCenterOfMass());

            mass = 0;
            torque = new Vector3(0, 0, 0);
            momentumOfInertia = new Vector3(0, 0, 0);
            angularMomentum = new Vector3(0, 0, 0);

            foreach(Part p in vessel.parts)
            {
                if (p.physicalSignificance != Part.PhysicalSignificance.NONE)
                {
                    double partMass = p.mass + p.GetResourceMass();
                    mass += partMass;
                }

                if (p is CommandPod)
                {
                    torque = torque + Vector3.one * Math.Abs(((CommandPod)p).rotPower);
                }

                foreach (PartModule pm in p.Modules)
                {
                    if (!pm.isEnabled) continue;

                    if (pm is ModuleReactionWheel)
                    {
                        ModuleReactionWheel rw = (ModuleReactionWheel)pm;
                        if (rw.wheelState == ModuleReactionWheel.WheelState.Active)
                        {
                            torque = torque + new Vector3(rw.PitchTorque, rw.RollTorque, rw.YawTorque);
                        }
                    }
                }
            }

            var inertiaTensor = new Matrix3x3();

            foreach (Part p in vessel.parts)
            {
                if (p.Rigidbody == null) continue;

                Vector3d principalMoments = p.Rigidbody.inertiaTensor;
                UnityEngine.Quaternion princAxesRot = UnityEngine.Quaternion.Inverse(vessel.GetTransform().rotation) * p.transform.rotation * p.Rigidbody.inertiaTensorRotation;
                UnityEngine.Quaternion invPrincAxesRot = UnityEngine.Quaternion.Inverse(princAxesRot);

                for (int i = 0; i < 3; i++)
                {
                    Vector3d iHat = Vector3d.zero;
                    iHat[i] = 1;
                    for (int j = 0; j < 3; j++)
                    {
                        Vector3d jHat = Vector3d.zero;
                        jHat[j] = 1;
                        inertiaTensor[i, j] += Vector3d.Dot(iHat, princAxesRot * Vector3d.Scale(principalMoments, invPrincAxesRot * jHat));
                    }
                }

                double partMass = p.mass + p.GetResourceMass();
                UnityEngine.Vector3 partPosition = vessel.GetTransform().InverseTransformDirection(p.Rigidbody.worldCenterOfMass - centerOfMass.unity);

                for (int i = 0; i < 3; i++)
                {
                    inertiaTensor[i, i] += partMass * partPosition.sqrMagnitude;

                    for (int j = 0; j < 3; j++)
                    {
                        inertiaTensor[i, j] += -partMass * partPosition[i] * partPosition[j];
                    }
                }
            }

            momentumOfInertia = new Vector3(inertiaTensor[0, 0], inertiaTensor[2, 2], inertiaTensor[1, 1]);

            Vector3 angularVelocity = new Quaternion(vessel.GetTransform().rotation).inverse * new Vector3(vessel.rigidbody.angularVelocity);

            angularMomentum = inertiaTensor * angularVelocity;
            angularMomentum = new Vector3(angularMomentum.x, angularMomentum.z, angularMomentum.y);
        }
开发者ID:sopindm,项目名称:bjeb,代码行数:80,代码来源:Vessel.cs


注:本文中的global.GetTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。