0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その71

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。

練習問題

カメラのアングルを求めるRUBYスクリプトを書け。

写真

image.png

サンプルコード


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



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?