Open djungelorm opened 1 year ago
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();
}
}
@djungelorm Are you working on this one? Don't want to overlap your progress.
Not currently. I posted my findings above
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:
With the following methods/properties: