You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
Just playing around with kOS and KerbalEngineer and faced to absence of sensors to detect ground.
And what if KerbalEngineer module becomes sensor and then we can probe it from kOS.
Something like this
public class FlightEngineerModule : PartModule
{
[KSPField(guiActive=true)]
public float slope = float.NaN;
[KSPField( guiActive = true )]
public float heading = float.NaN;
//[KSPField( guiActive = true )]
//SlopeReadoutField slopeReadoutField;
/// <summary>
/// to avoid onUpdate
/// </summary>
[KSPEvent( active=true, guiActive = true, guiName = "Measure Surface data" )]
public void measureSurfaceData() {
///get all surface and update probes.
///right now just slope @ head
ReadoutModule slopeReadout = Readouts.ReadoutLibrary.GetReadout( "Surface.Slope" );
// tbd ReadoutModule as PartModule.
// now design breach!
// BAD BAD BAD BAD BAD BAD
Slope sl = (Slope)slopeReadout;
sl._Update();
this.slope = (float)sl.slope;
this.heading = (float)sl.heading;
//this.slopeReadoutField.slope = slope;
//this.slopeReadoutField.heading = heading;
}
public override void OnStart(StartState state) {
//if ( slopeReadoutField == null ) {
//// slopeReadoutField = new SlopeReadoutField();
//}
}
}
in slope readout I have to break routine into two different:
public class Slope : ReadoutModule
{
public double slope = float.NaN;
public double heading = float.NaN;
#region Constructors
public Slope() {
this.Name = "Slope";
this.Category = ReadoutCategory.GetCategory( "Surface" );
this.HelpString = "Shows the slope of the terrain below your vessel.";
this.IsDefault = true;
}
#endregion
#region Methods: public
public override void Draw(SectionModule section) {
this._Update();
this.DrawLine( this.GetSlopeAngleAndHeading(), section.IsHud );
}
//public override void Update() {
// base.Update();
public void _Update() {
var mainBody = FlightGlobals.ActiveVessel.mainBody;
var rad = ( FlightGlobals.ActiveVessel.CoM - mainBody.position ).normalized;
RaycastHit hit;
if ( Physics.Raycast( FlightGlobals.ActiveVessel.CoM, -rad, out hit, Mathf.Infinity, 1 << 15 ) ) { // Just "Local Scenery" please {
var norm = hit.normal;
norm = norm.normalized;
var raddotnorm = Vector3d.Dot( rad, norm );
if ( raddotnorm > 1.0 ) {
raddotnorm = 1.0;
} else if ( raddotnorm < 0.0 ) {
raddotnorm = 0.0;
}
this.slope = Math.Acos( raddotnorm ) * 180 / Math.PI;
if ( slope < 0.05 ) {
this.heading = float.NaN;
} else {
var side = Vector3d.Cross( rad, norm ).normalized;
var east = Vector3d.Cross( rad, Vector3d.up ).normalized;
var north = Vector3d.Cross( rad, east ).normalized;
var sidedoteast = Vector3d.Dot( side, east );
this.heading = Math.Acos( sidedoteast ) * 180 / Math.PI;
var sidedotnorth = Vector3d.Dot( side, north );
if ( sidedotnorth < 0 ) {
heading = 360 - heading;
}
}
}
}
#endregion
#region Methods: private
private string GetSlopeAngleAndHeading() {
try {
string result = double.IsNaN( slope ) ? "--°" : Units.ToAngle( slope, 1 );
result += " @ " + ( double.IsNaN( heading ) ? "---°" : Units.ToAngle( heading, 1 ) );
return result;
}
catch ( Exception ex ) {
Logger.Exception( ex, "Surface->Slope->GetSlopeAngleAndHeading" );
return "--° @ ---°";
}
}
#endregion
}
and voila
later i will provide patches if you want.
But it looks like it leads to some high redesign of Readouts to layout it into PartModules or IConfigNode.
The text was updated successfully, but these errors were encountered:
Hi.
Just playing around with kOS and KerbalEngineer and faced to absence of sensors to detect ground.
And what if KerbalEngineer module becomes sensor and then we can probe it from kOS.
Something like this
in slope readout I have to break routine into two different:
and voila
later i will provide patches if you want.
But it looks like it leads to some high redesign of Readouts to layout it into PartModules or IConfigNode.
The text was updated successfully, but these errors were encountered: