コード例 #1
0
ファイル: WWTControl.cs プロジェクト: spamarti/wwt-web-client
 public double GetDistance(Vector2d a, Vector2d b)
 {
     double x;
     double y;
     x = a.X - b.X;
     y = a.Y - b.Y;
     return Math.Sqrt(x * x + y * y);
 }
コード例 #2
0
ファイル: WWTControl.cs プロジェクト: spamarti/wwt-web-client
        public Vector3d TransformPickPointToWorldSpace(Vector2d ptCursor, double backBufferWidth, double backBufferHeight)
        {
            Vector3d vPickRayOrig;
            Vector3d vPickRayDir;

            Vector3d v = new Vector3d();
            v.X = (((2.0f * ptCursor.X) / backBufferWidth) - 1) / (RenderContext.Projection.M11);// / (backBufferWidth / 2));
            v.Y = (((2.0f * ptCursor.Y) / backBufferHeight) - 1) / (RenderContext.Projection.M22);// / (backBufferHeight / 2));
            v.Z = 1.0f;

            Matrix3d m = Matrix3d.MultiplyMatrix(RenderContext.View, RenderContext.World);

            m.Invert();

            vPickRayDir = new Vector3d();
            vPickRayOrig = new Vector3d();
            // Transform the screen space pick ray into 3D space
            vPickRayDir.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31;
            vPickRayDir.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32;
            vPickRayDir.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33;

            vPickRayDir.Normalize();

            return vPickRayDir;
        }
コード例 #3
0
ファイル: WWTControl.cs プロジェクト: spamarti/wwt-web-client
 private bool AnnotationHover(double ra, double dec, double x, double y)
 {
     if (annotations != null && annotations.Count > 0)
     {
         int index = 0;
         foreach (Annotation note in annotations)
         {
             if (note.HitTest(RenderContext, ra, dec, x, y))
             {
                 hoverText = note.Label;
                 hoverTextPoint = Vector2d.Create(x, y);
                 return true;
             }
             index++;
         }
     }
     return false;
 }
コード例 #4
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
        public static Vector2d Average3d(Vector2d left, Vector2d right)
        {
            Vector3d pntLeft = Coordinates.GeoTo3dDouble(left.Y, left.X);
            Vector3d pntRight = Coordinates.GeoTo3dDouble(right.Y, right.X);

            Vector3d pntOut = Vector3d.AddVectors(pntLeft, pntRight);
            pntOut.Multiply(.5);
            pntOut.Normalize();

            return CartesianToSpherical2(pntOut);
        }
コード例 #5
0
ファイル: WWTControl.cs プロジェクト: spamarti/wwt-web-client
        public void PinchMove(TouchEvent ev)
        {
            TouchInfo t0 = ev.Touches[0];
            TouchInfo t1 = ev.Touches[1];
            Vector2d[] newRect = new Vector2d[2];

            newRect[0] = Vector2d.Create(t0.PageX, t0.PageY);
            newRect[1] = Vector2d.Create(t1.PageX, t1.PageY);
            if (rect[0] != null)
            {
                double oldDist = GetDistance(rect[0], rect[1]);
                double newDist = GetDistance(newRect[0], newRect[1]);
                double ratio = oldDist / newDist;
                Zoom(ratio);
            }
            rect = newRect;
            ev.StopPropagation();
            ev.PreventDefault();
        }
コード例 #6
0
        private static Vector2d GetMiterPoint(Vector2d p1, Vector2d p2, Vector2d p3, double edgeOffset)
        {
            Vector2d edge1 = Vector2d.SubtractVector(p2, p1);
            Vector2d edge2 = Vector2d.SubtractVector(p3, p1);
            edge1.Normalize();
            edge2.Normalize();
            Vector2d dir = Vector2d.Create(edge1.X + edge2.X, edge1.Y + edge2.Y);
            dir.Normalize();
            Vector2d delta = Vector2d.Create(edge1.X - edge2.X, edge1.Y - edge2.Y);
            double sineHalfAngle = delta.Length / 2;
            double net = Math.Min(2, edgeOffset / sineHalfAngle);

            dir.Extend(net);

            return Vector2d.Create(p1.X-dir.X,p1.Y-dir.Y);
        }
