Skip to content

Commit

Permalink
Merge pull request #107 from JuliaComputing/framerender
Browse files Browse the repository at this point in the history
Framerender
  • Loading branch information
baggepinnen authored Jul 30, 2024
2 parents ca7b980 + ffa397f commit a0ed915
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/src/rotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ E = RotXYZ(R)
Evec = params(E)
```

```@example ORI
rotation_axis(R), rotation_angle(R) # Get an axis-angle representation
```

## Conventions for modeling
See [Orientations and directions](@ref)

Expand Down
36 changes: 36 additions & 0 deletions ext/Render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,42 @@ function render!(scene, ::typeof(World), sys, sol, t)
true
end

function render!(scene, ::typeof(Frame), sys, sol, t)
sol(sol.t[1], idxs=sys.render)==true || return true # yes, == true
radius = sol(sol.t[1], idxs=sys.radius) |> Float32
length = sol(sol.t[1], idxs=sys.length) |> Float32
T = get_frame_fun(sol, sys)

thing = @lift begin
Ti = T($t)
Rx = Ti[:, 1]
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
x = O .+ Point3f(length*Rx)
Makie.GeometryBasics.Cylinder(O, x, radius)
end
mesh!(scene, thing, color=:red)

thing = @lift begin
Ti = T($t)
Ry = Ti[:, 2]
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
y = O .+ Point3f(length*Ry)
Makie.GeometryBasics.Cylinder(O, y, radius)
end
mesh!(scene, thing, color=:green)

thing = @lift begin
Ti = T($t)
Rz = Ti[:, 3]
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
z = O .+ Point3f(length*Rz)
Makie.GeometryBasics.Cylinder(O, z, radius)
end
mesh!(scene, thing, color=:blue)

true
end

function render!(scene, T::Union{typeof(Revolute), typeof(RevolutePlanarLoopConstraint)}, sys, sol, t)
r_0 = get_fun(sol, collect(sys.frame_a.r_0))
n = get_fun(sol, collect(sys.n))
Expand Down
9 changes: 7 additions & 2 deletions src/frames.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@connector function Frame(; name, varw = false, r_0 = zeros(3))
@connector function Frame(; name, varw = false, r_0 = zeros(3), render=false, length=1.0, radius=0.1)
@variables r_0(t)[1:3]=r_0 [
description = "Position vector directed from the origin of the world frame to the connector frame origin, resolved in world frame",
]
Expand All @@ -10,12 +10,17 @@
connect = Flow,
description = "Cut torque resolved in connector frame",
]
pars = @parameters begin
render = render
length = length
radius = radius
end
r_0, f, tau = collect.((r_0, f, tau))
# R: Orientation object to rotate the world frame into the connector frame

R = NumRotationMatrix(; name, varw, state_priority=-1)

ODESystem(Equation[], t, [r_0; f; tau], []; name,
ODESystem(Equation[], t, [r_0; f; tau], pars; name,
metadata = Dict(:orientation => R, :frame => true))
end

Expand Down

0 comments on commit a0ed915

Please sign in to comment.