Ejemplo n.º 1
0
 public FlightAttitude(string desc)
 {
     switch(desc)
     {
     case "srfRetrograde":
         frame = ReferenceFrame.Surface;
         attitude = RelativeAttitude.Retrograde;
         break;
     case "orbRetrograde":
         frame = ReferenceFrame.Orbit;
         attitude = RelativeAttitude.Retrograde;
         break;
     case "srfPrograde":
         frame = ReferenceFrame.Surface;
         attitude = RelativeAttitude.Prograde;
         break;
     case "orbPrograde":
         frame = ReferenceFrame.Orbit;
         attitude = RelativeAttitude.Prograde;
         break;
     case "srfVertical":
         frame = ReferenceFrame.Surface;
         attitude = RelativeAttitude.Vertical;
         break;
     case "orbVertical":
     default:
         frame = ReferenceFrame.Orbit;
         attitude = RelativeAttitude.Vertical;
         break;
     };
 }
Ejemplo n.º 2
0
 public FlightAttitude(double hdg, double pitch)
 {
     frame = ReferenceFrame.North;
     attitude = RelativeAttitude.CustomHP;
     Hdg = hdg;
     Pitch = pitch;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the rotation for the given frame of reference.
 /// Applying the rotation to a vector in reference-frame-space produces the corresponding vector in world-space.
 /// </summary>
 public static QuaternionD GetRotation(ReferenceFrame referenceFrame, Vessel vessel)
 {
     if (referenceFrame == ReferenceFrame.Docking) {
         var target = FlightGlobals.fetch.VesselTarget;
         if (target != null && target is ModuleDockingNode) {
             // Who knows why this Quaternion.Euler(90, 0, 0) rotation is required?
             // Note that the delta-calculation in AutoPilotAddon seems to reverse this rotation.
             // So it seems like a problem with what Quaternion.LookRotation does.
             // FIXME: Uses single precision floating point
             return (target as ModuleDockingNode).transform.rotation * Quaternion.Euler (90, 0, 0);
         } else {
             return GetRotation (ReferenceFrame.Target, vessel);
         }
     }
     var forward = GetForwardNotNormalized (referenceFrame, vessel);
     // Note: forward is along the z-axis, up is along the negative y-axis
     var up = -GetUpNotNormalized (referenceFrame, vessel);
     //FIXME: Vector3d.OrthoNormalize and QuaternionD.LookRotation methods are not found at run-time
     //Vector3d.OrthoNormalize (ref forward, ref up);
     //return QuaternionD.LookRotation (forward, up);
     Vector3 forward2 = forward;
     Vector3 up2 = up;
     Vector3.OrthoNormalize (ref forward2, ref up2);
     return Quaternion.LookRotation (forward2, up2);
 }
Ejemplo n.º 4
0
 internal Force (Part part, Tuple3 forceVector, Tuple3 forcePosition, ReferenceFrame referenceFrame)
 {
     Part = part;
     force = forceVector.ToVector ();
     position = forcePosition.ToVector ();
     ReferenceFrame = referenceFrame;
 }
Ejemplo n.º 5
0
 public FlightAttitude(double hdg, double pitch, double roll)
 {
     frame = ReferenceFrame.North;
     attitude = RelativeAttitude.CustomHPR; // this doesn't seem to have a working roll reference
     Hdg = hdg;
     Pitch = pitch;
     Roll = roll;
 }
Ejemplo n.º 6
0
    // Use this for initialization
    private void Start()
    {
        referenceFrame = GetComponentInParent<ReferenceFrame>();

        margin = this.renderer.bounds.size;
        topBound = ScreenBounds.Top + margin.y;
        bottomBound = ScreenBounds.Bottom - margin.y;
        leftBound = ScreenBounds.Left - margin.x;
        rightBound = ScreenBounds.Right + margin.x;
    }
Ejemplo n.º 7
0
 internal static void AddDirection(Vector3 direction, ReferenceFrame referenceFrame, Tuple3 color, float length)
 {
     var obj = new GameObject ("direction");
     var line = obj.AddComponent<LineRenderer> ();
     line.useWorldSpace = true;
     line.material = new Material (Shader.Find ("Particles/Additive"));
     line.SetWidth (0.25f, 0.25f);
     line.SetVertexCount (2);
     line.SetPosition (0, Vector3d.zero);
     line.SetPosition (1, Vector3d.zero);
     var rgbColor = new Color ((float)color.Item1, (float)color.Item2, (float)color.Item3);
     line.SetColors (rgbColor, rgbColor);
     directions.Add (new Direction (KRPC.KRPCServer.Context.RPCClient, obj, line, direction, length, referenceFrame));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns the velocity of the reference frame in world-space.
 /// </summary>
 public static Vector3d GetVelocity(ReferenceFrame referenceFrame, Vessel vessel)
 {
     switch (referenceFrame) {
     case ReferenceFrame.Orbital:
     case ReferenceFrame.Maneuver:
         return Vector3d.zero;
     // Relative to the surface velocity vector
     case ReferenceFrame.Surface:
         return ((Vector3d)vessel.GetObtVelocity ()) - ((Vector3d)vessel.GetSrfVelocity ());
     // Relative to the target's velocity vector, or relative to the orbit if there is no target
     case ReferenceFrame.Target:
         throw new NotImplementedException ();
     // Relative to the negative surface normal of the target docking port, or relative to the target if the target is not a docking port
     case ReferenceFrame.Docking:
         throw new NotImplementedException ();
     default:
         throw new ArgumentException ("No such reference frame");
     }
 }
Ejemplo n.º 9
0
        public void mapFlightMode(FlightMode flightMode, FlightAttitude flightAttitude, ReferenceFrame frame)
        {
            computerMode = ComputerMode.Off;
            computerAttitude = flightAttitude;

            switch (flightMode)
            {
                case FlightMode.Off: { computerMode = ComputerMode.Off; break; }
                case FlightMode.KillRot: { computerMode = ComputerMode.Kill; break; }
                case FlightMode.AttitudeHold:
                {
                    computerMode = ComputerMode.Custom;
                    switch (frame)
                    {
                        case ReferenceFrame.Maneuver: { computerMode = ComputerMode.Node; break; }
                        case ReferenceFrame.Orbit: { computerMode = ComputerMode.Orbital; break; }
                        case ReferenceFrame.Surface: { computerMode = ComputerMode.Surface; break; }
                        case ReferenceFrame.TargetParallel: { computerMode = ComputerMode.TargetPos; break; }
                        case ReferenceFrame.TargetVelocity: { computerMode = ComputerMode.TargetVel; break; }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 10
0
 double startBurnAlt(ReferenceFrame srfFrame)
 {
     return((vessel.Flight(srfFrame).Speed *vessel.Flight(srfFrame).Speed) / (GetTWR() * GetTWR()));
 }
Ejemplo n.º 11
0
 public ConstraintVelocity(Body body, ReferenceFrame frame, Vector3?vel, Vector3?angVel)
 {
     Initialise(body, frame, vel, angVel);
 }
Ejemplo n.º 12
0
 public Tuple4 Rotation(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.RotationToWorldSpace(InternalPart.transform.rotation).ToTuple());
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Update the text.
 /// </summary>
 public override void Update()
 {
     renderer.enabled            = Visible;
     renderer.transform.position = ReferenceFrame.PositionToWorldSpace(position);
     renderer.transform.rotation = ReferenceFrame.RotationToWorldSpace(rotation);
 }
Ejemplo n.º 14
0
        void CreateHybrid()
        {
            var relative = ReferenceFrame.CreateRelative(connection, reference_, targetPosition.ToTuple());

            hybrid = ReferenceFrame.CreateHybrid(connection, relative, surfaceRef);
        }
Ejemplo n.º 15
0
 public Vector3 getAngularVelocity()
 {
     return(tupleToVec3(Vessel.AngularVelocity(ReferenceFrame.CreateHybrid(Vessel.connection, Vessel.ReferenceFrame, Vessel.ReferenceFrame, nonRotatingRefFrame, nonRotatingRefFrame))));
 }
Ejemplo n.º 16
0
 public static Polygon AddPolygon (IList<Tuple3> vertices, ReferenceFrame referenceFrame, bool visible = true)
 {
     return new Polygon (vertices.Select (x => x.ToVector ()).ToList (), referenceFrame, visible);
 }
Ejemplo n.º 17
0
 public static Line AddDirection (Tuple3 direction, ReferenceFrame referenceFrame, float length = 10f, bool visible = true)
 {
     return new Line (Vector3d.zero, direction.ToVector () * length, referenceFrame, visible);
 }
Ejemplo n.º 18
0
 public static Line AddLine (Tuple3 start, Tuple3 end, ReferenceFrame referenceFrame, bool visible = true)
 {
     return new Line (start.ToVector (), end.ToVector (), referenceFrame, visible);
 }
Ejemplo n.º 19
0
 public static void DrawLine(Tuple3 start, Tuple3 end, ReferenceFrame referenceFrame, Tuple3 color)
 {
     DrawAddon.AddLine (start.ToVector (), end.ToVector (), referenceFrame, color);
 }
Ejemplo n.º 20
0
    // Use this for initialization
    private void Start()
    {
        if (searchForSpecialBehavior) specialBehavior = GetComponent<SpawnBehavior>();

        referenceFrame = GetComponentInParent<ReferenceFrame>();

        randomChoice = new RandomChoice(spawnables);

        if (spawnAtWakeUp.Length != 0) {
            for (var i = 0; i < spawnAtWakeUp.Length; i++) {
                for (var j = 0; j < spawnAtWakeUp[i].quantity; j++) {
                    Spawn(spawnAtWakeUp[i].element);
                }
            }
        }

        StartCoroutine(WaitAndSpawn());
    }
Ejemplo n.º 21
0
 /// <summary>
 /// Returns the forward vector for the given reference frame in world coordinates.
 /// The resulting vector is not normalized.
 /// </summary>
 static Vector3d GetForwardNotNormalized(ReferenceFrame referenceFrame, Vessel vessel)
 {
     switch (referenceFrame) {
     // Relative to the orbital velocity vector
     //case ReferenceFrame.Orbital:
     //    return vessel.GetObtVelocity ();
     // Relative to the surface velocity vector
     //case ReferenceFrame.Surface:
     //    return vessel.GetSrfVelocity ();
     // Relative to the surface / navball
     case ReferenceFrame.Orbital:
     case ReferenceFrame.Surface:
         {
             var up = GetUp (referenceFrame, vessel);
             var exclude = vessel.mainBody.position + ((Vector3d)vessel.mainBody.transform.up) * vessel.mainBody.Radius - ((Vector3d)vessel.CoM);
             return Vector3d.Exclude (up, exclude);
         }
     // Relative to the direction of the burn for a maneuver node, or relative to the orbit if there is no node
     case ReferenceFrame.Maneuver:
         {
             if (vessel.patchedConicSolver.maneuverNodes.Count > 0)
                 return vessel.patchedConicSolver.maneuverNodes [0].GetBurnVector (vessel.orbit);
             else
                 return GetForward (ReferenceFrame.Orbital, vessel);
         }
     // Relative to the target's velocity vector, or relative to the orbit if there is no target
     case ReferenceFrame.Target:
         {
             var target = FlightGlobals.fetch.VesselTarget;
             if (target != null)
                 return ((Vector3d)vessel.GetObtVelocity ()) - ((Vector3d)target.GetObtVelocity ());
             else
                 return GetForward (ReferenceFrame.Orbital, vessel);
         }
     // Relative to the direction to the target, or relative to the orbit if there is no target
     //case ReferenceFrame.Target:
     //    {
     //        var target = FlightGlobals.fetch.VesselTarget;
     //        if (target != null)
     //            // TODO: use the center of control instead of v.CoM?
     //            return target.GetTransform ().position - vessel.CoM;
     //        else
     //            return GetForward (ReferenceFrame.Orbital, vessel);
     //    }
     // Relative to the negative surface normal of the target docking port, or relative to the target if the target is not a docking port
     case ReferenceFrame.Docking:
         throw new NotImplementedException ();
     default:
         throw new ArgumentException ("No such reference frame");
     }
 }
Ejemplo n.º 22
0
 public static Tuple3 TransformPosition(Tuple3 position, ReferenceFrame from, ReferenceFrame to)
 {
     return to.PositionFromWorldSpace (from.PositionToWorldSpace (position.ToVector ())).ToTuple ();
 }
Ejemplo n.º 23
0
        public static void HoldAttitude(FlightCtrlState fs, FlightComputer f, ReferenceFrame frame, FlightAttitude attitude, Quaternion extra)
        {
            var v = f.Vessel;
            var forward = Vector3.zero;
            var up = Vector3.zero;
            bool ignoreRoll = false;

            switch (frame)
            {
                case ReferenceFrame.Orbit:
                    ignoreRoll = true;
                    forward = v.GetObtVelocity();
                    up = (v.mainBody.position - v.CoM);
                    break;

                case ReferenceFrame.Surface:
                    ignoreRoll = true;
                    forward = v.GetSrfVelocity();
                    up = (v.mainBody.position - v.CoM);
                    break;

                case ReferenceFrame.North:
                    up = (v.mainBody.position - v.CoM);
                    forward = Vector3.ProjectOnPlane(v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius - v.CoM, up);
                    break;

                case ReferenceFrame.Maneuver:
                    ignoreRoll = true;
                    if (f.Vessel.patchedConicSolver.maneuverNodes.Count != 0)
                    {
                        forward = f.Vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(v.orbit);
                        up = (v.mainBody.position - v.CoM);
                    }
                    else
                    {
                        forward = v.GetObtVelocity();
                        up = (v.mainBody.position - v.CoM);
                    }
                    break;

                case ReferenceFrame.TargetVelocity:
                    // f.DelayedTarget may be any ITargetable, including a planet
                    // Velocity matching only makes sense for vessels and part modules
                    // Can test for Vessel but not PartModule, so instead test that it's not the third case (CelestialBody)
                    if (f.DelayedTarget != null && !(f.DelayedTarget is CelestialBody))
                    {
                        forward = v.GetObtVelocity() - f.DelayedTarget.GetObtVelocity();
                        up = (v.mainBody.position - v.CoM);
                    }
                    else
                    {
                        up = (v.mainBody.position - v.CoM);
                        forward = v.GetObtVelocity();
                    }
                    break;

                case ReferenceFrame.TargetParallel:
                    if (f.DelayedTarget != null && !(f.DelayedTarget is CelestialBody))
                    {
                        forward = f.DelayedTarget.GetTransform().position - v.CoM;
                        up = (v.mainBody.position - v.CoM);
                    }
                    else
                    {
                        up = (v.mainBody.position - v.CoM);
                        forward = v.GetObtVelocity();
                    }
                    break;
            }
            Vector3.OrthoNormalize(ref forward, ref up);
            Quaternion rotationReference = Quaternion.LookRotation(forward, up);
            
            switch (attitude)
            {
                case FlightAttitude.Prograde:
                    break;

                case FlightAttitude.Retrograde:
                    rotationReference = rotationReference * Quaternion.AngleAxis(180, Vector3.up);
                    break;

                case FlightAttitude.NormalPlus:
                    rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.up);
                    break;

                case FlightAttitude.NormalMinus:
                    rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.down);
                    break;

                case FlightAttitude.RadialPlus:
                    rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.right);
                    break;

                case FlightAttitude.RadialMinus:
                    rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.left);
                    break;

                case FlightAttitude.Surface:
                    rotationReference = rotationReference * extra;
                    break;
            }
            HoldOrientation(fs, f, rotationReference, ignoreRoll);
        }
Ejemplo n.º 24
0
 public static Text AddText (string text, ReferenceFrame referenceFrame, Tuple3 position, Tuple4 rotation, bool visible = true)
 {
     return new Text (text, referenceFrame, position.ToVector (), rotation.ToQuaternion (), visible);
 }
        private void OnLoad(object sender, EventArgs e)
        {
            // Create overlay toolbar and panels
            m_overlayToolbar = new OverlayToolbar(m_insight3D);
            m_overlayToolbar.Overlay.Origin = ScreenOverlayOrigin.BottomCenter;

            // Add additional toolbar buttons

            // Number of Satellites Button
            m_overlayToolbar.AddButton(GetDataFilePath("Textures/OverlayToolbar/manysatellites.png"),
                                       GetDataFilePath("Textures/OverlayToolbar/fewsatellites.png"),
                                       ToggleNumberOfSatellites);

            // Show/Hide Access Button
            m_overlayToolbar.AddButton(GetDataFilePath("Textures/OverlayToolbar/noshowaccess.png"),
                                       GetDataFilePath("Textures/OverlayToolbar/showaccess.png"),
                                       ToggleComputeAccess);

            // Initialize the text panel
            m_textPanel = new TextureScreenOverlay(0, 0, 80, 35)
            {
                Origin             = ScreenOverlayOrigin.TopRight,
                BorderSize         = 2,
                BorderColor        = Color.Transparent,
                BorderTranslucency = 0.6f,
                Color        = Color.Transparent,
                Translucency = 0.4f
            };
            SceneManager.ScreenOverlays.Add(m_textPanel);

            // Show label for the moon
            Scene scene = m_insight3D.Scene;

            scene.CentralBodies[CentralBodiesFacet.GetFromContext().Moon].ShowLabel = true;

            // Create a marker primitive for the facility at Bells Beach Australia
            EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

            Cartographic facilityPosition = new Cartographic(Trig.DegreesToRadians(144.2829), Trig.DegreesToRadians(-38.3697), 0.0);

            Texture2D facilityTexture = SceneManager.Textures.FromUri(GetDataFilePath(@"Markers\Facility.png"));

            MarkerBatchPrimitive marker = new MarkerBatchPrimitive(SetHint.Infrequent)
            {
                Texture = facilityTexture
            };

            marker.Set(new[] { earth.Shape.CartographicToCartesian(facilityPosition) });

            SceneManager.Primitives.Add(marker);

            PointCartographic point     = new PointCartographic(earth, facilityPosition);
            Axes           topographic  = new AxesNorthEastDown(earth, point);
            ReferenceFrame facilityTopo = new ReferenceFrame(point, topographic);

            m_fixedToFacilityTopoEvaluator = GeometryTransformer.GetReferenceFrameTransformation(earth.FixedFrame, facilityTopo);
            Axes temeAxes = earth.TrueEquatorMeanEquinoxFrame.Axes;

            m_temeToFixedEvaluator = GeometryTransformer.GetAxesTransformation(temeAxes, earth.FixedFrame.Axes);
            m_showAccess           = true;
            m_satellites           = new Satellites();
            CreateSatellites("stkSatDb");

            // This Render() is needed so that the stars will show.
            scene.Render();
        }
Ejemplo n.º 26
0
 public static Text AddText(string text, ReferenceFrame referenceFrame, Tuple3 position, Tuple4 rotation, bool visible = true)
 {
     return(new Text(text, referenceFrame, position.ToVector(), rotation.ToQuaternion(), visible));
 }
Ejemplo n.º 27
0
        public void Initialise(Body body, ReferenceFrame frame, Vector3? vel, Vector3? angVel)
        {
            this.body = body;
            this.frame = frame;

            this.doVel = (vel != null);
            this.doAngVel = (angVel != null);

            if (doVel) targetVel = (Vector3)vel;
            if (doAngVel) targetAngVel = (Vector3)angVel;

            if (body != null)
            {
                vel = body.Velocity;
                angVel = body.AngularVelocity;
            }
            else
            {
                vel = Vector3.Zero;
                angVel = Vector3.Zero;
            }

            velRate = Vector3.Zero;
            angVelRate = Vector3.Zero;

            if (body != null)
                body.AddConstraint(this);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Returns the up vector for the given reference frame in world coordinates.
 /// The resulting vector is not normalized.
 /// </summary>
 static Vector3d GetUpNotNormalized(ReferenceFrame referenceFrame, Vessel vessel)
 {
     switch (referenceFrame) {
     case ReferenceFrame.Orbital:
     case ReferenceFrame.Surface:
     case ReferenceFrame.Maneuver:
     case ReferenceFrame.Target:
         return ((Vector3d)vessel.CoM) - vessel.mainBody.position;
     // Relative to the negative surface normal of the target docking port, or relative to the target if the target is not a docking port
     case ReferenceFrame.Docking:
         throw new NotImplementedException ();
     default:
         throw new ArgumentException ("No such reference frame");
     }
 }
Ejemplo n.º 29
0
 public Tuple3 Direction(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.DirectionFromWorldSpace(InternalPart.transform.up).ToTuple());
 }
Ejemplo n.º 30
0
 public override void Start()
 {
     data     = GetOrAddComponent <CommonDataStream>();
     orbitRef = vessel.Orbit.Body.ReferenceFrame;
 }
Ejemplo n.º 31
0
 public static Tuple3 TransformDirection (Tuple3 direction, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames (from, to);
     return to.DirectionFromWorldSpace (from.DirectionToWorldSpace (direction.ToVector ())).ToTuple ();
 }
Ejemplo n.º 32
0
        //#####################################################################
        /// <summary>
        /// 根据星历表,创建新的PathPrimitive</para>
        /// </summary>
        /// <param name="ephemeris">卫星星历数据</param>
        /// <param name="frame">参考系</param>
        public static PathPrimitive CreatePathPrimitiveFromEphemeris(DateMotionCollection <Cartesian> ephemeris, ReferenceFrame frame)
        {
            try
            {
                List <PathPoint> points = new List <PathPoint>();
                for (int i = 0; i < ephemeris.Count; i++)
                {
                    points.Add(new PathPointBuilder(ephemeris.Values[i], ephemeris.Dates[i], Color.Yellow).ToPathPoint());
                }

                PathPrimitive pathPrimitive = new PathPrimitive();
                //pathPrimitive.UpdatePolicy = new DurationPathPrimitiveUpdatePolicy(new Duration(0, 60), PathPrimitiveRemoveLocation.RemoveLocationFront);
                pathPrimitive.ReferenceFrame = frame;
                //pathPrimitive.AddRangeToFront(points);
                pathPrimitive.AddRangeToBack(points);
                pathPrimitive.Width = 3.0F;

                SceneManager.Animation.Time = ephemeris.Dates[0];
                return(pathPrimitive);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n" + "向3D图中画卫星轨迹出错!");
            }
        }
Ejemplo n.º 33
0
Archivo: Orbit.cs Proyecto: 602p/krpc
 public static Tuple3 ReferencePlaneNormal(ReferenceFrame referenceFrame)
 {
     return referenceFrame.DirectionFromWorldSpace (Planetarium.up).normalized.ToTuple ();
 }
Ejemplo n.º 34
0
        /// <summary>
        /// 从Table表中,创建新的PathPrimitive
        /// <para>表中提供的位置、速度要与参考系一致</para>
        /// </summary>
        /// <param name="dt">表名</param>
        /// <param name="colNames">表列名称(t,x,y,z,Vx,Vy,Vz)</param>
        /// <param name="frame">坐标系</param>
        /// <returns></returns>
        public static PathPrimitive CreatePathPrimitiveFromTable(DataTable dt, JulianDate jd0, string[] colNames, ReferenceFrame frame)
        {
            try
            {
                DateMotionCollection <Cartesian> ephemeris = new DateMotionCollection <Cartesian> ();

                //将Table中的相应参数读入
                JulianDate jd;
                Cartesian  R, V;
                foreach (DataRow dr in dt.Rows)
                {
                    jd = jd0.AddSeconds((double)dr[colNames[0]]);
                    R  = new Cartesian((double)dr[colNames[1]], (double)dr[colNames[2]], (double)dr[colNames[3]]);
                    V  = new Cartesian((double)dr[colNames[4]], (double)dr[colNames[5]], (double)dr[colNames[6]]);
                    ephemeris.Add(jd, R, V);
                }

                return(CreatePathPrimitiveFromEphemeris(ephemeris, frame));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n" + "从Table中创建PathPrimitive出错!");
            }
        }
Ejemplo n.º 35
0
        public static void HoldAttitude(FlightCtrlState fs, FlightComputer f, ReferenceFrame frame, FlightAttitude attitude, Quaternion extra)
        {
            var v                 = f.Vessel;
            var forward           = Vector3.zero;
            var up                = Vector3.zero;
            var rotationReference = Quaternion.identity;

            switch (frame)
            {
            case ReferenceFrame.Orbit:
                forward = v.GetObtVelocity();
                up      = (v.mainBody.position - v.CoM);
                break;

            case ReferenceFrame.Surface:
                forward = v.GetSrfVelocity();
                up      = (v.mainBody.position - v.CoM);
                break;

            case ReferenceFrame.North:
                up      = (v.mainBody.position - v.CoM);
                forward = Vector3.Exclude(up,
                                          v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius - v.CoM
                                          );
                break;

            case ReferenceFrame.Maneuver:
                up = v.transform.up;
                if (f.DelayedManeuver != null)
                {
                    forward = f.DelayedManeuver.GetBurnVector(v.orbit);
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    forward = v.GetObtVelocity();
                    up      = (v.mainBody.position - v.CoM);
                }
                break;

            case ReferenceFrame.TargetVelocity:
                if (f.DelayedTarget != null && f.DelayedTarget is Vessel)
                {
                    forward = v.GetObtVelocity() - f.DelayedTarget.GetObtVelocity();
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    up      = (v.mainBody.position - v.CoM);
                    forward = v.GetObtVelocity();
                }
                break;

            case ReferenceFrame.TargetParallel:
                if (f.DelayedTarget != null && f.DelayedTarget is Vessel)
                {
                    forward = f.DelayedTarget.GetTransform().position - v.CoM;
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    up      = (v.mainBody.position - v.CoM);
                    forward = v.GetObtVelocity();
                }
                break;
            }
            Vector3.OrthoNormalize(ref forward, ref up);
            rotationReference = Quaternion.LookRotation(forward, up);
            switch (attitude)
            {
            case FlightAttitude.Prograde:
                break;

            case FlightAttitude.Retrograde:
                rotationReference = rotationReference * Quaternion.AngleAxis(180, Vector3.up);
                break;

            case FlightAttitude.NormalPlus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.up);
                break;

            case FlightAttitude.NormalMinus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.down);
                break;

            case FlightAttitude.RadialPlus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.right);
                break;

            case FlightAttitude.RadialMinus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.left);
                break;

            case FlightAttitude.Surface:
                rotationReference = rotationReference * extra;
                break;
            }
            HoldOrientation(fs, f, rotationReference);
        }
Ejemplo n.º 36
0
        private void addStream(DataType type)
        {
            // Some much used variables
            spaceCenter = connection.SpaceCenter();

            vessel          = connection.SpaceCenter().ActiveVessel;
            control         = connection.SpaceCenter().ActiveVessel.Control;
            orbit           = connection.SpaceCenter().ActiveVessel.Orbit;
            resources       = connection.SpaceCenter().ActiveVessel.Resources;
            resources_stage = connection.SpaceCenter().ActiveVessel.ResourcesInDecoupleStage(stage, false);

            inertialRefFrame = orbit.Body.NonRotatingReferenceFrame;
            surfaceRefFrame  = vessel.SurfaceReferenceFrame;
            mapRefFrame      = orbit.Body.ReferenceFrame;

            inertFlight = connection.SpaceCenter().ActiveVessel.Flight(inertialRefFrame);
            flight      = connection.SpaceCenter().ActiveVessel.Flight(surfaceRefFrame);
            mapFlight   = connection.SpaceCenter().ActiveVessel.Flight(mapRefFrame);


            Kstream stream;

            switch (type)
            {
            ///// BODY DATA /////
            case DataType.body_radius:
                stream = new floatStream(connection.AddStream(() => orbit.Body.EquatorialRadius));
                break;

            case DataType.body_gravityParameter:
                stream = new floatStream(connection.AddStream(() => orbit.Body.GravitationalParameter));
                break;

            case DataType.body_rotSpeed:
                stream = new floatStream(connection.AddStream(() => orbit.Body.RotationalSpeed));
                break;

            case DataType.body_name:
                stream = new stringStream(connection.AddStream(() => orbit.Body.Name));
                break;

            case DataType.body_mass:
                stream = new floatStream(connection.AddStream(() => orbit.Body.Mass));
                break;

            case DataType.body_rotPeriod:
                stream = new floatStream(connection.AddStream(() => orbit.Body.RotationalPeriod));
                break;

            case DataType.body_nonRotatingReferenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => orbit.Body.NonRotatingReferenceFrame));
                break;

            ///// CONTROL DATA /////

            case DataType.control_SAS:
                stream = new boolStream(connection.AddStream(() => control.SAS));
                break;

            case DataType.control_SASmode:
                stream = new sasModeStream(connection.AddStream(() => control.SASMode));
                break;

            case DataType.control_RCS:
                stream = new boolStream(connection.AddStream(() => control.RCS));
                break;

            case DataType.control_gear:
                stream = new boolStream(connection.AddStream(() => control.Gear));
                break;

            case DataType.control_brakes:
                stream = new boolStream(connection.AddStream(() => control.Brakes));
                break;

            case DataType.control_lights:
                stream = new boolStream(connection.AddStream(() => control.Lights));
                break;

            case DataType.control_abort:
                stream = new boolStream(connection.AddStream(() => control.Abort));
                break;

            case DataType.control_actionGroup0:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(0)));
                break;

            case DataType.control_actionGroup1:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(1)));
                break;

            case DataType.control_actionGroup2:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(2)));
                break;

            case DataType.control_actionGroup3:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(3)));
                break;

            case DataType.control_actionGroup4:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(4)));
                break;

            case DataType.control_actionGroup5:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(5)));
                break;

            case DataType.control_actionGroup6:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(6)));
                break;

            case DataType.control_actionGroup7:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(7)));
                break;

            case DataType.control_actionGroup8:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(8)));
                break;

            case DataType.control_actionGroup9:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(9)));
                break;

            case DataType.control_throttle:
                stream = new floatStream(connection.AddStream(() => control.Throttle));
                break;

            case DataType.control_currentStage:
                stream = new intStream(connection.AddStream(() => control.CurrentStage));
                break;

            case DataType.control_nodes:
                stream = new IListNodeStream(connection.AddStream(() => control.Nodes));
                break;

            ///// FLIGHT DATA /////

            case DataType.flight_gForce:
                stream = new floatStream(connection.AddStream(() => flight.GForce));
                break;

            case DataType.flight_angleOfAttack:
                stream = new floatStream(connection.AddStream(() => flight.AngleOfAttack));
                break;

            case DataType.flight_meanAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.MeanAltitude));
                break;

            case DataType.flight_surfaceAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.SurfaceAltitude));
                break;

            case DataType.flight_bedrockAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.BedrockAltitude));
                break;

            case DataType.flight_elevation:
                stream = new doubleStream(connection.AddStream(() => flight.Elevation));
                break;

            case DataType.flight_latitude:
                stream = new doubleStream(connection.AddStream(() => flight.Latitude));
                break;

            case DataType.flight_longitude:
                stream = new doubleStream(connection.AddStream(() => flight.Longitude));
                break;

            case DataType.flight_map_latitude:
                stream = new doubleStream(connection.AddStream(() => mapFlight.Latitude));
                break;

            case DataType.flight_map_longitude:
                stream = new doubleStream(connection.AddStream(() => mapFlight.Longitude));
                break;

            case DataType.flight_velocity:
                stream = new tuple3Stream(connection.AddStream(() => flight.Velocity));
                break;

            case DataType.flight_speed:
                stream = new doubleStream(connection.AddStream(() => flight.Speed));
                break;

            case DataType.flight_horizontalSpeed:
                stream = new doubleStream(connection.AddStream(() => flight.HorizontalSpeed));
                break;

            case DataType.flight_verticalSpeed:
                stream = new doubleStream(connection.AddStream(() => flight.VerticalSpeed));
                break;

            case DataType.flight_centerOfMass:
                stream = new tuple3Stream(connection.AddStream(() => flight.CenterOfMass));
                break;

            case DataType.flight_rotation:
                stream = new tuple4Stream(connection.AddStream(() => flight.Rotation));
                break;

            case DataType.flight_direction:
                stream = new tuple3Stream(connection.AddStream(() => flight.Direction));
                break;

            case DataType.flight_pitch:
                stream = new floatStream(connection.AddStream(() => flight.Pitch));
                break;

            case DataType.flight_heading:
                stream = new floatStream(connection.AddStream(() => flight.Heading));
                break;

            case DataType.flight_roll:
                stream = new floatStream(connection.AddStream(() => flight.Roll));
                break;

            case DataType.flight_atmosphereDensity:
                stream = new floatStream(connection.AddStream(() => flight.AtmosphereDensity));
                break;

            case DataType.flight_dynamicPressure:
                stream = new floatStream(connection.AddStream(() => flight.DynamicPressure));
                break;

            case DataType.flight_staticPressure:
                stream = new floatStream(connection.AddStream(() => flight.StaticPressure));
                break;

            case DataType.flight_prograde:
                stream = new tuple3Stream(connection.AddStream(() => flight.Prograde));
                break;

            case DataType.flight_retrograde:
                stream = new tuple3Stream(connection.AddStream(() => flight.Retrograde));
                break;

            case DataType.flight_radial:
                stream = new tuple3Stream(connection.AddStream(() => flight.Radial));
                break;

            case DataType.flight_antiRadial:
                stream = new tuple3Stream(connection.AddStream(() => flight.AntiRadial));
                break;

            case DataType.flight_normal:
                stream = new tuple3Stream(connection.AddStream(() => flight.Normal));
                break;

            case DataType.flight_antiNormal:
                stream = new tuple3Stream(connection.AddStream(() => flight.AntiNormal));
                break;


            ///// INERTIAL FLIGHT DATA /////

            case DataType.flight_inertial_roll:
                stream = new floatStream(connection.AddStream(() => inertFlight.Roll));
                break;

            case DataType.flight_inertial_pitch:
                stream = new floatStream(connection.AddStream(() => inertFlight.Pitch));
                break;

            case DataType.flight_inertial_yaw:
                stream = new floatStream(connection.AddStream(() => inertFlight.Heading));
                break;

            case DataType.flight_inertial_direction:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Direction));
                break;

            case DataType.flight_inertial_rotation:
                stream = new tuple4Stream(connection.AddStream(() => inertFlight.Rotation));
                break;

            case DataType.flight_inertial_velocity:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Velocity));
                break;

            case DataType.flight_inertial_prograde:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Prograde));
                break;

            case DataType.flight_inertial_retrograde:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Retrograde));
                break;

            case DataType.flight_inertial_radial:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Radial));
                break;

            case DataType.flight_inertial_antiRadial:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.AntiRadial));
                break;

            case DataType.flight_inertial_normal:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Normal));
                break;

            case DataType.flight_inertial_antiNormal:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.AntiNormal));
                break;


            ///// ORBIT DATA /////

            case DataType.orbit_apoapsisAltitude:
                stream = new doubleStream(connection.AddStream(() => orbit.ApoapsisAltitude));
                break;

            case DataType.orbit_apoapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.Apoapsis));
                break;

            case DataType.orbit_periapsisAltitude:
                stream = new doubleStream(connection.AddStream(() => orbit.PeriapsisAltitude));
                break;

            case DataType.orbit_periapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.Periapsis));
                break;

            case DataType.orbit_radius:
                stream = new doubleStream(connection.AddStream(() => orbit.Radius));
                break;

            case DataType.orbit_speed:
                stream = new doubleStream(connection.AddStream(() => orbit.Speed));
                break;

            case DataType.orbit_celestialBody:
                stream = new celestialBodyStream(connection.AddStream(() => orbit.Body));
                break;

            case DataType.orbit_semiMajorAxis:
                stream = new doubleStream(connection.AddStream(() => orbit.SemiMajorAxis));
                break;

            case DataType.orbit_semiMinorAxis:
                stream = new doubleStream(connection.AddStream(() => orbit.SemiMinorAxis));
                break;

            case DataType.orbit_argumentOfPeriapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.ArgumentOfPeriapsis));
                break;

            case DataType.orbit_longitudeOfAscendingNode:
                stream = new doubleStream(connection.AddStream(() => orbit.LongitudeOfAscendingNode));
                break;

            case DataType.orbit_eccentricity:
                stream = new doubleStream(connection.AddStream(() => orbit.Eccentricity));
                break;

            case DataType.orbit_inclination:
                stream = new doubleStream(connection.AddStream(() => orbit.Inclination));
                break;

            case DataType.orbit_trueAnomaly:
                stream = new doubleStream(connection.AddStream(() => orbit.TrueAnomaly));
                break;

            case DataType.orbit_timeToApoapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToApoapsis));
                break;

            case DataType.orbit_timeToPeriapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToPeriapsis));
                break;

            case DataType.orbit_period:
                stream = new doubleStream(connection.AddStream(() => orbit.Period));
                break;

            case DataType.orbit_timeToSOIChange:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToSOIChange));
                break;



            ///// RESOURCE DATA /////

            case DataType.resource_total_max_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources.Max("ElectricCharge")));
                break;

            case DataType.resource_total_amount_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources.Amount("ElectricCharge")));
                break;

            case DataType.resource_stage_max_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("ElectricCharge")));
                break;

            case DataType.resource_stage_amount_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("ElectricCharge")));
                break;


            case DataType.resource_total_max_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources.Max("MonoPropellant")));
                break;

            case DataType.resource_total_amount_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources.Amount("MonoPropellant")));
                break;

            case DataType.resource_stage_max_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("MonoPropellant")));
                break;

            case DataType.resource_stage_amount_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("MonoPropellant")));
                break;


            case DataType.resource_total_max_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources.Max("LiquidFuel")));
                break;

            case DataType.resource_total_amount_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources.Amount("LiquidFuel")));
                break;

            case DataType.resource_stage_max_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("LiquidFuel")));
                break;

            case DataType.resource_stage_amount_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("LiquidFuel")));
                break;


            case DataType.resource_stage_max_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("Oxidizer")));
                break;

            case DataType.resource_stage_amount_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("Oxidizer")));
                break;

            case DataType.resource_total_max_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources.Max("Oxidizer")));
                break;

            case DataType.resource_total_amount_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources.Amount("Oxidizer")));
                break;


            ///// SPACECENTER DATA /////
            case DataType.spacecenter_universial_time:
                stream = new doubleStream(connection.AddStream(() => spaceCenter.UT));
                break;


            ///// VESSEL DATA /////
            case DataType.vessel_MET:
                stream = new doubleStream(connection.AddStream(() => vessel.MET));
                break;

            case DataType.vessel_type:
                stream = new vesselTypeStream(connection.AddStream(() => vessel.Type));
                break;

            case DataType.vessel_mass:
                stream = new floatStream(connection.AddStream(() => vessel.Mass));
                break;

            case DataType.vessel_dryMass:
                stream = new floatStream(connection.AddStream(() => vessel.DryMass));
                break;

            case DataType.vessel_position:
                stream = new tuple3Stream(connection.AddStream(() => vessel.Position(vessel.Orbit.Body.NonRotatingReferenceFrame)));
                break;

            case DataType.vessel_velocity:
                stream = new tuple3Stream(connection.AddStream(() => vessel.Velocity(vessel.Orbit.Body.NonRotatingReferenceFrame)));
                break;

            case DataType.vessel_parts:
                stream = new vesselPartsStream(connection.AddStream(() => vessel.Parts));
                break;

            case DataType.vessel_referenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => vessel.ReferenceFrame));
                break;

            case DataType.vessel_orbit:
                stream = new OrbitStream(connection.AddStream(() => vessel.Orbit));
                break;

            case DataType.vessel_autoPilot:
                stream = new AutoPilotStream(connection.AddStream(() => vessel.AutoPilot));
                break;

            case DataType.vessel_surfaceReferenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => vessel.SurfaceReferenceFrame));
                break;


            default:
                throw (new Exception("DataType: " + type.ToString() + " not supported"));
            }

            // Safety check if type already exists in streams
            if (!streams.ContainsKey(type))
            {
                streams.Add(type, stream);
            }
        }
Ejemplo n.º 37
0
 public static void DrawDirection(Tuple3 direction, ReferenceFrame referenceFrame, Tuple3 color, float length = 10f)
 {
     DrawAddon.AddDirection (direction.ToVector (), referenceFrame, color, length);
 }
Ejemplo n.º 38
0
 private void getInertialRefFrame()
 {
     inertialRefFrame = orbit.Body.NonRotatingReferenceFrame;
 }
Ejemplo n.º 39
0
        /*double[] IVelocity.RevativeVelocity
         * {
         *  get
         *  {
         *      return relativeVelocity;
         *  }
         * }*/


        #endregion

        /// <summary>
        /// Sets state
        /// </summary>
        /// <param name="baseFrame">Base frame</param>
        /// <param name="relative">Relative frame</param>
        public override void Set(ReferenceFrame baseFrame, ReferenceFrame relative)
        {
            base.Set(baseFrame, relative);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// 压力出口
        /// </summary>
        /// <param name="boundaryName">边界名</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="bfDirectionM">回流方向方法</param>
        /// <param name="bfPressure">回流压力类型</param>
        /// <param name="gaugePressure">表压</param>
        /// <param name="isCheck">复选情况</param>
        /// <param name="xyzDirection">[xyz方向矢量],bfdm为DirectionVector时,需要在指定</param>
        /// <param name="massFlowParameter">[目标质量流率的参数],目标质量流率复选时,需要在指定</param>
        /// <returns>TUI命令</returns>
        string IEnOFF_ViscousOFF.PO(string boundaryName, ReferenceFrame referenceFrame, BackflowDirectionMethond bfDirectionM, BackflowPressure bfPressure, string gaugePressure, PO_MomentumCheck isCheck, float[] xyzDirection = null, float[] massFlowParameter = null)
        {
            string        bounaryType = BoundaryTypeE.pressure_outlet.ToString();
            StringBuilder sb          = new StringBuilder();

            if (bfDirectionM == BackflowDirectionMethond.DirectionVector)
            {
                if (xyzDirection == null)
                {
                    MessageBox.Show("当前指定方向的方法,xyzDirction不可为null");
                    return(null);
                }
            }
            sb.Append(m_boundaryConditionInitialTUI + bounaryType + " " + boundaryName + " ");
            if ((int)referenceFrame == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }

            sb.Append("n " + gaugePressure + " ");

            if ((int)bfDirectionM == 0)
            {
                sb.Append("y y n " + xyzDirection[0].ToString() + " n " + xyzDirection[1].ToString() + " n " + xyzDirection[2].ToString() + " ");
            }
            else if ((int)bfDirectionM == 1)
            {
                sb.Append("n y ");
            }
            else
            {
                sb.Append("n n y ");
            }

            if (bfPressure == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }


            if (isCheck.RadialEquilibriumPD)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n ");
            }
            if (isCheck.AverageP)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n ");
            }
            if (isCheck.TargetMassFlow)
            {
                sb.Append("y n " + massFlowParameter[0].ToString() + " n " + massFlowParameter[1].ToString() + " n " + massFlowParameter[2].ToString() + " ");
            }
            else
            {
                sb.Append("n ");
            }

            return(sb.ToString());
        }
Ejemplo n.º 41
0
        public static void HoldAttitude(FlightCtrlState fs, FlightComputer f, ReferenceFrame frame, FlightAttitude attitude, Quaternion extra)
        {
            var v       = f.Vessel;
            var forward = Vector3.zero;
            var up      = Vector3.zero;

            switch (frame)
            {
            case ReferenceFrame.Orbit:
                forward = v.GetObtVelocity();
                up      = (v.mainBody.position - v.CoM);
                break;

            case ReferenceFrame.Surface:
                forward = v.GetSrfVelocity();
                up      = (v.mainBody.position - v.CoM);
                break;

            case ReferenceFrame.North:
                up      = (v.mainBody.position - v.CoM);
                forward = Vector3.ProjectOnPlane(up,
                                                 v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius - v.CoM);
                break;

            case ReferenceFrame.Maneuver:
                if (f.Vessel.patchedConicSolver.maneuverNodes.Count != 0)
                {
                    forward = f.Vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(v.orbit);
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    forward = v.GetObtVelocity();
                    up      = (v.mainBody.position - v.CoM);
                }
                break;

            case ReferenceFrame.TargetVelocity:
                // f.DelayedTarget may be any ITargetable, including a planet
                // Velocity matching only makes sense for vessels and part modules
                // Can test for Vessel but not PartModule, so instead test that it's not the third case (CelestialBody)
                if (f.DelayedTarget != null && !(f.DelayedTarget is CelestialBody))
                {
                    forward = v.GetObtVelocity() - f.DelayedTarget.GetObtVelocity();
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    up      = (v.mainBody.position - v.CoM);
                    forward = v.GetObtVelocity();
                }
                break;

            case ReferenceFrame.TargetParallel:
                if (f.DelayedTarget != null && !(f.DelayedTarget is CelestialBody))
                {
                    forward = f.DelayedTarget.GetTransform().position - v.CoM;
                    up      = (v.mainBody.position - v.CoM);
                }
                else
                {
                    up      = (v.mainBody.position - v.CoM);
                    forward = v.GetObtVelocity();
                }
                break;
            }
            Vector3.OrthoNormalize(ref forward, ref up);
            Quaternion rotationReference = Quaternion.LookRotation(forward, up);

            switch (attitude)
            {
            case FlightAttitude.Prograde:
                break;

            case FlightAttitude.Retrograde:
                rotationReference = rotationReference * Quaternion.AngleAxis(180, Vector3.up);
                break;

            case FlightAttitude.NormalPlus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.up);
                break;

            case FlightAttitude.NormalMinus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.down);
                break;

            case FlightAttitude.RadialPlus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.right);
                break;

            case FlightAttitude.RadialMinus:
                rotationReference = rotationReference * Quaternion.AngleAxis(90, Vector3.left);
                break;

            case FlightAttitude.Surface:
                rotationReference = rotationReference * extra;
                break;
            }
            HoldOrientation(fs, f, rotationReference);
        }