コード例 #7
0
ファイル: SkyText.cs プロジェクト: spamarti/wwt-web-client
        public static GlyphItem Create(string glyph, Rectangle uv, Vector2d size, Vector2d extents)
        {
            GlyphItem temp = new GlyphItem(glyph);
            temp.Glyph = glyph;
            temp.UVRect = uv;
            temp.Size = size;
            temp.Extents = extents;
            temp.ReferenceCount = 1;

            return temp;
        }
コード例 #8
0
ファイル: TourPlayer.cs プロジェクト: spamarti/wwt-web-client
 public bool Hover(Vector2d pnt)
 {
     if (playing)
     {
         return true;
     }
     return false;
 }
コード例 #9
0
ファイル: TourPlayer.cs プロジェクト: spamarti/wwt-web-client
        public Vector2d PointToView(Vector2d pnt)
        {
            double clientHeight = WWTControl.Singleton.Canvas.Height;
            double clientWidth = WWTControl.Singleton.Canvas.Width;
            double viewWidth = (clientWidth / clientHeight) * 1116f;
            double x = (((double)pnt.X) / ((double)clientWidth) * viewWidth) - ((viewWidth - 1920) / 2);
            double y = ((double)pnt.Y) / clientHeight * 1116;

            return Vector2d.Create(x, y);
        }
コード例 #10
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
 public static Vector2d SubtractVector(Vector2d left, Vector2d right)
 {
     return Vector2d.Create(left.X - right.X, left.Y - right.Y);
 }
コード例 #11
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
        public double Distance3d(Vector2d pointB)
        {
            Vector3d pnt1 = Coordinates.GeoTo3dDouble(pointB.Y, pointB.X);
            Vector3d pnt2 = Coordinates.GeoTo3dDouble(this.Y, this.X);

            Vector3d pntDiff = Vector3d.SubtractVectors(pnt1, pnt2);

            return pntDiff.Length() / Math.PI * 180;
        }
コード例 #12
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
 public static Vector2d Subtract(Vector2d vec)
 {
     return Vector2d.Create(-vec.X, -vec.Y);
 }
コード例 #13
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
 public static Vector2d Lerp(Vector2d left, Vector2d right, double interpolater)
 {
     //if (Math.Abs(left.X - right.X) > 12)
     //{
     //    if (left.X > right.X)
     //    {
     //        right.X += 24;
     //    }
     //    else
     //    {
     //        left.X += 24;
     //    }
     //}
     return Vector2d.Create(left.X * (1 - interpolater) + right.X * interpolater, left.Y * (1 - interpolater) + right.Y * interpolater);
 }
コード例 #14
0
ファイル: Double3D.cs プロジェクト: spamarti/wwt-web-client
        public static Vector2d Create(double x, double y)
        {
            Vector2d temp = new Vector2d();

            temp.X = x;
            temp.Y = y;
            return temp;
        }
コード例 #15
0
ファイル: Layer.cs プロジェクト: spamarti/wwt-web-client
 public virtual bool HoverCheckScreenSpace(Vector2d cursor)
 {
     return false;
 }
コード例 #16
0
ファイル: TourPlayer.cs プロジェクト: spamarti/wwt-web-client
        bool HitTextPlayerControls(Vector2d point, bool click, bool act)
        {
            if (click)
            {
                leftDown = false;
                rightDown = false;
                middleDown = false;
            }
            else
            {
                leftHover = false;
                rightHover = false;
                middleHover = false;

            }

            if (point.Y < (top - 2))
            {
                return false;
            }

            if (point.X < (center - 32) && point.X > (center - 105))
            {
                if (click)
                {

                    leftDown = true;
                }
                else
                {
                    leftHover = true;
                }
                if (act)
                {
                    PlayPreviousSlide();
                    lastHit = Date.Now;
                }
                return true;
            }

            if (point.X < (center + 105) && point.X > (center + 32))
            {
                if (click)
                {

                    rightDown = true;
                }
                else
                {
                    rightHover = true;
                }
                if (act)
                {
                    PlayNextSlide();
                    lastHit = Date.Now;
                }
                return true;
            }

            if (point.X < (center + 32) && point.X > (center - 32))
            {
                if (click)
                {

                    middleDown = true;
                }
                else
                {
                    middleHover = true;
                }
                if (act)
                {
                    PauseTour();
                    lastHit = Date.Now;
                }
                return true;
            }

            return false;
        }
コード例 #17
0
        private int GetItemIndexFromCursor(Vector2d testPointIn)
        {
            Vector2d testPoint = Vector2d.Create(testPointIn.X + Left, testPointIn.Y + Top);

            imageClicked = false;
            int index = -1;
            int xpos = (int)((float)testPoint.X / horzMultiple);
            int xPart = (int)((float)testPoint.X % horzMultiple);
            if (xpos >= colCount)
            {
                return -1;
            }
            if (xpos < 0)
            {
                return -1;
            }

            int ypos = (int)(testPoint.Y / VertSpacing);
            int yPart = (int)(testPoint.Y % VertSpacing);
            if (ypos >= rowCount)
            {
                return -1;
            }

            if (ypos < 0)
            {
                return -1;
            }

            index = startIndex + ypos * colCount + xpos;

            if (index == items.Count)
            {
                addButtonHover = true;
            }
            else
            {
                addButtonHover = false;
            }

            if (index > items.Count-1)
            {
                return -1;
            }

            if (((IThumbnail)items[index]).IsImage && yPart < 16 && xPart > 78)
            {
                imageClicked = true;
            }

            return index;
        }
コード例 #18
0
ファイル: Overlay.cs プロジェクト: spamarti/wwt-web-client
        public virtual bool HitTest(Vector2d pntTest)
        {
            //todo this needs to be translated to script#

            //Matrix3d mat = new Matrix3d();
            //mat.RotateAt(new Quaternion(new Vector3D(0,0,1), -RotationAngle), new Point3D(X , Y , 0 ));

            //Point3D tempPoint = new Point3D(pntTest.X, pntTest.Y, 0);

            //tempPoint  = mat.Transform(tempPoint);

            //Rect rect = new Rect((X-(Width/2)), (Y-(Height/2)), Width, Height);
            //if (rect.Contains(new Point(tempPoint.X,tempPoint.Y)))
            //{
            //    return true;
            //}
            return false;
        }
コード例 #19
0
ファイル: SkyText.cs プロジェクト: spamarti/wwt-web-client
 public GlyphItem(string glyph)
 {
     Glyph = glyph;
     UVRect = new Rectangle();
     Size = new Vector2d();
     ReferenceCount = 1;
 }
コード例 #20
0
ファイル: WWTControl.cs プロジェクト: spamarti/wwt-web-client
        public void OnMouseMove(ElementEvent e)
        {
            lastMouseMove = Date.Now;
            hoverTextPoint = Vector2d.Create( Mouse.OffsetX(Canvas, e), Mouse.OffsetY(Canvas, e));
            hoverText = "";

            if (mouseDown)
            {
                e.PreventDefault();
                e.StopPropagation();

                moved = true;
                if (e.CtrlKey)
                {
                    Tilt(Mouse.OffsetX(Canvas, e) - lastX, Mouse.OffsetY(Canvas, e) - lastY);
                }
                else
                {
                    Move(Mouse.OffsetX(Canvas, e) - lastX, Mouse.OffsetY(Canvas, e) - lastY);
                }

                lastX = Mouse.OffsetX(Canvas, e);
                lastY = Mouse.OffsetY(Canvas, e);
            }
            else
            {
                if (uiController != null)
                {
                    if (uiController.MouseMove(this, e))
                    {
                        e.PreventDefault();
                        e.StopPropagation();
                        return;
                    }
                }
            }
        }
