Skip to content

Instantly share code, notes, and snippets.

@jimfoltz
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimfoltz/9595430 to your computer and use it in GitHub Desktop.
Save jimfoltz/9595430 to your computer and use it in GitHub Desktop.
Projectile Motion Animation SketchUp
class Cannon
def initialize(bearing, elev, velocity)
@item = Sketchup.active_model.entities[0]
@t = 0
@v = velocity.to_f
@angle = elev.to_f
@bearing = bearing.to_f
@vy = @v * Math::cos(@angle.degrees)
@vz = @v * Math::sin(@angle.degrees)
#@zi = @item.bounds.center.z
@zi = @item.transformation.to_a[-2]
@last_pt = nil
end
def nextFrame(view)
x = 0
y = @vy * @t
z = (@vz * @t) + 0.5 * -10.0 * (@t ** 2)
pt = Geom::Point3d.new(x, y, z)
t = Geom::Transformation.new(pt)
@item.transformation = t
if @last_pt
#Sketchup.active_model.entities.add_cpoint @item.bounds.center
Sketchup.active_model.entities.add_line pt, @last_pt
end
@last_pt = pt
@t += 0.2
if z < 0
return false
else
return true
end
end
end
def fire(bearing, angle, velocity)
Sketchup.active_model.active_view.animation = Cannon.new(bearing, angle, velocity)
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment