概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。
練習問題
カメラのアングルを求めるRUBYスクリプトを書け。
写真
サンプルコード
def camera
view = Sketchup.active_model.active_view
camera = view.camera
if camera.perspective?
cam_type = "type: perspective"
else
cam_type = "type: orthographic"
end
eye = camera.eye
vx = eye.x.to_f
vy = eye.y.to_f
vz = eye.z.to_f
target = camera.target
tx = target.x.to_f
ty = target.y.to_f
tz = target.z.to_f
vfovdeg = camera.fov
vfovrad = vfovdeg * Math::PI / 180.0
h = Float(view.vpheight)
w = Float(view.vpwidth)
foc = (h / 2) / Math.tan(vfovrad / 2.0)
hfovrad = 2.0 * Math.atan2((w / 2), foc)
hfovdeg = hfovrad * 180.0 / Math::PI
ar = camera.aspect_ratio
ratio = view.vpwidth.to_f / view.vpheight.to_f
puts(cam_type)
puts("location: " + vx.to_s + ", " + vz.to_s + ", " + vy.to_s)
puts("look_at: " + tx.to_s + ", " + tz.to_s + ", " + ty.to_s)
puts("ratio: " + ratio.to_s)
puts("up " + camera.up.x.to_s + ", " + camera.up.z.to_s + ", " + camera.up.y.to_s)
puts("angle: " + hfovdeg.to_s + ".degrees")
end
以上。
