Skip to content

Commit 11ff68e

Browse files
committed
Added camera class for animation
1 parent 76d9b7b commit 11ff68e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/accessvis/earth.py

+55
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,61 @@ def lookat(lv, pos, lookat=None, up=None):
12481248
lv.translation(tr)
12491249

12501250

1251+
class Camera:
1252+
lv = None
1253+
1254+
def __init__(self, lv):
1255+
self.lv = lv
1256+
1257+
def look_at(self, pos, at=None, up=None):
1258+
lookat(self.lv, pos, at, up)
1259+
1260+
def lerpto(self, pos, L):
1261+
# Lerp using current camera orientation as start point
1262+
pos0 = self.lv.camera(quiet=True)
1263+
return self.lerp(pos0, pos)
1264+
1265+
def lerp(self, pos0, pos1, L):
1266+
"""
1267+
Linearly Interpolate between two camera positions/orientations and
1268+
set the camera to the resulting position/orientation
1269+
"""
1270+
final = {}
1271+
for key in ["translate", "rotate", "focus"]:
1272+
val0 = np.array(pos0[key])
1273+
val1 = np.array(pos1[key])
1274+
res = val0 + (val1 - val0) * L
1275+
if len(res) > 3:
1276+
# Normalise quaternion
1277+
res = res / np.linalg.norm(res)
1278+
final[key] = res.tolist()
1279+
1280+
self.lv.camera(final)
1281+
1282+
def flyto(self, pos, steps, stop=False):
1283+
# Fly using current camera orientation as start point
1284+
pos0 = self.lv.camera(quiet=True)
1285+
return self.fly(pos0, pos, steps, stop)
1286+
1287+
def fly(self, pos0, pos1, steps, stop=False):
1288+
# self.lv.translation(*tr0)
1289+
# self.lv.rotation(*rot0)
1290+
self.lv.camera(pos0)
1291+
self.lv.render()
1292+
1293+
for i in range(steps):
1294+
if stop and i > stop:
1295+
break
1296+
L = i / (steps - 1)
1297+
self.lerp(pos0, pos1, L)
1298+
self.lv.render()
1299+
1300+
def pause(self, frames=50):
1301+
# Render pause
1302+
for i in range(frames):
1303+
self.lv.render()
1304+
1305+
12511306
def sun_light(
12521307
time=None,
12531308
now=False,

0 commit comments

Comments
 (0)