-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
685 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
using kOS.Safe.Encapsulation; | ||
using kOS.Safe.Encapsulation.Suffixes; | ||
using kOS.Safe.Exceptions; | ||
using kOS.Safe.Utilities; | ||
using kOS.Suffixed; | ||
using kOS.Suffixed.Part; | ||
|
||
namespace kOS.AddOns.CameraTools | ||
{ | ||
[kOS.Safe.Utilities.KOSNomenclature("CTAddon")] | ||
public class Addon : Suffixed.Addon | ||
{ | ||
CameraToolsWrapper wrapper; | ||
|
||
public Addon(SharedObjects shared) : base ("CT", shared) | ||
{ | ||
//CameraToolsWrapper.InitWrapper(); | ||
//wrapper = CameraToolsWrapper.Fetch; | ||
wrapper = new CameraToolsWrapper(); | ||
InitializeSuffixes(); | ||
} | ||
|
||
private void InitializeSuffixes() | ||
{ | ||
AddSuffix("REVERTCAMERA", new NoArgsVoidSuffix(wrapper.RevertCamera)); | ||
AddSuffix("STATIONARYCAMERA", new NoArgsVoidSuffix(wrapper.StationaryCamera)); | ||
AddSuffix("MANUALPOSITION", new SetSuffix<Vector>(GetManualPosition, SetManualPosition)); | ||
AddSuffix("CAMERAPOSITION", new SetSuffix<Vector>(GetCameraPosition, SetCameraPosition)); | ||
//AddSuffix("TARGET", new SetSuffix<VesselTarget>(GetCamTarget, SetCamTarget)); | ||
AddSuffix("TARGET", new SetSuffix<Structure>(GetCamTarget, SetCamTarget)); | ||
AddSuffix("MAXRELV", new SetSuffix<ScalarValue>(GetMaxRelV, SetMaxRelV)); | ||
AddSuffix("REFERENCEMODE", new SetSuffix<StringValue>(GetReferenceMode, SetRefereneceMode)); | ||
AddSuffix("AUTOFLYBY", new SetSuffix<BooleanValue>(GetAutoFlybyEnabledEnabled, SetAutoFlybyEnabled)); | ||
AddSuffix("MANUALFLYBY", new SetSuffix<BooleanValue>(GetManualOffsetEnabled, SetManualOffsetEnabled)); | ||
AddSuffix("MANUALOFFSETFORE", new SetSuffix<ScalarValue>(GetManualOffsetFore, SetManualOffsetFore)); | ||
AddSuffix("MANUALOFFSETTOP", new SetSuffix<ScalarValue>(GetManualOffsetTop, SetManualOffsetTop)); | ||
AddSuffix("MANUALOFFSETSTARBOARD", new SetSuffix<ScalarValue>(GetManualOffsetStarboard, SetManualOffsetStarboard)); | ||
AddSuffix("STATIONARYCAMERAENABLED", new Suffix<BooleanValue>(GetStationaryCameraEnabled)); | ||
AddSuffix("AUTOFOV", new SetSuffix<BooleanValue>(() => wrapper.AutoFOV, value => wrapper.AutoFOV = value)); | ||
} | ||
|
||
public void SetManualPosition(Vector pos) | ||
{ | ||
wrapper.SetManualPosition(pos.ToVector3() + shared.Vessel.findWorldCenterOfMass()); | ||
} | ||
|
||
public Vector GetManualPosition() | ||
{ | ||
return new Vector(wrapper.GetManualPosition() - shared.Vessel.findWorldCenterOfMass()); | ||
} | ||
|
||
public void SetCameraPosition(Vector pos) | ||
{ | ||
wrapper.SetCameraPosition(pos.ToVector3() + shared.Vessel.findWorldCenterOfMass()); | ||
} | ||
|
||
public Vector GetCameraPosition() | ||
{ | ||
return new Vector(wrapper.GetCameraPosition() - shared.Vessel.findWorldCenterOfMass()); | ||
} | ||
|
||
//public void SetCamTarget(VesselTarget target) | ||
//{ | ||
// wrapper.SetCamTarget(target.Vessel.ReferenceTransform); | ||
//} | ||
|
||
//public VesselTarget GetCamTarget() | ||
//{ | ||
// var transform = wrapper.GetCamTarget(); | ||
// var part = transform.gameObject.GetComponent<Part>(); | ||
// return new VesselTarget(part.vessel, shared); | ||
//} | ||
|
||
public void SetCamTarget(Structure target) | ||
{ | ||
var ves = target as VesselTarget; | ||
if (ves != null) | ||
{ | ||
//wrapper.SetCamTarget(ves.Vessel.ReferenceTransform); | ||
wrapper.SetCamTarget(ves.Vessel.rootPart.transform); | ||
return; | ||
} | ||
var part = target as PartValue; | ||
if (part != null) | ||
{ | ||
wrapper.SetCamTarget(part.Part.transform); | ||
return; | ||
} | ||
var body = target as BodyTarget; | ||
if (body != null) | ||
{ | ||
wrapper.SetCamTarget(body.Body.transform); | ||
return; | ||
} | ||
wrapper.SetCamTarget(null); | ||
throw new KOSException("Cannot set the camera target to this structure type. Value must be a Vessel, Part, or Body"); | ||
} | ||
|
||
public Structure GetCamTarget() | ||
{ | ||
var transform = wrapper.GetCamTarget(); | ||
var part = transform.gameObject.GetComponent<Part>(); | ||
return new VesselTarget(part.vessel, shared); | ||
} | ||
|
||
public void SetMaxRelV(ScalarValue val) | ||
{ | ||
wrapper.SetMaxRelativeVelocity(val); | ||
} | ||
|
||
public ScalarValue GetMaxRelV() | ||
{ | ||
return wrapper.GetMaxRelativeVelocity(); | ||
} | ||
|
||
public void SetRefereneceMode(StringValue val) | ||
{ | ||
wrapper.SetReferenceMode(val); | ||
} | ||
|
||
public StringValue GetReferenceMode() | ||
{ | ||
return wrapper.GetReferenceMode(); | ||
} | ||
|
||
public void SetManualOffsetFore(ScalarValue val) | ||
{ | ||
wrapper.SetManualOffsetForward(val); | ||
} | ||
|
||
public void SetManualOffsetTop(ScalarValue val) | ||
{ | ||
wrapper.SetManualOffsetUp(val); | ||
} | ||
|
||
public void SetManualOffsetStarboard(ScalarValue val) | ||
{ | ||
wrapper.SetManualOffsetRight(val); | ||
} | ||
|
||
public ScalarValue GetManualOffsetFore() | ||
{ | ||
return wrapper.GetManualOffsetForward(); | ||
} | ||
|
||
public ScalarValue GetManualOffsetTop() | ||
{ | ||
return wrapper.GetManualOffsetUp(); | ||
} | ||
|
||
public ScalarValue GetManualOffsetStarboard() | ||
{ | ||
return wrapper.GetManualOffsetRight(); | ||
} | ||
|
||
public void SetManualOffsetEnabled(BooleanValue val) | ||
{ | ||
wrapper.SetManualOffset(val); | ||
} | ||
|
||
public BooleanValue GetManualOffsetEnabled() | ||
{ | ||
return wrapper.GetManualOffset(); | ||
} | ||
|
||
public void SetAutoFlybyEnabled(BooleanValue val) | ||
{ | ||
wrapper.SetAutoFlybyPosition(val); | ||
} | ||
|
||
public BooleanValue GetAutoFlybyEnabledEnabled() | ||
{ | ||
return wrapper.GetAutoFlybyPosition(); | ||
} | ||
|
||
public BooleanValue GetStationaryCameraEnabled() | ||
{ | ||
return wrapper.GetIsStationaryCamera(); | ||
} | ||
|
||
public override BooleanValue Available() | ||
{ | ||
return CameraToolsWrapper.IsAvailable; | ||
} | ||
} | ||
} |
Oops, something went wrong.