@@ -1203,106 +1203,6 @@ def vector_align(v1, v2, lvformat=True):
12031203        return  qr 
12041204
12051205
1206- def  lookat (lv , pos , lookat = None , up = None ):
1207-     """ 
1208-     Set the camera with a position coord and lookat coord 
1209- 
1210-     Parameters 
1211-     ---------- 
1212-     lv : lavavu.Viewer 
1213-         The viewer object 
1214-     pos : list/numpy.ndarray 
1215-         Camera position in world coords 
1216-     lookat : list/numpy.ndarray 
1217-         Look at position in world coords, defaults to model origin 
1218-     up : list/numpy.ndarray 
1219-         Up vector, defaults to Y axis [0,1,0] 
1220-     """ 
1221- 
1222-     # Use the origin from viewer if no target provided 
1223-     if  lookat  is  None :
1224-         lookat  =  lv ["focus" ]
1225-     else :
1226-         lv ["focus" ] =  lookat 
1227- 
1228-     # Default to Y-axis up vector 
1229-     if  up  is  None :
1230-         up  =  np .array ([0 , 1 , 0 ])
1231- 
1232-     # Calculate the rotation matrix 
1233-     heading  =  np .array (pos ) -  np .array (lookat )
1234-     zd  =  normalise (heading )
1235-     xd  =  normalise (np .cross (up , zd ))
1236-     yd  =  normalise (np .cross (zd , xd ))
1237-     q  =  quat .from_rotation_matrix (np .array ([xd , yd , zd ]))
1238-     q  =  q .normalized ()
1239- 
1240-     # Apply the rotation 
1241-     lv .rotation (q .x , q .y , q .z , q .w )
1242- 
1243-     # Translate back by heading vector length in Z 
1244-     # (model origin in lavavu takes care of lookat offset) 
1245-     tr  =  [0 , 0 , - magnitude (np .array (pos ) -  np .array (lookat ))]
1246- 
1247-     # Apply translation 
1248-     lv .translation (tr )
1249- 
1250- 
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- 
13061206def  sun_light (
13071207    time = None ,
13081208    now = False ,
0 commit comments