Skip to content

Commit

Permalink
Fixes to Reference Frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
astrojonathan committed Jul 20, 2018
1 parent a19e1e7 commit b65bb74
Show file tree
Hide file tree
Showing 10 changed files with 738 additions and 67 deletions.
112 changes: 104 additions & 8 deletions HTML5SDK/wwtlib/Layers/LayerManager.cs
Expand Up @@ -558,6 +558,7 @@ public static void ConnectAllChildren()
if (!AllMaps[map.Frame.Parent].ChildMaps.ContainsKey(map.Frame.Name))
{
AllMaps[map.Frame.Parent].ChildMaps[map.Frame.Name] = map;
map.Parent = AllMaps[map.Frame.Parent];
}
}
}
Expand Down Expand Up @@ -588,6 +589,90 @@ public static bool DeleteLayerByID(Guid ID, bool removeFromParent, bool updateTr

}

internal static FrameTarget GetFrameTarget(RenderContext renderContext, string TrackingFrame)
{

FrameTarget target = new FrameTarget();

Vector3d targetPoint = Vector3d.Empty;

target.Target = Vector3d.Empty;
target.Matrix = Matrix3d.Identity;

if (!AllMaps.ContainsKey(TrackingFrame))
{
return target;
}

List<LayerMap> mapList = new List<LayerMap>();

LayerMap current = AllMaps[TrackingFrame];

mapList.Add(current);

while (current.Frame.Reference == ReferenceFrames.Custom)
{
current = current.Parent;
mapList.Insert(0, current);
}

Matrix3d matOld = renderContext.World;
Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating;
Matrix3d matOldBase = renderContext.WorldBase;
double oldNominalRadius = renderContext.NominalRadius;

foreach (LayerMap map in mapList)
{
if (map.Frame.Reference != ReferenceFrames.Custom && map.Frame.Reference != ReferenceFrames.Sandbox)
{

Planets.SetupPlanetMatrix(renderContext, (int)Enums.Parse("SolarSystemObjects", map.Frame.Name), Vector3d.Empty, false);
}
else
{
map.ComputeFrame(renderContext);
if (map.Frame.useRotatingParentFrame())
{
renderContext.World = Matrix3d.MultiplyMatrix(map.Frame.WorldMatrix, renderContext.World);
}
else
{
renderContext.World = Matrix3d.MultiplyMatrix(map.Frame.WorldMatrix, renderContext.WorldBaseNonRotating);

}
if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Synodic)
{
renderContext.WorldBaseNonRotating = renderContext.World;
}

renderContext.NominalRadius = map.Frame.MeanRadius;
}
}

targetPoint = renderContext.World.Transform(targetPoint);

Vector3d lookAt = renderContext.World.Transform(Vector3d.Create(0, 0, 1));

Vector3d lookUp = renderContext.World.Transform(Vector3d.SubtractVectors(Vector3d.Create(0, 1, 0),targetPoint));


lookUp.Normalize();


target.Matrix = Matrix3d.LookAtLH(new Vector3d(), Vector3d.SubtractVectors(lookAt, targetPoint), lookUp);


renderContext.NominalRadius = oldNominalRadius;
renderContext.World = matOld;
renderContext.WorldBaseNonRotating = matOldNonRotating;
renderContext.WorldBase = matOldBase;



target.Target = targetPoint;
return target;
}

internal static void PrepTourLayers()
{
if (TourPlayer.Playing)
Expand Down Expand Up @@ -667,7 +752,7 @@ internal static void Draw(RenderContext renderContext, float opacity, bool astro
Matrix3d matOld = renderContext.World;
Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating;
double oldNominalRadius = renderContext.NominalRadius;
if (thisMap.Frame.Reference == ReferenceFrames.Custom)
if (thisMap.Frame.Reference == ReferenceFrames.Custom | thisMap.Frame.Reference == ReferenceFrames.Custom)
{
thisMap.ComputeFrame(renderContext);
if (thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Orbital && thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Trajectory)
Expand Down Expand Up @@ -701,7 +786,14 @@ internal static void Draw(RenderContext renderContext, float opacity, bool astro
{
if ((pass == 0 && layer is ImageSetLayer) || (pass == 1 && !(layer is ImageSetLayer)))
{
if (layer.Enabled) // && astronomical == layer.Astronomical)
bool skipLayer = false;
if (pass == 0)
{
// Skip default image set layer so that it's not drawn twice
skipLayer = !astronomical && ((ImageSetLayer)layer).OverrideDefaultLayer;
}

if (layer.Enabled && !skipLayer) // && astronomical == layer.Astronomical)
{
double layerStart = SpaceTimeController.UtcToJulian(layer.StartTime);
double layerEnd = SpaceTimeController.UtcToJulian(layer.EndTime);
Expand All @@ -721,10 +813,7 @@ internal static void Draw(RenderContext renderContext, float opacity, bool astro
fadeOpacity = (float)((fadeOut - SpaceTimeController.JNow) / (layer.FadeSpan / 864000000));
}
layer.Astronomical = astronomical;
//if (thisMap.Frame.Reference == ReferenceFrames.Sky)
//{
// layer.Astronomical = true;
//}

if (layer is SpreadSheetLayer)
{
SpreadSheetLayer tsl = layer as SpreadSheetLayer;
Expand All @@ -748,7 +837,7 @@ internal static void Draw(RenderContext renderContext, float opacity, bool astro
{
continue;
}
if (map.Frame.ShowOrbitPath && Settings.Active.SolarSystemOrbits && Settings.Active.SolarSystemMinorOrbits)
if (map.Enabled && map.Frame.ShowOrbitPath && Settings.Active.SolarSystemOrbits && Settings.Active.SolarSystemMinorOrbits)
{
if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Orbital)
{
Expand Down Expand Up @@ -2195,7 +2284,8 @@ public enum ReferenceFrames
Ganymede = 16,
Callisto = 17,
Custom = 18,
Identity = 19
Identity = 19,
Sandbox = 20
};

public class SkyOverlays
Expand All @@ -2210,4 +2300,10 @@ public class OrbitLayer
{

}

public class FrameTarget
{
public Vector3d Target;
public Matrix3d Matrix;
}
}
17 changes: 14 additions & 3 deletions HTML5SDK/wwtlib/Layers/ReferenceFrame.cs
Expand Up @@ -9,7 +9,7 @@

namespace wwtlib
{
public enum ReferenceFrameTypes { FixedSherical=0, Orbital=1, Trajectory = 2 /*,FixedRectangular*/ };
public enum ReferenceFrameTypes { FixedSherical=0, Orbital=1, Trajectory = 2, Synodic = 3 /*,FixedRectangular*/ };
public class ReferenceFrame
{
public ReferenceFrame()
Expand Down Expand Up @@ -369,7 +369,7 @@ public void ComputeFrame(RenderContext renderContext)
case ReferenceFrameTypes.Trajectory:
ComputeFrameTrajectory(renderContext);
break;

// todo port synodic for JWST orbits..
//case ReferenceFrameTypes.FixedRectangular:
// ComputeFixedRectangular(renderContext);
// break;
Expand All @@ -378,7 +378,18 @@ public void ComputeFrame(RenderContext renderContext)
}
}


public bool useRotatingParentFrame()
{
switch (ReferenceFrameType)
{
case ReferenceFrameTypes.Orbital:
case ReferenceFrameTypes.Trajectory:
case ReferenceFrameTypes.Synodic:
return false;
default:
return true;
}
}

private void ComputeFixedRectangular(RenderContext renderContext)
{
Expand Down
8 changes: 4 additions & 4 deletions HTML5SDK/wwtlib/Place.cs
Expand Up @@ -536,10 +536,10 @@ internal static Place FromXml(XmlNode place)
newPlace.camParams.ViewTarget = Vector3d.Parse(place.Attributes.GetNamedItem("ViewTarget").Value);
}

//if (place.Attributes.GetNamedItem("TargetReferenceFrame") != null)
//{
// newPlace.camParams.TargetReferenceFrame = place.Attributes.GetNamedItem("TargetReferenceFrame").Value;
//}
if (place.Attributes.GetNamedItem("TargetReferenceFrame") != null)
{
newPlace.camParams.TargetReferenceFrame = place.Attributes.GetNamedItem("TargetReferenceFrame").Value;
}

XmlNode descriptionNode = Util.SelectSingleNode(place, "Description");
if (descriptionNode != null)
Expand Down

0 comments on commit b65bb74

Please sign in to comment.