private ICollection <BSPImage> PreparePhotos(IEnumerable <string> urls) { var items = new List <BSPImage>(); var count = urls.Count(); var size = (int)Math.Ceiling(Math.Pow(count, 1.0 / 3)); // TODO: Properly split BSP items in tree if they cross planes; then don't need to force even-valued sizez if ((size & 1) == 1) { ++size; } var offset = -(((double)size - 1) / 2); var origin = new Vector3D(offset, offset, offset); pending = 0; var positions = new Dictionary <string, string>(); var rand = new Random(); foreach (var url in urls) { Point3D point; string key; do { point = new Point3D( rand.Next(size), rand.Next(size), rand.Next(size)); key = point.X + "," + point.Y + "," + point.Z; }while (positions.ContainsKey(key)); positions[key] = url; var image = new BSPImage(point + origin, new Uri(url)); image.Loaded += delegate { if (Interlocked.Decrement(ref pending) < 1) { loading.Stop(); } }; image.Failed += delegate { if (Interlocked.Decrement(ref pending) < 1) { loading.Stop(); } }; image.Click += ItemClick; image.WebClick += ItemWebClick; items.Add(image); } pending = items.Count; return(items); }
private void SelectItem(BSPImage image) { if (selected == image) { image.Selected = false; image.RefreshState(); selected = null; to = from; fromZ = camera.Position.Z; toZ = -10; slerp = 1; jumpAngle = 0; } else { if (selected != null) { var oldImage = (BSPImage)selected; oldImage.Selected = false; oldImage.RefreshState(); } image.Selected = true; image.Visited = true; image.RefreshState(); selected = image; Point3D center = image.Position; Vector3D dir = (Vector3D)center; dir.Normalize(); Point3D viewpoint = center + (dir * image.ViewDistance); var axis = Vector3D.CrossProduct((Vector3D)camera.Position, (Vector3D)viewpoint); var angle = Vector3D.AngleBetween((Vector3D)camera.Position, (Vector3D)viewpoint); to = (axis != new Vector3D()) ? new Quaternion(axis, angle) : new Quaternion(new Vector3D(0, 1, 0), angle); to.Normalize(); toZ = -((Vector3D)viewpoint).Length; slerp = 1; jumpAngle = Vector3D.AngleBetween( (Vector3D)camera.GetRotationMatrix().Transform(camera.Position), (Vector3D)viewpoint); } }
private void SelectItem( BSPImage image ) { if ( selected == image ) { image.Selected = false; image.RefreshState(); selected = null; to = from; fromZ = camera.Position.Z; toZ = -10; slerp = 1; jumpAngle = 0; } else { if ( selected != null ) { var oldImage = (BSPImage)selected; oldImage.Selected = false; oldImage.RefreshState(); } image.Selected = true; image.Visited = true; image.RefreshState(); selected = image; Point3D center = image.Position; Vector3D dir = (Vector3D)center; dir.Normalize(); Point3D viewpoint = center + ( dir * image.ViewDistance ); var axis = Vector3D.CrossProduct( (Vector3D)camera.Position, (Vector3D)viewpoint ); var angle = Vector3D.AngleBetween( (Vector3D)camera.Position, (Vector3D)viewpoint ); to = ( axis != new Vector3D() ) ? new Quaternion( axis, angle ) : new Quaternion( new Vector3D( 0, 1, 0 ), angle ); to.Normalize(); toZ = -( (Vector3D)viewpoint ).Length; slerp = 1; jumpAngle = Vector3D.AngleBetween( (Vector3D)camera.GetRotationMatrix().Transform( camera.Position ), (Vector3D)viewpoint ); } }
private ICollection<BSPImage> PreparePhotos( IEnumerable<string> urls ) { var items = new List<BSPImage>(); var count = urls.Count(); var size = (int)Math.Ceiling( Math.Pow( count, 1.0 / 3 ) ); // TODO: Properly split BSP items in tree if they cross planes; then don't need to force even-valued sizez if ( ( size & 1 ) == 1 ) ++size; var offset = -( ( (double)size - 1 ) / 2 ); var origin = new Vector3D( offset, offset, offset ); pending = 0; var positions = new Dictionary<string, string>(); var rand = new Random(); foreach ( var url in urls ) { Point3D point; string key; do { point = new Point3D( rand.Next( size ), rand.Next( size ), rand.Next( size ) ); key = point.X + "," + point.Y + "," + point.Z; } while ( positions.ContainsKey( key ) ); positions[ key ] = url; var image = new BSPImage( point + origin, new Uri( url ) ); image.Loaded += delegate { if ( Interlocked.Decrement( ref pending ) < 1 ) loading.Stop(); }; image.Failed += delegate { if ( Interlocked.Decrement( ref pending ) < 1 ) loading.Stop(); }; image.Click += ItemClick; image.WebClick += ItemWebClick; items.Add( image ); } pending = items.Count; return items; }