Skip to content

Commit a0ed915

Browse files
authored
Merge pull request #107 from JuliaComputing/framerender
Framerender
2 parents ca7b980 + ffa397f commit a0ed915

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

docs/src/rotations.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ E = RotXYZ(R)
5454
Evec = params(E)
5555
```
5656

57+
```@example ORI
58+
rotation_axis(R), rotation_angle(R) # Get an axis-angle representation
59+
```
60+
5761
## Conventions for modeling
5862
See [Orientations and directions](@ref)
5963

ext/Render.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,42 @@ function render!(scene, ::typeof(World), sys, sol, t)
305305
true
306306
end
307307

308+
function render!(scene, ::typeof(Frame), sys, sol, t)
309+
sol(sol.t[1], idxs=sys.render)==true || return true # yes, == true
310+
radius = sol(sol.t[1], idxs=sys.radius) |> Float32
311+
length = sol(sol.t[1], idxs=sys.length) |> Float32
312+
T = get_frame_fun(sol, sys)
313+
314+
thing = @lift begin
315+
Ti = T($t)
316+
Rx = Ti[:, 1]
317+
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
318+
x = O .+ Point3f(length*Rx)
319+
Makie.GeometryBasics.Cylinder(O, x, radius)
320+
end
321+
mesh!(scene, thing, color=:red)
322+
323+
thing = @lift begin
324+
Ti = T($t)
325+
Ry = Ti[:, 2]
326+
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
327+
y = O .+ Point3f(length*Ry)
328+
Makie.GeometryBasics.Cylinder(O, y, radius)
329+
end
330+
mesh!(scene, thing, color=:green)
331+
332+
thing = @lift begin
333+
Ti = T($t)
334+
Rz = Ti[:, 3]
335+
O = Point3f(Ti[1:3, 4]) # Assume world is never moving
336+
z = O .+ Point3f(length*Rz)
337+
Makie.GeometryBasics.Cylinder(O, z, radius)
338+
end
339+
mesh!(scene, thing, color=:blue)
340+
341+
true
342+
end
343+
308344
function render!(scene, T::Union{typeof(Revolute), typeof(RevolutePlanarLoopConstraint)}, sys, sol, t)
309345
r_0 = get_fun(sol, collect(sys.frame_a.r_0))
310346
n = get_fun(sol, collect(sys.n))

src/frames.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@connector function Frame(; name, varw = false, r_0 = zeros(3))
1+
@connector function Frame(; name, varw = false, r_0 = zeros(3), render=false, length=1.0, radius=0.1)
22
@variables r_0(t)[1:3]=r_0 [
33
description = "Position vector directed from the origin of the world frame to the connector frame origin, resolved in world frame",
44
]
@@ -10,12 +10,17 @@
1010
connect = Flow,
1111
description = "Cut torque resolved in connector frame",
1212
]
13+
pars = @parameters begin
14+
render = render
15+
length = length
16+
radius = radius
17+
end
1318
r_0, f, tau = collect.((r_0, f, tau))
1419
# R: Orientation object to rotate the world frame into the connector frame
1520

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

18-
ODESystem(Equation[], t, [r_0; f; tau], []; name,
23+
ODESystem(Equation[], t, [r_0; f; tau], pars; name,
1924
metadata = Dict(:orientation => R, :frame => true))
2025
end
2126

0 commit comments

Comments
 (0)