usingAbstractPlottingusingAbstractPlotting:Mesh,Scene,LineSegments,translate!,rotate!,vbox,hbox,qrotation,mesh!usingGeometryBasics:Vec3f0,Point3f0,SphereusingAbstractPlotting:textsliderusingObservables:onusingGLMakieusingAbstractPlotting"""
example by @pbouffard from JuliaPlots/Makie.jl#307
https://github.com/pbouffard/miniature-garbanzo/
"""functiontriad!(scene,len;translation=(0f0,0f0,0f0),show_axis=false)ret=linesegments!(scene,[Point3f0(0)=>Point3f0(len,0,0),Point3f0(0)=>Point3f0(0,len,0),Point3f0(0)=>Point3f0(0,0,len)],color=[:red,:green,:blue],linewidth=3)[end]translate!(ret,translation)returnretend# Joint vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvmutable structJointscene::Scenetriad::LineSegments# link::Meshangle::Float32axis::Vec3f0offset::Vec3f0endfunctionJoint(s::Scene)newscene=Scene(s)triad=triad!(newscene,1)Joint(newscene,triad,0f0,(0,1,0),(0,0,0))endfunctionJoint(j::Joint;offset::Point3f0=(0,0,0),axis=(0,1,0),angle=0.0)jnew=Joint(j.scene)translate!(jnew.scene,j.offset)linesegments!(jnew.scene,[Point3f0(0)=>offset],linewidth=4,color=:magenta)jnew.axis=axisjnew.offset=offsetsetangle!(jnew,angle)returnjnewendfunctionsetangle!(j::Joint,angle::Real)j.angle=anglerotate!(j.scene,qrotation(j.axis,angle))end# Joint ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^joints=Vector{Joint}()links=Float32[5,5]s=Scene(center=false,show_axis=false)push!(joints,Joint(s))joints[1].axis=(0,0,1)# first joint is yawjoints[1].offset=(0,0,1)push!(joints,Joint(joints[end];offset=Point3f0(3,0,0),axis=(0,1,0),angle=-pi/4))# Pitchpush!(joints,Joint(joints[end];offset=Point3f0(3,0,0),axis=(0,1,0),angle=pi/2))# Pitchpush!(joints,Joint(joints[end];offset=Point3f0(1,0,0),axis=(0,1,0),angle=-pi/4))# Pitchpush!(joints,Joint(joints[end];offset=Point3f0(1,0,0),axis=(0,0,1)))# Yawpush!(joints,Joint(joints[end];offset=Point3f0(0,0,0),axis=(1,0,0)))# Rollsliders=[]vals=[]fori=1:length(joints)slider,val=textslider(-180.0:1.0:180.0,"Joint $(i)",start=rad2deg(joints[i].angle))push!(sliders,slider)push!(vals,val)on(val)doxsetangle!(joints[i],deg2rad(x))endend# Add sphere to end effector:mesh!(joints[end].scene,Sphere(Point3f0(0.5,0,0),0.25f0),color=:cyan)update_cam!(s,Vec3f0(7.0,4.0,6.0),Vec3f0(6.0,2.5,4.5))parent=Scene(resolution=(1000,500))vbox(hbox(sliders...),s,parent=parent)# Do not execute beyond this point!RecordEvents(parent,"output")