Ejemplo n.º 42
0
        /// <summary>
        /// 设置速度入口边界条件
        /// </summary>
        /// <param name="boundaryName">边界名</param>
        /// <param name="velocityMethod">速度方法</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="velocityMagnitude">速度大小</param>
        /// <param name="gaugePressure">初始表压</param>
        /// <param name="turbulenceSet">湍流设置</param>
        /// <param name="xyzDirctionOrComponent ">[xyz方向或者xyz速度分量](根据速度方法而定,如果速度方法选择:大小和方向则该参数代表速度方向;如果速度方法选择:速度分量的矢量和则该参数代表速度分量(m/s),否则默认为null)</param>
        /// <returns>TUI命令</returns>
        string IEnOFF_ViscousON.VI(string boundaryName, VelocityMethod velocityMethod, ReferenceFrame referenceFrame, string velocityMagnitude, string gaugePressure, TurbulenceSet turbulenceSet, float[] xyzDirctionOrComponent = null)
        {
            StringBuilder sb = new StringBuilder();

            BoundaryConditionImp BC = new BoundaryConditionImp();
            IEnOFF_ViscousOFF    iEnOFF_ViscousOFF = BC;
            //动量TUI
            string TUI = iEnOFF_ViscousOFF.VI(boundaryName, velocityMethod, referenceFrame, velocityMagnitude, gaugePressure, xyzDirctionOrComponent);

            sb.Append(TUI);
            //湍流TUI
            TUI = TurbulenceSetTUI(turbulenceSet);
            sb.Append(TUI);

            return(sb.ToString());
        }
Ejemplo n.º 43
0
    protected virtual void Start()
    {
        var collider = this.GetComponentInChildren<Collider2D>();

        visibleBoxSize = Mathf.Max(collider.bounds.size.x, collider.bounds.size.y);

        referenceFrame = GetComponentInParent<ReferenceFrame>();
        if (referenceFrame == null) {
            Debug.LogError("There's an enemy not parented to the scene controller!", this);
            Debug.Break();
        }

        currentPos = this.rigidbody2D.position;
    }
Ejemplo n.º 44
0
        /// <summary>
        /// 设置速度入口边界条件
        /// </summary>
        /// <param name="boundaryType">边界类型</param>
        /// <param name="boundaryName">边界名</param>
        /// <param name="velocityMethod">速度方法</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="velocityMagnitude">速度大小</param>
        /// <param name="gaugePressure">初始表压</param>
        /// <param name="xyzDirctionOrComponent ">[xyz方向或者xyz速度分量](根据速度方法而定,如果速度方法选择:大小和方向则该参数代表速度方向;如果速度方法选择:速度分量的矢量和则该参数代表速度分量(m/s),否则默认为null)</param>
        /// <returns>TUI命令</returns>
        string IEnOFF_ViscousOFF.VI(string boundaryName, VelocityMethod velocityMethod, ReferenceFrame referenceFrame, string velocityMagnitude, string gaugePressure, float[] xyzDirctionOrComponent = null)
        {
            string boundaryType = BoundaryTypeE.velocity_inlet.ToString();

            if ((int)velocityMethod == 0 || (int)velocityMethod == 1)
            {
                if (xyzDirctionOrComponent == null)
                {
                    MessageBox.Show("当前速度方法,xyzDirctionOrComponent不可为null");
                    return(null);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(m_boundaryConditionInitialTUI + boundaryType + " " + boundaryName + " ");

            if ((int)velocityMethod == 0)
            {
                sb.Append("y ");
            }
            else if ((int)velocityMethod == 1)
            {
                sb.Append("n y");
            }
            else
            {
                sb.Append("n n y ");
            }

            if ((int)referenceFrame == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }

            if ((int)velocityMethod == 0 || (int)velocityMethod == 2)
            {
                sb.Append("n " + velocityMagnitude + " n " + gaugePressure + " ");
            }
            else
            {
                sb.Append("n " + gaugePressure + " ");
            }

            if ((int)velocityMethod == 0 || (int)velocityMethod == 1)
            {
                sb.Append("y n " + xyzDirctionOrComponent[0].ToString() + " n " + xyzDirctionOrComponent[1].ToString() + " n " + xyzDirctionOrComponent[2].ToString() + " ");
            }
            return(sb.ToString());
        }
Ejemplo n.º 45
0
        private void update()
        {
            IDataConsumer  cons  = this;
            ReferenceFrame frame = position.GetParentFrame();
            int            ncol  = colored ? 3 : 1;

            foreach (IPhysicalField field in fieldAliases.Keys)
            {
                IPositionObject po = field as IPositionObject;
                ReferenceFrame  ff = po.Position.GetParentFrame();
                ReferenceFrame.GetRelativeFrame(ff, frame, relative);
                Dictionary <int, Transformer> d = fieldAliases[field];
                foreach (int nf in d.Keys)
                {
                    Transformer      tr         = d[nf];
                    FieldTransformer transfomer = tr.tr;
                    tr.tr.Set(relative);
                }
                int fc = facet.Count;
                for (int i = 0; i < fc; i++)
                {
                    double[] p = facet[i];
                    relative.GetRelativePosition(p, pos);
                    object[] o = field[pos];
                    foreach (int nf in d.Keys)
                    {
                        Transformer tr = d[nf];
                        object      ot = tr.tr.Transform(o[nf]);
                        tr.an.SetValue(ot);
                    }
                    foreach (int ns in surfaceAliaes.Keys)
                    {
                        object sp = facet[i, ns];
                        surfaceAliaes[ns].SetValue(sp);
                    }
                    this.FullReset();
                    cons.UpdateChildrenData();
                    for (int j = 0; j < measures.Count; j++)
                    {
                        parameters[i, j] = measures[j].Parameter();
                    }
                    if (colorMea[0] == null)
                    {
                        continue;
                    }
                    for (int nnc = 0; nnc < ncol; nnc++)
                    {
                        double col = (double)colorMea[0].Parameter();
                        if (proportional)
                        {
                            if (i == 0)
                            {
                                min[nnc] = col;
                                max[nnc] = col;
                            }
                            else
                            {
                                if (min[nnc] > col)
                                {
                                    min[nnc] = col;
                                }
                                if (max[nnc] < col)
                                {
                                    max[nnc] = col;
                                }
                            }
                            colorValues[i, nnc] = col;
                        }
                    }
                }
            }
            if (colorMea[0] != null)
            {
                draw();
            }
        }
Ejemplo n.º 46
0
        /// <summary>
        /// 设置速度入口边界条件
        /// </summary>
        /// <param name="boundaryName">边界名</param>
        /// <param name="velocityMethod">速度方法</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="velocityMagnitude">速度大小</param>
        /// <param name="gaugePressure">初始表压</param>
        /// <param name="turbulenceSet">湍流设置</param>
        /// <param name="temperature">热量温度设置</param>
        /// <param name="speciesMassFractions">组分质量分数设置</param>
        /// <param name="xyzDirctionOrComponent ">[xyz方向或者xyz速度分量](根据速度方法而定,如果速度方法选择:大小和方向则该参数代表速度方向;如果速度方法选择:速度分量的矢量和则该参数代表速度分量(m/s),否则默认为null)</param>
        /// <returns>TUI命令</returns>
        string IEnON_ViscousON_RadiationOFF_SpeciesON.VI(string boundaryName, VelocityMethod velocityMethod, ReferenceFrame referenceFrame, string velocityMagnitude, string gaugePressure, TurbulenceSet turbulenceSet, string temperature, List <string> speciesMassFractions, float[] xyzDirctionOrComponent)
        {
            StringBuilder sb = new StringBuilder();

            BoundaryConditionImp BC = new BoundaryConditionImp();
            IEnOFF_ViscousOFF    iEnOFF_ViscousOFF = BC;
            //动量TUI
            string TUI = iEnOFF_ViscousOFF.VI(boundaryName, velocityMethod, referenceFrame, velocityMagnitude, gaugePressure, xyzDirctionOrComponent);

            sb.Append(TUI);

            //热量TUI
            sb.Append("n " + temperature + " ");

            //湍流TUI
            TUI = TurbulenceSetTUI(turbulenceSet);
            sb.Append(TUI);

            //组分TUI
            sb.Append("n ");
            foreach (string specieMassFractions in speciesMassFractions)
            {
                sb.Append("n " + specieMassFractions + " ");
            }

            return(sb.ToString());
        }
Ejemplo n.º 47
0
        public override void updateLocalElements(object sender, EventArgs e)
        {
            screenLabels[2].Text = "LT: " + Helper.timeString(DateTime.Now.TimeOfDay.TotalSeconds);

            if (form.form.connected && form.form.krpc.CurrentGameScene == GameScene.Flight)
            {
                MET                  = screenStreams.GetData(DataType.vessel_MET);
                UT                   = screenStreams.GetData(DataType.spacecenter_universial_time);
                frame                = screenStreams.GetData(DataType.body_nonRotatingReferenceFrame);
                RCS                  = screenStreams.GetData(DataType.control_RCS);
                autoPilot            = screenStreams.GetData(DataType.vessel_autoPilot);
                screenLabels[3].Text = "MET: " + Helper.timeString(MET, 3);

                if (autoPilotState)
                {
                    screenButtons[0].setLitState(true);
                }
                else
                {
                    screenButtons[0].setLitState(false);
                }

                if (autoPilot.SAS)
                {
                    screenButtons[1].setLitState(true);
                }
                else
                {
                    screenButtons[1].setLitState(false);
                }

                if (RCS)
                {
                    screenButtons[2].setLitState(true);
                }
                else
                {
                    screenButtons[2].setLitState(false);
                }

                Tuple <double, double, double> dir  = screenStreams.GetData(DataType.flight_direction);
                Tuple <double, double, double> idir = screenStreams.GetData(DataType.flight_inertial_direction);
                string dirs = "SURF: ";
                dirs += Helper.toFixed(dir.Item1, 3).ToString();
                dirs += " :: " + Helper.toFixed(dir.Item2, 3).ToString();
                dirs += " :: " + Helper.toFixed(dir.Item3, 3).ToString();
                dirs += "\nINER: " + Helper.toFixed(idir.Item1, 3).ToString();
                dirs += " :: " + Helper.toFixed(idir.Item2, 3).ToString();
                dirs += " :: " + Helper.toFixed(idir.Item3, 3).ToString();

                Tuple <double, double, double, double> rot  = screenStreams.GetData(DataType.flight_rotation);
                Tuple <double, double, double, double> irot = screenStreams.GetData(DataType.flight_inertial_rotation);
                dirs += "\n\nSURF: ";
                dirs += Helper.toFixed(rot.Item1, 3).ToString();
                dirs += " :: " + Helper.toFixed(rot.Item2, 3).ToString();
                dirs += " :: " + Helper.toFixed(rot.Item3, 3).ToString();
                dirs += " :: " + Helper.toFixed(rot.Item4, 3).ToString();

                dirs += "\nINER: ";
                dirs += Helper.toFixed(irot.Item1, 3).ToString();
                dirs += " :: " + Helper.toFixed(irot.Item2, 3).ToString();
                dirs += " :: " + Helper.toFixed(irot.Item3, 3).ToString();
                dirs += " :: " + Helper.toFixed(irot.Item4, 3).ToString();



                screenLabels[10].Text = dirs;
            }
        }
Ejemplo n.º 48
0
        /// <summary>
        /// 质量流入口
        /// </summary>
        /// <param name="boundaryName">边界名</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="massFlowMethond">质量流方法</param>
        /// <param name="dirctionMethond">指定方向方法</param>
        /// <param name="massFlowRateOrFlux">质量流率或质量流量</param>
        /// <param name="initialGaugePress">初始表压</param>
        /// <param name="turbulenceSet">湍流设置</param>
        /// <param name="temperature">热量温度设置</param>
        /// <param name="speciesMassFractions">组分质量分数设置</param>
        /// <param name="averageFlux">[平均质量流量]根据质量流方法确定该值是否为null</param>
        /// <param name="xyzDirection">[xyz方向矢量]根据指定方向方法确定确定该值是否为null</param>
        /// <returns>TUI命令</returns>
        string IEnON_ViscousON_RadiationOFF_SpeciesON.MI(string boundaryName, ReferenceFrame referenceFrame, MassFlowMethond massFlowMethond, PI_DirectionMethond directionMethond, string massFlowRateOrFlux, string initialGaugePress, TurbulenceSet turbulenceSet, string temperature, List <string> speciesMassFractions, string averageFlux, float[] xyzDirection)
        {
            string        bounaryType = BoundaryTypeE.mass_flow_inlet.ToString();
            StringBuilder sb          = new StringBuilder();

            if (massFlowMethond == MassFlowMethond.MassFluxWithAverageMassFlux)
            {
                if (averageFlux == null)
                {
                    MessageBox.Show("当前质量流方法,averageFlux不能为null");
                }
            }
            if (directionMethond == PI_DirectionMethond.DirectionVector)
            {
                if (xyzDirection == null)
                {
                    MessageBox.Show("当前指定方向的方法,xyzDirction不可为null");
                    return(null);
                }
            }
            sb.Append(m_boundaryConditionInitialTUI + bounaryType + " " + boundaryName + " ");
            if ((int)referenceFrame == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }

            if ((int)massFlowMethond == 0)
            {
                sb.Append("y " + "n " + massFlowRateOrFlux + " ");
            }
            else if ((int)massFlowMethond == 1)
            {
                sb.Append("n y " + "n " + massFlowRateOrFlux + " ");
            }
            else
            {
                sb.Append("n n y n " + massFlowRateOrFlux + " " + averageFlux + " ");
            }

            //热量TUI
            sb.Append("n " + temperature + " ");

            sb.Append("n " + initialGaugePress + " ");

            if (directionMethond == 0)
            {
                sb.Append("y y n " + xyzDirection[0].ToString() + " n " + xyzDirection[1].ToString() + " n " + xyzDirection[2].ToString() + " ");
            }
            else
            {
                sb.Append("n y ");
            }

            //湍流TUI
            string TUI = TurbulenceSetTUI(turbulenceSet);

            sb.Append(TUI);

            //组分TUI
            sb.Append("n ");
            foreach (string specieMassFractions in speciesMassFractions)
            {
                sb.Append("n " + specieMassFractions + " ");
            }

            return(sb.ToString());
        }
Ejemplo n.º 49
0
 public ConstraintVelocity(Body body, ReferenceFrame frame, Vector3? vel, Vector3? angVel)
 {
     Initialise(body, frame, vel, angVel);
 }
Ejemplo n.º 50
0
        /// <summary>
        /// 压力出口
        /// </summary>
        /// <param name="boundaryName">边界名</param>
        /// <param name="referenceFrame">参考框架</param>
        /// <param name="bfDirectionM">回流方向方法</param>
        /// <param name="bfPressure">回流压力类型</param>
        /// <param name="gaugePressure">表压</param>
        /// <param name="isCheck">复选情况</param>
        /// <param name="turbulenceSet">湍流设置</param>
        /// <param name="temperature">热量温度设置</param>
        /// <param name="speciesMassFractions">组分质量分数设置</param>
        /// <param name="xyzDirection">[xyz方向矢量],bfdm为DirectionVector时,需要在指定</param>
        /// <param name="massFlowParameter">[目标质量流率的参数],目标质量流率复选时,需要在指定</param>
        /// <returns>TUI命令</returns>
        string IEnON_ViscousON_RadiationOFF_SpeciesON.PO(string boundaryName, ReferenceFrame referenceFrame, BackflowDirectionMethond bfDirectionM, BackflowPressure bfPressure, string gaugePressure, PO_MomentumCheck isCheck, TurbulenceSet turbulenceSet, string temperature, List <string> speciesMassFractions, float[] xyzDirection, float[] massFlowParameter)
        {
            string        bounaryType = BoundaryTypeE.pressure_outlet.ToString();
            StringBuilder sb          = new StringBuilder();

            if (bfDirectionM == BackflowDirectionMethond.DirectionVector)
            {
                if (xyzDirection == null)
                {
                    MessageBox.Show("当前指定方向的方法,xyzDirction不可为null");
                    return(null);
                }
            }
            sb.Append(m_boundaryConditionInitialTUI + bounaryType + " " + boundaryName + " ");
            if ((int)referenceFrame == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }

            sb.Append("n " + gaugePressure + " ");

            //热量TUI
            sb.Append("n " + temperature + " ");

            if ((int)bfDirectionM == 0)
            {
                sb.Append("y y n " + xyzDirection[0].ToString() + " n " + xyzDirection[1].ToString() + " n " + xyzDirection[2].ToString() + " ");
            }
            else if ((int)bfDirectionM == 1)
            {
                sb.Append("n y ");
            }
            else
            {
                sb.Append("n n y ");
            }

            //湍流TUI
            sb.Append(TurbulenceSetTUI(turbulenceSet));

            //组分TUI
            sb.Append("n ");
            foreach (string specieMassFractions in speciesMassFractions)
            {
                sb.Append("n " + specieMassFractions + " ");
            }

            if (bfPressure == 0)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n y ");
            }


            if (isCheck.RadialEquilibriumPD)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n ");
            }
            if (isCheck.AverageP)
            {
                sb.Append("y ");
            }
            else
            {
                sb.Append("n ");
            }
            if (isCheck.TargetMassFlow)
            {
                sb.Append("y n " + massFlowParameter[0].ToString() + " n " + massFlowParameter[1].ToString() + " n " + massFlowParameter[2].ToString() + " ");
            }
            else
            {
                sb.Append("n ");
            }

            return(sb.ToString());
        }
Ejemplo n.º 51
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalPart.transform.position).ToTuple());
 }
Ejemplo n.º 52
0
 public static Tuple3 TransformVelocity (Tuple3 position, Tuple3 velocity, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames (from, to);
     var worldPosition = from.PositionToWorldSpace (position.ToVector ());
     var worldVelocity = from.VelocityToWorldSpace (position.ToVector (), velocity.ToVector ());
     return to.VelocityFromWorldSpace (worldPosition, worldVelocity).ToTuple ();
 }
Ejemplo n.º 53
0
 public Tuple3 Velocity(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.VelocityFromWorldSpace(InternalPart.transform.position, InternalPart.orbit.GetVel()).ToTuple());
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Update the line
 /// </summary>
 public override void Update()
 {
     renderer.enabled = Visible;
     renderer.SetPosition(0, ReferenceFrame.PositionToWorldSpace(start));
     renderer.SetPosition(1, ReferenceFrame.PositionToWorldSpace(end));
 }
 public static AttitudeCommand WithAttitude(FlightAttitude att, ReferenceFrame frame)
 {
     return new AttitudeCommand()
     {
         Mode = FlightMode.AttitudeHold,
         Attitude = att,
         Frame = frame,
         Orientation = Quaternion.identity,
         Altitude = Single.NaN,
         TimeStamp = RTUtil.GameTime,
     };
 }
