Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framerender #107

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading