updates
This commit is contained in:
parent
32ed347b58
commit
f41e197f20
4 changed files with 100 additions and 149 deletions
|
|
@ -364,8 +364,9 @@ func _place_camera(instant: bool) -> void:
|
|||
|
||||
|
||||
## The camera spot that fits the mat (and the bot's hand past it) into the screen the panels leave
|
||||
## free, from your side: angled for "seat", straight down for "top". Tries a few aim points and
|
||||
## keeps the closest camera that fits, then applies the zoom.
|
||||
## free, from your side: angled for "seat", straight down for "top". Tries a few aim points, slid
|
||||
## sideways to center the mat in that space, and keeps the closest camera that fits, then applies
|
||||
## the zoom.
|
||||
func _fit_camera() -> Transform3D:
|
||||
var side := 1.0 if me == 0 else -1.0
|
||||
var vp := get_viewport().get_visible_rect().size
|
||||
|
|
@ -387,7 +388,7 @@ func _fit_camera() -> Transform3D:
|
|||
var hi := 80.0
|
||||
for _k in 22:
|
||||
var d := (lo + hi) / 2.0
|
||||
camera.transform = Transform3D(Basis.IDENTITY, target + dir * d).looking_at(target, up)
|
||||
camera.transform = _aim(target, dir, d, up, points, region)
|
||||
var fits := true
|
||||
for pt in points:
|
||||
if not region.has_point(camera.unproject_position(pt)):
|
||||
|
|
@ -399,11 +400,31 @@ func _fit_camera() -> Transform3D:
|
|||
lo = d
|
||||
if hi < best_d:
|
||||
best_d = hi
|
||||
best = Transform3D(Basis.IDENTITY, target + dir * hi * _zoom).looking_at(target, up)
|
||||
best = _aim(target, dir, hi * _zoom, up, points, region)
|
||||
camera.transform = saved
|
||||
return best
|
||||
|
||||
|
||||
## The camera `d` from `target` along `dir`, slid sideways so `points` are centered across
|
||||
## `region`. A slide shifts a point on screen in proportion, so two trial spots give the slide.
|
||||
## Leaves the camera there.
|
||||
func _aim(target: Vector3, dir: Vector3, d: float, up: Vector3, points: Array, region: Rect2) -> Transform3D:
|
||||
var mids := []
|
||||
for x in [0.0, 1.0]:
|
||||
var at := target + Vector3(x, 0, 0)
|
||||
camera.transform = Transform3D(Basis.IDENTITY, at + dir * d).looking_at(at, up)
|
||||
var lo := INF
|
||||
var hi := -INF
|
||||
for pt in points:
|
||||
var sx := camera.unproject_position(pt).x
|
||||
lo = minf(lo, sx)
|
||||
hi = maxf(hi, sx)
|
||||
mids.append((lo + hi) / 2.0)
|
||||
var at := target + Vector3((region.get_center().x - mids[0]) / (mids[1] - mids[0]), 0, 0)
|
||||
camera.transform = Transform3D(Basis.IDENTITY, at + dir * d).looking_at(at, up)
|
||||
return camera.transform
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
# Picking
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue