Skip to content

Commit

Permalink
[Solarsystem demo] integrated GetPositionTransformationMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldsteinlechner committed Feb 12, 2024
1 parent 20b5be1 commit ba3df67
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 72 deletions.
Binary file modified lib/JR.Wrappers.dll
Binary file not shown.
5 changes: 4 additions & 1 deletion src/InstrumentPlatforms/CooTransformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static extern int GetRelState(string pcTargetBody,
string pcOutputReferenceFrame,
IntPtr pdPosVec,
IntPtr pdRotMat);



[DllImport(@"CooTransformation.dll")]
public static extern int GetPositionTransformationMatrix(string pcFrom, string pcTo, string pcDatetime, IntPtr pdRotMat);
}
}
10 changes: 9 additions & 1 deletion src/InstrumentPlatforms/JR.Wrappers.Tests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ let tests () =
let result = JR.CooTransformation.Xyz2LatLonAlt("mars", 1.0, 1.0, 1.0, &lat, &lon, &alt)
Expect.equal 0 result "Xyz2LatLonAlt result code"
}
test "xyzToLatLon" {
test "XyzToLatLon" {
let mutable px,py,pz = 0.0,0.0,0.0
let result = JR.CooTransformation.LatLonAlt2Xyz("MARS", 18.447, 77.402, 0, &px, &py, &pz)
printfn "%A" (py, py, pz)
Expect.equal 0 result "LatLonAlt2Xyz result code"
}

test "GetPositionTransformationMatrix" {
let t = "2026-12-03 08:15:00.00"
let m : double[] = Array.zeroCreate 9
let pdMat = fixed &m[0]
let result = JR.CooTransformation.GetPositionTransformationMatrix("IAU_EARTH", "J2000", t, NativePtr.toNativeInt pdMat)
Expect.equal 0 result "GetPositionTransformationMatrix_AFC"
}

]


Expand Down
73 changes: 54 additions & 19 deletions src/InstrumentPlatforms/JR.Wrappers.Tests/Solarsystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ module Spice =
let pdPosVec = fixed &p[0]
let pdRotMat = fixed &m[0]
let r = JR.CooTransformation.GetRelState(target, "SUN", observer, obsTime, referenceFrame, NativePtr.toNativeInt pdPosVec, NativePtr.toNativeInt pdRotMat)
if r <> 0 then failwith "[spice] GetRelState failed."
{ pos = V3d(p[0],p[1],p[2]); vel = V3d.Zero; rot = M33d(m)}
if r <> 0 then
Log.warn "[spice] GetRelState failed %s, %s, %s" target observer obsTime
{ pos = V3d.Zero; vel = V3d.Zero; rot = M33d.Identity } //failwith "[spice] GetRelState failed."
else { pos = V3d(p[0],p[1],p[2]); vel = V3d.Zero; rot = M33d(m).Transposed }


module Shaders =
Expand Down Expand Up @@ -140,13 +142,15 @@ let run argv =
"mars", C4f.Red, 6779.0
"phobos", C4f.Red, 22.533
"deimos", C4f.Red, 12.4
"HERA", C4f.Magenta, 0.01
"HERA", C4f.Magenta, 0.00001
"HERA_AFC-1", C4f.White, 0.00001
|]

let time = cval (DateTime.Parse("2025-03-10 19:08:12.60"))
let time = cval (DateTime.Parse("2025-03-11 19:08:12.60"))
let time = cval (DateTime.Parse("2025-03-10 19:08:12.60"))
//let time = cval (DateTime.Parse("2024-12-01 19:08:12.60"))

let observer = "MARS" // "SUN"
let observer = "HERA_SA+Y" // "SUN"
let referenceFrame = "ECLIPJ2000"

let targetState = Spice.getRelState referenceFrame "MARS" "HERA" (Time.toUtcFormat time.Value)
Expand Down Expand Up @@ -208,13 +212,15 @@ let run argv =
let vertices =
AVal.custom (fun t ->
let w = win.Time.GetValue(t)
time.GetValue(t) |> ignore
let vp = viewProj.GetValue(t)
bodies |> Array.map (fun b -> vp.Forward.TransformPosProj b.pos.Value)
bodies |> Array.map (fun b -> vp.Forward.TransformPosProj (b.pos.GetValue(t)))
)
let sizes =
AVal.custom (fun t ->
let p = projTrafo.GetValue(t)
let location = view.GetValue(t)
time.GetValue(t) |> ignore
let s = win.Sizes.GetValue(t) |> V3d
let computeSize (radius : float) (pos : V3d) =
let d = V3d(radius, 0.0, Vec.length (location.Location - pos))
Expand Down Expand Up @@ -272,34 +278,63 @@ let run argv =
do! DefaultSurfaces.constantColor C4f.White
}

let spacecraftTrafo = cval (Trafo3d.Scale 0.0)
let coordinateCross (size : float) (modelTrafo : aval<Trafo3d>)=
let lines (lines : array<Line3d*C4f>) =
lines |> Array.collect(fun (l,c) -> [|l.P0; l.P1|]) |> Seq.toArray

let cross = [|
Line3d(V3d.Zero, V3d.XAxis * size), C4f.Red
Line3d(V3d.Zero, V3d.YAxis * size), C4f.Green
Line3d(V3d.Zero, V3d.ZAxis * size), C4f.Blue
|]

let vertices =
(modelTrafo, viewProj) ||> AVal.map2 (fun m vp ->
let mvp = m * vp
lines cross |> Array.map (fun v ->
let p = mvp.Forward.TransformPosProjFull v
p |> V4f
)
)

Sg.draw IndexedGeometryMode.LineList
|> Sg.vertexAttribute DefaultSemantic.Positions vertices
|> Sg.vertexArray DefaultSemantic.Colors (cross |> Array.collect (fun (l, c) -> [| c; c|]))
|> Sg.shader {
do! DefaultSurfaces.vertexColor
}

let heraCoordinateCross =
coordinateCross 1000000000.0 spacecraftTrafo

let sg =
Sg.ofList [planets; texts; info; lineSg ]
Sg.ofList [planets; texts; info; lineSg; heraCoordinateCross ]


win.Keyboard.KeyDown(Keys.R).Values.Add(fun _ ->
transact (fun _ ->
let targetState = Spice.getRelState referenceFrame "MARS" "HERA" (Time.toUtcFormat time.Value)
let rot = targetState.rot.Transposed
let t = Trafo3d.FromBasis(rot.C0, rot.C1, rot.C2, V3d.Zero)
let lookAt = CameraView.lookAt V3d.Zero targetState.pos V3d.OOI
let t2 = CameraView.viewTrafo lookAt
let c = CameraView.ofTrafo t.Inverse
let c2 = CameraView.ofTrafo t
initialView.Value <- c
let targetState = Spice.getRelState referenceFrame "MARS" observer (Time.toUtcFormat time.Value)
let rot = targetState.rot
let t = Trafo3d.FromBasis(rot.C0, rot.C1, -rot.C2, V3d.Zero)
initialView.Value <- CameraView.ofTrafo t.Inverse
)
)

let s =
let sw = Diagnostics.Stopwatch.StartNew()
animationStep()
win.AfterRender.Add(fun _ ->
transact (fun _ ->
//let targetState = Spice.getRelState referenceFrame "MARS" "HERA" (Time.toUtcFormat time.Value)
//let lookAt = CameraView.lookAt V3d.Zero targetState.pos V3d.OOI
//initialView.Value <- lookAt
let targetState = Spice.getRelState referenceFrame "MARS" observer (Time.toUtcFormat time.Value)
let rot = targetState.rot
let t = Trafo3d.FromBasis(rot.C0, rot.C1, rot.C2, V3d.Zero)
spacecraftTrafo.Value <- t

time.Value <- time.Value + TimeSpan.FromDays(0.001)
animationStep()

)

)


Expand Down
18 changes: 17 additions & 1 deletion src/OpcViewer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,26 @@ let main argv =
}


let jezereo =
{
useCompressedTextures = true
preTransform = Trafo3d.Identity
patchHierarchies =
Seq.delay (fun _ ->
System.IO.Directory.GetDirectories(@"K:\PRo3D Data\Jezero1")
|> Seq.collect System.IO.Directory.GetDirectories
)
boundingBox = Box3d.Parse("[[701677.203042967, 3141128.733093360, 1075935.257765322], [701942.935458576, 3141252.724183598, 1076182.681085336]]")
near = 0.1
far = 10000.0
speed = 5.0
lodDecider = DefaultMetrics.mars2
}

match kind with

| Solarsystem ->
Solarsytsem.run [mola;]
Solarsytsem.run [mola;shaler;jezereo]

| Scene ->

Expand Down
Loading

0 comments on commit ba3df67

Please sign in to comment.