Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic reference frames #17

Open
19 tasks
djungelorm opened this issue Mar 24, 2023 · 3 comments
Open
19 tasks

Basic reference frames #17

djungelorm opened this issue Mar 24, 2023 · 3 comments
Assignees
Labels
Milestone

Comments

@djungelorm
Copy link
Member

Add basic reference frames. This is a complex one, and is depended on by a lot of other functionality. Instances of this class don't expose any RPCs to the client, but they do have an "internal api" that is used by other parts of space center (e.g. getting the position, or rotation of the frame relative to world space).

See https://github.com/krpc/krpc/blob/main/service/SpaceCenter/src/Services/ReferenceFrame.cs

To start just add these three main ones:

  • ReferenceFrameType.Vessel
  • ReferenceFrameType.VesselOrbital
  • ReferenceFrameType.VesselSurface

With the following methods/properties:

  • Transform
  • Position
  • Rotation
  • Up
  • Forward
  • UpNotNormalized
  • ForwardNotNormalized
  • Velocity
  • PositionFromWorldSpace
  • PositionToWorldSpace
  • DirectionFromWorldSpace
  • DirectionToWorldSpace
  • RotationFromWorldSpace
  • RotationToWorldSpace
  • VelocityFromWorldSpace
  • VelocityToWorldSpace
@djungelorm djungelorm added this to the 0.2.0 milestone Mar 24, 2023
@djungelorm djungelorm mentioned this issue Mar 24, 2023
17 tasks
@djungelorm
Copy link
Member Author

djungelorm commented Mar 28, 2023

I've started looking into this. The implementation of KSP2 coordinates/transforms etc is very different to KSP1. Reference frames appear to be basically implemented in the KSP2 API, which might make our lives very simple implementing this.

For example some test RPCs I wrote:

        
        /// <summary>
        /// Vessel position in vessel reference frame
        /// </summary>
        [KRPCProperty]
        public Tuple3 VesselPositionVesselReferenceFrame
        {
            get
            {
                var pos = InternalVessel.SimulationObject.Position;
                var frame = InternalVessel.transform.bodyFrame;
                return frame.ToLocalPosition(pos).ToTuple();
            }
        }

        /// <summary>
        /// Vessel position in celestial body reference frame
        /// </summary>
        [KRPCProperty]
        public Tuple3 VesselPositionCelestialBodyReferenceFrame
        {
            get
            {
                var pos = InternalVessel.SimulationObject.Position;
                var frame = InternalVessel.mainBody.transform.bodyFrame;
                return frame.ToLocalPosition(pos).ToTuple();
            }
        }

        /// <summary>
        /// Celestial body position in celestial body reference frame
        /// </summary>
        [KRPCProperty]
        public Tuple3 CelestialBodyPositionCelestialBodyReferenceFrame
        {
            get
            {
                var pos = InternalVessel.mainBody.SimulationObject.Position;
                var frame = InternalVessel.mainBody.transform.bodyFrame;
                return frame.ToLocalPosition(pos).ToTuple();
            }
        }


        /// <summary>
        /// Celestial body position in vessel reference frame
        /// </summary>
        [KRPCProperty]
        public Tuple3 CelestialBodyPositionVesselReferenceFrame
        {
            get
            {
                var pos = InternalVessel.mainBody.SimulationObject.Position;
                var frame = InternalVessel.transform.bodyFrame;
                return frame.ToLocalPosition(pos).ToTuple();
            }
        }

@GaryDeco GaryDeco self-assigned this Mar 30, 2023
@GaryDeco
Copy link
Member

@djungelorm Are you working on this one? Don't want to overlap your progress.

@djungelorm
Copy link
Member Author

Not currently. I posted my findings above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants