概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。
練習問題
rubyスクリプトでカメラを動かせ。
写真
サンプルコード
def camera_vp_targ
model = Sketchup.active_model
view = model.active_view
camera = view.camera
eye = camera.eye
vx = eye.x
vy = eye.y
vz = eye.z
target = camera.target
tx = target.x
ty = target.y
tz = target.z
vfovdeg = camera.fov
w = Float(view.vpwidth)
h = Float(view.vpheight)
vfovrad = vfovdeg * Math::PI / 180.0
f = (h / 2) / Math.tan(vfovrad / 2.0)
hfovrad = 2.0 * Math.atan2((w / 2), f)
hfovdeg = hfovrad * 180.0 / Math::PI
prompts = ["Position X", "Position Y", "Position Z", "Target X", "Target Y", "Target Z", "angle focal"]
values = [vx, vy, vz, tx, ty, tz, hfovdeg]
results = inputbox prompts, values, "Point de vue Camera / Mire"
vx, vy, vz, tx, ty, tz, hfovdeg = results
eye.x = vx
eye.y = vy
eye.z = vz
target.x = tx
target.y = ty
target.z = tz
up = camera.up
up.set!(0.0, 0.0, 1.0)
camera.set eye, target, up
hfovrad = hfovdeg * Math::PI / 180.0
f = (w / 2) / Math.tan(hfovrad / 2.0)
vfovrad = 2.0 * Math.atan2((h / 2), f)
vfovdeg = vfovrad * 180.0 / Math::PI
camera.fov = vfovdeg
end
以上。