@@ -147,8 +147,14 @@ function render(model, sol,
147147 if traces != = nothing
148148 tvec = range (sol. t[1 ], stop= sol. t[end ], length= 500 )
149149 for frame in traces
150- (frame. metadata != = nothing && get (frame. metadata, :frame , false )) || error (" Only frames can be traced in animations." )
151- points = get_trans (sol, frame, tvec) |> Matrix
150+ (frame. metadata != = nothing ) || error (" Only frames can be traced in animations." )
151+ if get (frame. metadata, :frame , false )
152+ points = get_trans (sol, frame, tvec) |> Matrix
153+ elseif get (frame. metadata, :frame_2d , false )
154+ points = get_trans_2d (sol, frame, tvec) |> Matrix
155+ else
156+ error (" Got fishy frame metadata" )
157+ end
152158 Makie. lines! (scene, points)
153159 end
154160 end
@@ -199,8 +205,14 @@ function render(model, sol, time::Real;
199205 if traces != = nothing
200206 tvec = range (sol. t[1 ], stop= sol. t[end ], length= 500 )
201207 for frame in traces
202- (frame. metadata != = nothing && get (frame. metadata, :frame , false )) || error (" Only frames can be traced in animations." )
203- points = get_trans (sol, frame, tvec) |> Matrix
208+ (frame. metadata != = nothing ) || error (" Only frames can be traced in animations." )
209+ if get (frame. metadata, :frame , false )
210+ points = get_trans (sol, frame, tvec) |> Matrix
211+ elseif get (frame. metadata, :frame_2d , false )
212+ points = get_trans_2d (sol, frame, tvec) |> Matrix
213+ else
214+ error (" Got fishy frame metadata" )
215+ end
204216 Makie. lines! (scene, points)
205217 end
206218 end
@@ -700,11 +712,14 @@ function get_frame_fun_2d(sol, frame)
700712 end
701713end
702714
715+ get_trans_2d (sol, frame, t) = SVector {2} (sol (t, idxs = [frame. x, frame. y]))
716+ get_trans_2d (sol, frame, t:: AbstractArray ) = sol (t, idxs = [frame. x, frame. y])
717+
703718function render! (scene, :: typeof (P. Body), sys, sol, t)
704719 sol (sol. t[1 ], idxs= sys. render)== true || return true # yes, == true
705720 color = get_color (sys, sol, :purple )
706721 r_cm = get_fun (sol, collect (sys. r))
707- framefun = get_frame_fun_2d (sol, sys. frame )
722+ framefun = get_frame_fun_2d (sol, sys. frame_a )
708723 radius = sol (sol. t[1 ], idxs= sys. radius) |> Float32
709724 thing = @lift begin # Sphere
710725 # Ta = framefun($t)
@@ -736,6 +751,23 @@ function render!(scene, ::Union{typeof(P.FixedTranslation), typeof(P.BodyShape)}
736751 true
737752end
738753
754+ function render! (scene, :: typeof (P. Prismatic), sys, sol, t)
755+ sol (sol. t[1 ], idxs= sys. render)== true || return true # yes, == true
756+ r_0a = get_fun (sol, [sys. frame_a. x, sys. frame_a. y])
757+ r_0b = get_fun (sol, [sys. frame_b. x, sys. frame_b. y])
758+ color = get_color (sys, sol, :purple )
759+ thing = @lift begin
760+ r1 = Point3f (r_0a ($ t)... , 0 )
761+ r2 = Point3f (r_0b ($ t)... , 0 )
762+ origin = r1# (r1+r2) ./ 2
763+ extremity = r2# -r1 # Double pendulum is a good test for this
764+ radius = Float32 (sol ($ t, idxs= sys. radius))
765+ Makie. GeometryBasics. Cylinder (origin, extremity, radius)
766+ end
767+ mesh! (scene, thing; color, specular = Vec3f (1.5 ), shininess= 20f0 , diffuse= Vec3f (1 ))
768+ true
769+ end
770+
739771function render! (scene, :: typeof (P. Revolute), sys, sol, t)
740772 sol (sol. t[1 ], idxs= sys. render)== true || return true # yes, == true
741773 r_0 = get_fun (sol, [sys. frame_a. x, sys. frame_a. y])
@@ -782,4 +814,33 @@ function render!(scene, ::Union{typeof(P.Spring), typeof(P.SpringDamper)}, sys,
782814 true
783815end
784816
817+ function render! (scene, :: Union{typeof(P.SimpleWheel), typeof(P.SlipBasedWheelJoint)} , sys, sol, t)
818+
819+ r_0 = get_fun (sol, [sys. frame_a. x, sys. frame_a. y])
820+ rotfun = get_rot_fun_2d (sol, sys. frame_a)
821+ color = get_color (sys, sol, :red )
822+
823+ # TODO : add some form of assumetry to indicate that the wheel is rotating
824+
825+ radius = try
826+ sol (sol. t[1 ], idxs= sys. radius)
827+ catch
828+ 0.05f0
829+ end |> Float32
830+ thing = @lift begin
831+ # radius = sol($t, idxs=sys.radius)
832+ O = [r_0 ($ t)... , 0 ]
833+ # T_w_a = framefun($t)
834+ R_w_a = rotfun ($ t)
835+ n_a = [0 ,1 ] # Wheel rotates around y axis
836+ n_w = [R_w_a* n_a; 0 ] # Rotate to the world frame
837+ width = radius/ 10
838+ p1 = Point3f (O + width* n_w)
839+ p2 = Point3f (O - width* n_w)
840+ Makie. GeometryBasics. Cylinder (p1, p2, radius)
841+ end
842+ mesh! (scene, thing; color, specular = Vec3f (1.5 ), shininess= 20f0 , diffuse= Vec3f (1 ))
843+ true
844+ end
845+
785846end
0 commit comments