コード例 #21
0
ファイル: SkyText.cs プロジェクト: spamarti/wwt-web-client
        public void AddGlyphPoints(List<PositionTexture> pointList, Vector2d size, Rectangle position, Rectangle uv)
        {
            PositionTexture[] points = new PositionTexture[6];

            for(int i=0; i<6;i++)
            {
                points[i] = new PositionTexture();
            }

            Vector3d left = Vector3d.Cross(center, up);
            Vector3d right = Vector3d.Cross(up, center);

            left.Normalize();
            right.Normalize();
            up.Normalize();

            Vector3d upTan = Vector3d.Cross(center, right);

            upTan.Normalize();

            if (alignment == Alignment.Center)
            {
                left.Multiply(width - position.Left * 2);
                right.Multiply(width - ((width * 2) - position.Right * 2));
            }
            else if (alignment == Alignment.Left)
            {
                left.Multiply(-position.Left * 2);
                right.Multiply(position.Right * 2);
            }

            Vector3d top = upTan.Copy();
            Vector3d bottom = Vector3d.SubtractVectors(Vector3d.Empty,upTan);

            top.Multiply(height - position.Top * 2);
            bottom.Multiply(height - ((height * 2) - position.Bottom * 2));
            Vector3d ul = center.Copy();
            ul.Add(top);
            if (sky)
            {
                ul.Add(left);
            }
            else
            {
                ul.Subtract(left);
            }
            Vector3d ur = center.Copy();
            ur.Add(top);
            if (sky)
            {
                ur.Add(right);
            }
            else
            {
                ur.Subtract(right);
            }
            Vector3d ll = center.Copy();
            if (sky)
            {
                ll.Add(left);
            }
            else
            {
                ll.Subtract(left);
            }

            ll.Add(bottom);

            Vector3d lr = center.Copy();
            if (sky)
            {
                lr.Add(right);
            }
            else
            {
                lr.Subtract(right);
            }
            lr.Add(bottom);

            points[0].Position = ul.Copy();
            points[0].Tu = uv.Left;
            points[0].Tv = uv.Top;
               //     points[0].Color = Color;

            points[2].Tu = uv.Left;
            points[2].Tv = uv.Bottom;
            points[2].Position = ll.Copy();
              //      points[2].Color = Color;

            points[1].Tu = uv.Right;
            points[1].Tv = uv.Top;
            points[1].Position = ur.Copy();
              //      points[1].Color = Color;

            points[3].Tu = uv.Right;
            points[3].Tv = uv.Bottom;
            points[3].Position = lr.Copy();
              //      points[3].Color = Color;

            points[5].Tu = uv.Right;
            points[5].Tv = uv.Top;
            points[5].Position = ur.Copy();
               //     points[5].Color = Color;

            points[4].Tu = uv.Left;
            points[4].Tv = uv.Bottom;
            points[4].Position = ll.Copy();
               //     points[4].Color = Color;

            if (Rotation != 0 || Tilt != 0 || Bank != 0)
            {
                if (!matInit)
                {
                    Matrix3d lookAt = Matrix3d.LookAtLH(center, new Vector3d(), up);
                    Matrix3d lookAtInv = lookAt.Clone();
                    lookAtInv.Invert();

                    rtbMat =  Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix( Matrix3d.MultiplyMatrix(lookAt, Matrix3d.RotationZ(-Rotation / 180 * Math.PI)),  Matrix3d.RotationX(-Tilt / 180 * Math.PI)),  Matrix3d.RotationY(-Bank / 180 * Math.PI)), lookAtInv);
                    //todo make this true after debug
                    matInit = true;
                }
                for (int i = 0; i < 6; i++)
                {
                    points[i].Position = Vector3d.TransformCoordinate(points[i].Position, rtbMat);
                }
            }

            pointList.AddRange(points);
        }
コード例 #22
0
        private static void MiterPointOut(Vector2d pntOut, double p1x, double p1y, double p2x, double p2y, double p3x, double p3y, double ExpansionInPixels)
        {
            //Vector2d edge1 = Vector2d.SubtractVector(p2, p1);
            double e1x = p2x - p1x;
            double e1y = p2y - p1y;

            //Vector2d edge2 = Vector2d.SubtractVector(p3, p1);
            double e2x = p3x - p1x;
            double e2y = p3y - p1y;

            //edge1.Normalize();
            double length = Math.Sqrt(e1x * e1x + e1y * e1y);
            if (length != 0)
            {
                e1x /= length;
                e1y /= length;
            }

            //edge2.Normalize();
            length = Math.Sqrt(e2x * e2x + e2y * e2y);
            if (length != 0)
            {
                e2x /= length;
                e2y /= length;
            }
            //Vector2d dir = Vector2d.Create(edge1.X + edge2.X, edge1.Y + edge2.Y);
            double dx = e1x + e2x;
            double dy = e1y + e2y;

            //dir.Normalize();
            length = Math.Sqrt(dx * dx + dy * dy);
            if (length != 0)
            {
                dx /= length;
                dy /= length;
            }

            //Vector2d delta = Vector2d.Create(edge1.X - edge2.X, edge1.Y - edge2.Y);
            double deltax = e1x - e2x;
            double deltay = e1y - e2y;

            //double sineHalfAngle = delta.Length / 2;
            length = Math.Sqrt(deltax * deltax + deltay * deltay);
            double sineHalfAngle = length / 2.0;

            double net = Math.Min(2, ExpansionInPixels / sineHalfAngle);

            //dir.Extend(net);
            dx *= net;
            dy *= net;

            //return Vector2d.Create(p1.X-dir.X,p1.Y-dir.Y);
            pntOut.X = p1x - dx;
            pntOut.Y = p1y - dy;
        }