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


C# Vessel.GetFwdVector方法代码示例

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


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

示例1: GetTorque

        public static Vector3d GetTorque(Vessel vessel, float thrust)
        {
            var centerOfMass = vessel.findWorldCenterOfMass();
            var rollaxis = vessel.transform.up;
            rollaxis.Normalize ();
            var pitchaxis = vessel.GetFwdVector ();
            pitchaxis.Normalize ();

            float pitch = 0.0f;
            float yaw = 0.0f;
            float roll = 0.0f;

            foreach (Part part in vessel.parts)
            {
                var relCoM = part.Rigidbody.worldCenterOfMass - centerOfMass;

                foreach (PartModule module in part.Modules)
                {
                    var wheel = module as ModuleReactionWheel;
                    if (wheel == null) continue;

                    pitch += wheel.PitchTorque;
                    yaw += wheel.YawTorque;
                    roll += wheel.RollTorque;
                }
                if (vessel.ActionGroups [KSPActionGroup.RCS])
                {
                    foreach (PartModule module in part.Modules) {
                        var rcs = module as ModuleRCS;
                        if (rcs == null || !rcs.rcsEnabled) continue;

                        bool enoughfuel = rcs.propellants.All(p => (int) (p.totalResourceAvailable) != 0);
                        if (!enoughfuel) continue;
                        foreach (Transform thrustdir in rcs.thrusterTransforms)
                        {
                            float rcsthrust = rcs.thrusterPower;
                            //just counting positive contributions in one direction. This is incorrect for asymmetric thruster placements.
                            roll += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(relCoM, thrustdir.up), rollaxis), 0.0f);
                            pitch += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), pitchaxis), 0.0f);
                            yaw += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), Vector3.Cross(rollaxis,pitchaxis)),0.0f);
                        }
                    }
                }
                pitch += (float)GetThrustTorque(part, vessel) * thrust;
                yaw += (float)GetThrustTorque (part, vessel) * thrust;
            }

            return new Vector3d(pitch, roll, yaw);
        }
开发者ID:space-is-hard,项目名称:KOS,代码行数:49,代码来源:SteeringHelper.cs

示例2: GetTorque

        //from kOS
        public static Vector3d GetTorque(Vessel vessel, float thrust)
        {
            Vector3 centerOfMass = vessel.CoM;
            Vector3 rollaxis = vessel.ReferenceTransform.up;
            rollaxis.Normalize ();
            Vector3 pitchaxis = vessel.GetFwdVector ();
            pitchaxis.Normalize ();

            float pitch = 0.0f;
            float yaw = 0.0f;
            float roll = 0.0f;

            //reaction wheel torque
            foreach(ModuleReactionWheel wheel in vessel.FindPartModulesImplementing<ModuleReactionWheel>())
            {
                if (wheel == null) continue;

                pitch += wheel.PitchTorque;
                yaw += wheel.YawTorque;
                roll += wheel.RollTorque;
            }

            //rcs torque
            if (vessel.ActionGroups [KSPActionGroup.RCS])
            {
                foreach(ModuleRCS rcs in vessel.FindPartModulesImplementing<ModuleRCS>())
                {
                    if (rcs == null || !rcs.rcsEnabled) continue;

                    Vector3 relCoM = rcs.part.Rigidbody.worldCenterOfMass - centerOfMass;

                    bool enoughfuel = rcs.propellants.All(p => (int) (p.totalResourceAvailable) != 0);
                    if (!enoughfuel) continue;
                    foreach (Transform thrustdir in rcs.thrusterTransforms)
                    {
                        float rcsthrust = rcs.thrusterPower;
                        //just counting positive contributions in one direction. This is incorrect for asymmetric thruster placements.
                        roll += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(relCoM, thrustdir.up), rollaxis), 0.0f);
                        pitch += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), pitchaxis), 0.0f);
                        yaw += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), Vector3.Cross(rollaxis,pitchaxis)),0.0f);
                    }
                }
            }

            return new Vector3d(pitch, roll, yaw);
        }
开发者ID:Kerbas-ad-astra,项目名称:BurnTogether,代码行数:47,代码来源:Utils.cs


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