Ejemplo n.º 56
0
 public void InstantaneousForce(Tuple3 force, Tuple3 position, ReferenceFrame referenceFrame)
 {
     PartForcesAddon.AddInstantaneous(new Force(this, force, position, referenceFrame));
 }
Ejemplo n.º 57
0
 public static Tuple4 TransformRotation (Tuple4 rotation, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames (from, to);
     return to.RotationFromWorldSpace (from.RotationToWorldSpace (rotation.ToQuaternion ())).ToTuple ();
 }
Ejemplo n.º 58
0
 /// <summary>
 /// Returns the up vector for the given reference frame in world coordinates
 /// </summary>
 public static Vector3d GetUp(ReferenceFrame referenceFrame, Vessel vessel)
 {
     return GetUpNotNormalized (referenceFrame, vessel).normalized;
 }
Ejemplo n.º 59
0
 static void CheckReferenceFrames (ReferenceFrame from, ReferenceFrame to)
 {
     if (ReferenceEquals (from, null))
         throw new ArgumentNullException ("from");
     if (ReferenceEquals (to, null))
         throw new ArgumentNullException ("to");
 }
Ejemplo n.º 60
0
 /// <summary>
 /// Sets a frame
 /// </summary>
 /// <param name="relative">Relative frame</param>
 internal virtual void Set(ReferenceFrame relative)
 {
 }