コード例 #1
0
 public void Save()
 {
     if (gl != null)
     {
     }
     else
     {
         Device.Save();
     }
 }
コード例 #2
0
ファイル: FishTank.cs プロジェクト: puslmbps/dsharp
        private void Draw()
        {
            if (_width < FishTank.BackgroundImageWidth)
            {
                // Show just a portion of the background image, since the window is
                // smaller than the background
                _tankCanvasContext.DrawImage(_backgroundImageElement, 0, 0, FishTank.BackgroundImageWidth, _height);
            }
            else
            {
                // Tile the background image horizontally if the window is wider than
                // the background

                int    tileCount = (int)(_width / FishTank.BackgroundImageWidth);
                double flip      = 1;

                for (int i = 0; i <= tileCount; i++)
                {
                    _tankCanvasContext.Save();
                    _tankCanvasContext.Transform(flip, 0, 0, 1, 0, 0);
                    _tankCanvasContext.DrawImage(_backgroundImageElement,
                                                 (flip - 1) * FishTank.BackgroundImageWidth / 2 + flip * FishTank.BackgroundImageWidth * i,
                                                 0, FishTank.BackgroundImageWidth, _height);
                    _tankCanvasContext.Restore();
                    flip = -flip;
                }
            }
        }
コード例 #3
0
        public void Draw(RenderContext renderContext, float opacity, Color color)
        {
            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);

                double drawHeight = (Height / renderContext.FovAngle) * renderContext.Height / 180;

                foreach (Text3d t3d in Items)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(t3d.center);
                    if (screenSpacePnt.Z < 0)
                    {
                        continue;
                    }

                    if (Vector3d.Dot((Vector3d)viewPoint, (Vector3d)t3d.center) < .55)
                    {
                        continue;
                    }

                    Vector3d screenSpaceTop = renderContext.WVP.Transform(t3d.top);

                    double rotation = Math.Atan2(screenSpacePnt.X - screenSpaceTop.X, screenSpacePnt.Y - screenSpaceTop.Y);


                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();

                    ctx.Translate(screenSpacePnt.X, screenSpacePnt.Y);
                    ctx.Rotate(-rotation); // todo update with up vector
                    ctx.Alpha        = opacity;
                    ctx.FillStyle    = color.ToString();
                    ctx.Font         = "normal" + " " + (false ? "bold" : "normal") + " " + Math.Round(drawHeight * 1.2).ToString() + "px " + "Arial";
                    ctx.TextBaseline = TextBaseline.Top;

                    TextMetrics tm = ctx.MeasureText(t3d.Text);

                    ctx.FillText(t3d.Text, -tm.Width / 2, -drawHeight / 2);
                    ctx.Restore();
                }
            }
            else
            {
                // gl version
                if (glyphCache == null || glyphCache.Version > glyphVersion)
                {
                    PrepareBatch();
                }
                if (glyphCache.Ready == false)
                {
                    return;
                }


                TextShader.Use(renderContext, vertexBuffer.VertexBuffer, glyphCache.Texture.Texture2d);

                renderContext.gl.drawArrays(GL.TRIANGLES, 0, vertexBuffer.Count);
            }
        }
コード例 #4
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #5
0
        public void DrawLines(RenderContext renderContext, float opacity, Color color)
        {
            if (linePoints.Count < 2)
            {
                return;
            }

            InitLineBuffer(renderContext);

            int count = linePoints.Count;

            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);



                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();

                ctx.StrokeStyle = color.ToString();
                ctx.LineWidth   = 2;
                ctx.Alpha       = .25;
                Vector3d firstPoint  = new Vector3d();
                Vector3d secondPoint = new Vector3d();
                for (int i = 0; i < count; i += 2)
                {
                    firstPoint  = renderContext.WVP.Transform(linePoints[i]);
                    secondPoint = renderContext.WVP.Transform(linePoints[i + 1]);
                    if (Vector3d.Dot(linePoints[i], viewPoint) > .60)
                    {
                        ctx.BeginPath();
                        ctx.MoveTo(firstPoint.X, firstPoint.Y);
                        ctx.LineTo(secondPoint.X, secondPoint.Y);


                        ctx.Stroke();
                    }
                }
                ctx.Restore();
            }
            else
            {
                foreach (PositionVertexBuffer lineBuffer in lineBuffers)
                {
                    if (Pure2D)
                    {
                        SimpleLineShader2D.Use(renderContext, lineBuffer.VertexBuffer, color, zBuffer);
                    }
                    else
                    {
                        SimpleLineShader.Use(renderContext, lineBuffer.VertexBuffer, color, zBuffer);
                    }
                    renderContext.gl.drawArrays(GL.LINES, 0, lineBuffer.Count);
                }
            }
        }
コード例 #6
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateCircleGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Scale(1, Width / Height);
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();
            ctx.Alpha     = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #7
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateStarGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();

            double centerX = 0;
            double centerY = 0;
            double radius  = Width / 2;

            double radiansPerSegment = ((double)Math.PI * 2) / 5;

            bool first = true;

            for (int i = 0; i < 5; i++)
            {
                double rads = i * radiansPerSegment - (Math.PI / 2);
                if (first)
                {
                    first = false;
                    ctx.MoveTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }
                else
                {
                    ctx.LineTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }

                double rads2 = i * radiansPerSegment + (radiansPerSegment / 2) - (Math.PI / 2);
                ctx.LineTo(centerX + Math.Cos(rads2) * (Width / 5.3), centerY + Math.Sin(rads2) * (Height / 5.3));
            }

            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();


            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #8
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateDonutGeometry(RenderContext renderContext)
        {
            //todo move to dashed lines in future
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Scale(1, Height / Width);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width / 2, 0, Math.PI * 2, false);

            ctx.ClosePath();
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
コード例 #9
0
        public override void Draw(RenderContext renderContext)
        {
            double rad = radius;

            if (skyRelative)
            {
                rad /= renderContext.FovScale / 3600;
            }
            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);

            if (screenSpacePnt.Z < 0)
            {
                return;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55)
            {
                return;
            }
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;
                ctx.BeginPath();
                ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                ctx.LineWidth = strokeWidth;
                ctx.FillStyle = fillColor.ToString();
                if (fill)
                {
                    ctx.Fill();
                }
                ctx.Alpha       = 1.0;
                ctx.StrokeStyle = lineColor.ToString();
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #10
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateLineGeometry(RenderContext renderContext)
        {
            //todo this needs to be Dashed rounded lines..

            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            double radius = Width / 2;

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.MoveTo(-radius, 0);
            ctx.LineTo(radius, 0);
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
コード例 #11
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        public override void Draw3D(RenderContext renderContext, bool designTime)
        {
            if (texture == null)
            {
                InitializeTexture();
            }

            if (!textureReady)
            {
                return;
            }
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.Alpha = Opacity;
            ctx.DrawImage(texture, -Width / 2, -Height / 2, Width, Height);
            ctx.Restore();
        }
コード例 #12
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateRectGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.BeginPath();
            ctx.MoveTo(-Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, +Height / 2);
            ctx.LineTo(-Width / 2, +Height / 2);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();

            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #13
0
        void DrawPlayerControls(RenderContext renderContext)
        {
            LoadImages();

            if (!imagesLoaded)
            {
                return;
            }

            if (PlayerState.State)
            {
                int span = Date.Now - lastHit;

                if (span > 7000)
                {
                    PlayerState.TargetState = false;
                }


                CanvasContext2D ctx = renderContext.Device;

                ctx.Save();
                ctx.Alpha = PlayerState.Opacity;
                top       = renderContext.Height - 60;
                center    = renderContext.Width / 2;

                ImageElement left   = leftDown ? buttonPreviousPressed : (leftHover ? buttonPreviousHover : buttonPreviousNormal);
                ImageElement middle = Playing ? (middleDown ? buttonPausePressed : (middleHover ? buttonPauseHover : buttonPauseNormal)) :
                                      (middleDown ? buttonPlayPressed : (middleHover ? buttonPlayHover : buttonPlayNormal));
                ImageElement right = rightDown ? buttonNextPressed : (rightHover ? buttonNextHover : buttonNextNormal);

                ctx.DrawImage(left, center - 110, top);
                ctx.DrawImage(right, center, top);
                ctx.DrawImage(middle, center - 32, top - 4);

                ctx.Restore();
            }
        }
コード例 #14
0
        public override void Update(CanvasContext2D context)
        {
            context.Save();
            context.BeginPath();
            context.Rect(0, 0, 800, 320);
            context.ClosePath();
            context.Clip();

            float speed = -(_level.Curve * _level.Speed * 50);

            if (_level.Left && _level.Speed > 0)
            {
                speed += 1;
            }
            if (_level.Right && _level.Speed > 0)
            {
                speed -= 1;
            }

            UpdateExplosions(context, speed);

            UpdateFlak(context, speed);

            foreach (Cloud cloud in _clouds)
            {
                float scale = (400 - cloud.Y) / 400;

                cloud.X = (cloud.X - (0.3f - speed) * scale + 2400) % 2400;

                context.DrawImage(
                    _cloudImage,
                    cloud.X - 1200,
                    cloud.Y - (_cloudImage.NaturalHeight / 2) * scale,
                    _cloudImage.NaturalWidth * scale,
                    _cloudImage.NaturalHeight * scale);
            }
            context.Restore();
        }
コード例 #15
0
        public void Update()
        {
            // Calculate next position of fish
            double fps = FishTank.FramesPerSecond;

            _velocity = Math.Max(Math.Floor(fps * fps * .5 / 3), 1);

            double nextX     = _x + _xAngle * _velocity * FishTank.TimeDelta;
            double nextY     = _y + _yAngle * _velocity * FishTank.TimeDelta;
            double nextZ     = _z + _zAngle * .1 * _velocity * FishTank.TimeDelta;
            double nextScale = Math.Abs(nextZ) / (FishTank.ZFar - FishTank.ZNear);

            // If fish is going to move off right side of screen
            if (nextX + FishTank.FishWidth / 2 * _scale > _tank.Width)
            {
                // If angle is between 3 o'clock and 6 o'clock
                if ((_angle >= 0 && _angle < Math.PI / 2))
                {
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI / 2 * 3)
                {
                    // If angle is between 12 o'clock and 3 o'clock
                    _angle  = _angle - (_angle - Math.PI / 2 * 3) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off left side of screen
            if (nextX - FishTank.FishWidth / 2 * _scale < 0)
            {
                if ((_angle > Math.PI / 2 && _angle < Math.PI))
                {
                    // If angle is between 6 o'clock and 9 o'clock
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI && _angle < Math.PI / 2 * 3)
                {
                    // If angle is between 9 o'clock and 12 o'clock
                    _angle  = _angle + (Math.PI / 2 * 3 - _angle) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off bottom side of screen
            if (nextY + FishTank.FishHeight / 2 * _scale > _tank.Height)
            {
                // If angle is between 3 o'clock and 9 o'clock
                if ((_angle > 0 && _angle < Math.PI))
                {
                    _angle  = Math.PI * 2 - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                }
            }

            // If fish is going to move off top side of screen
            if (nextY - FishTank.FishHeight / 2 * _scale < 0)
            {
                // If angle is between 9 o'clock and 3 o'clock
                if ((_angle > Math.PI && _angle < Math.PI * 2))
                {
                    _angle  = _angle - (_angle - Math.PI) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle);
                }
            }

            // If fish is going too far (getting too small)
            if (nextZ <= FishTank.ZNear && _zAngle < 0)
            {
                _zAngle = -_zAngle;
            }

            // If fish is getting to close (getting too large)
            if (((_tank.Width / FishTank.FishWidth) * 10) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .3;
            }
            else if (((_tank.Width / FishTank.FishWidth) * 2) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .5;
            }
            else
            {
                _zFactor = 1;
            }

            if (nextZ >= FishTank.ZFar * _zFactor && _zAngle > 0)
            {
                _zAngle = -_zAngle;
            }

            if (_scale < .1)
            {
                // Don't let fish get too tiny
                _scale = .1;
            }

            // Draw the fish
            _context.Save();

            // Move the fish to where it is within the fish tank
            _context.Translate(_x, _y);

            // Make the fish bigger or smaller depending on how far away it is.
            _context.Scale(_scale, _scale);

            // Make the fish face the way it is swimming.
            _context.Transform(_flip, 0, 0, 1, 0, 0);

            _context.DrawImage(_fishStrip,
                               FishTank.FishWidth * _cellIndex, FishTank.FishHeight * _species,
                               FishTank.FishWidth, FishTank.FishHeight,
                               -FishTank.FishWidth / 2, -FishTank.FishHeight / 2,
                               FishTank.FishWidth, FishTank.FishHeight);
            _context.Restore();

            // Increment to next state
            _x     = nextX;
            _y     = nextY;
            _z     = nextZ;
            _scale = nextScale;

            if ((_cellIndex >= FishTank.CellsInFishStrip - 1) || (_cellIndex <= 0))
            {
                // Go through each cell in the animation
                _cellReverse = -_cellReverse;
            }

            // Go back down once we hit the end of the animation
            _cellIndex = _cellIndex + _cellReverse;
        }
コード例 #16
0
        //protected Vector3d RaDecTo3d(double lat, double lng)
        //{
        //    return Vector3d.Create((Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius), (Math.Sin(lat * RC) * radius), (Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius));

        //}
        private void DrawSingleConstellationOld(RenderContext renderContext, Lineset ls)
        {
            bool reverse = false;
            // todo get this working
            Place centroid = ConstellationCentroids[ls.Name];

            if (centroid != null)
            {
                Vector3d pos = Coordinates.RADecTo3d(reverse ? -centroid.RA - 6 : centroid.RA, reverse ? centroid.Dec : centroid.Dec);

                if (Vector3d.Dot(renderContext.ViewPoint, pos) < maxSeperation)
                {
                    return;
                }
            }

            drawCount++;
            string col;

            if (boundry)
            {
                if (constToDraw != ls.Name)
                {
                    col = Settings.GlobalSettings.ConstellationBoundryColor;
                }
                else
                {
                    col = Settings.GlobalSettings.ConstellationSelectionColor;
                }
            }
            else
            {
                col = Settings.GlobalSettings.ConstellationFigureColor;
            }

            if (renderContext.gl == null)
            {
                CanvasContext2D ctx = renderContext.Device;

                int count = ls.Points.Count;

                Vector3d lastPoint = new Vector3d();
                ctx.Save();
                bool linePending = false;
                ctx.BeginPath();
                ctx.StrokeStyle = col;
                ctx.LineWidth   = 2;
                ctx.Alpha       = .25;
                for (int i = 0; i < count; i++)
                {
                    if (ls.Points[i].PointType == PointType.Move || i == 0)
                    {
                        if (linePending)
                        {
                            ctx.Stroke();
                        }
                        lastPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        ctx.MoveTo(lastPoint.X, lastPoint.Y);
                    }
                    else
                    {
                        Vector3d newPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        //            if (lastPoint.Z > 0 && newPoint.Z > 0)
                        {
                            ctx.LineTo(newPoint.X, newPoint.Y);
                            linePending = true;
                        }
                    }
                }

                if (boundry)
                {
                    ctx.ClosePath();
                }

                ctx.Stroke();
                ctx.Restore();
            }
            else
            {
                //todo add webgl method of drawing
            }
        }
コード例 #17
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        //public static TextOverlay(Canvas canvas, TextObject textObject)
        //{
        //    this.canvas = canvas;
        //    this.TextObject = textObject;
        //    this.Name = textObject.Text.Split(new char[] { '\r', '\n' })[0];
        //    X = 0;
        //    Y = 0;

        //}


        public override void Draw3D(RenderContext renderContext, bool designTime)
        {
            //TextBlock textBlock = new TextBlock();
            //textBlock.Width = this.Width;
            //textBlock.Height = this.Height;
            //textBlock.Foreground = new SolidColorBrush(TextObject.ForgroundColor);
            //textBlock.Text = TextObject.Text;
            //textBlock.FontWeight = TextObject.Bold ? FontWeights.Bold : FontWeights.Normal;
            //textBlock.FontSize = TextObject.FontSize * 1.2;
            //textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            //TranslateTransform tt = new TranslateTransform();
            //tt.X = this.X - (Width / 2);
            //tt.Y = this.Y - (Height / 2);
            //textBlock.RenderTransform = tt;
            //canvas.Children.Add(textBlock);
            //textBlock.Opacity = this.Opacity;

            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.Alpha        = Opacity;
            ctx.FillStyle    = TextObject.ForgroundColor.ToString();
            ctx.Font         = (TextObject.Italic ? "italic" : "normal") + " " + (TextObject.Bold ? "bold" : "normal") + " " + Math.Round(TextObject.FontSize * 1.2).ToString() + "px " + TextObject.FontName;
            ctx.TextBaseline = TextBaseline.Top;

            String text = TextObject.Text;

            if (text.IndexOf("{$") > -1)
            {
                if (text.IndexOf("{$DATE}") > -1)
                {
                    string date = String.Format("{0:yyyy/MM/dd}", SpaceTimeController.Now);
                    text = text.Replace("{$DATE}", date);
                }

                if (text.IndexOf("{$TIME}") > -1)
                {
                    string time = String.Format("{0:HH:mm:ss}", SpaceTimeController.Now);
                    text = text.Replace("{$TIME}", time);
                }


                //  text = text.Replace("{$DIST}", UiTools.FormatDistance(WWTControl.Singleton.SolarSystemCameraDistance));
                text = text.Replace("{$LAT}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat));
                text = text.Replace("{$LNG}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Lat));
                text = text.Replace("{$RA}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.RA));
                text = text.Replace("{$DEC}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.ViewCamera.Dec));
                text = text.Replace("{$FOV}", Coordinates.FormatDMS(WWTControl.Singleton.RenderContext.FovAngle));
            }



            string[] lines = text.Split("\n");

            double baseline  = -(Height / 2);
            double lineSpace = TextObject.FontSize * 1.7;

            foreach (string line in lines)
            {
                List <string> parts = Util.GetWrappedText(ctx, line, Width);
                foreach (string part in parts)
                {
                    ctx.FillText(part, -Width / 2, baseline);
                    baseline += lineSpace;
                }
            }

            ctx.Restore();
        }
コード例 #18
0
        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                    }

                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();
                        return;
                    }
                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }
                    if (first)
                    {
                        first = false;
                        ctx.BeginPath();
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }

                ctx.LineWidth = strokeWidth;

                ctx.StrokeStyle = lineColor.ToString();

                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #19
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0 && points.Count > 1)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #20
0
        public override void Draw(RenderContext renderContext)
        {
            bool   onScreen = true;
            double rad      = radius;

            if (skyRelative)
            {
                rad /= renderContext.FovScale / 3600;
            }
            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);

            if (screenSpacePnt.Z < 0)
            {
                onScreen = false;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, center) < .55)
            {
                onScreen = false;
            }

            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    Vector3d up = Vector3d.Create(0, 1, 0);

                    Vector3d xNormal = Vector3d.Cross(center, up);

                    Vector3d yNormal = Vector3d.Cross(center, xNormal);

                    double r = radius / 44;

                    int segments = 72;

                    double          radiansPerSegment = Math.PI * 2 / segments;
                    List <Vector3d> vertexList        = new List <Vector3d>();

                    for (int j = 0; j <= segments; j++)
                    {
                        double x = Math.Cos(j * radiansPerSegment) * r;
                        double y = Math.Sin(j * radiansPerSegment) * r;

                        vertexList.Add(Vector3d.Create(center.X + x * xNormal.X + y * yNormal.X, center.Y + x * xNormal.Y + y * yNormal.Y, center.Z + x * xNormal.Z + y * yNormal.Z));
                    }

                    if (strokeWidth > 0 && vertexList.Count > 1)
                    {
                        for (int i = 0; i < (vertexList.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[vertexList.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                if (onScreen)
                {
                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();
                    ctx.Alpha = Opacity;
                    ctx.BeginPath();
                    ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                    ctx.LineWidth = strokeWidth;
                    ctx.FillStyle = fillColor.ToString();
                    if (fill)
                    {
                        ctx.Fill();
                    }
                    ctx.Alpha       = 1.0;
                    ctx.StrokeStyle = lineColor.ToString();
                    ctx.Stroke();

                    ctx.Restore();
                }
            }
        }
コード例 #21
0
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2))
            {
                return(false);
            }

            //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels);

            //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2);
            //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2);
            //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0);
            MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            if (RenderingOn)
            {
                ctx.BeginPath();
                ctx.MoveTo(x0, y0);
                ctx.LineTo(x1, y1);
                ctx.LineTo(x2, y2);
                ctx.ClosePath();
                ctx.Clip();
            }
            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            //if (denom == 0)
            //{
            //    ctx.Restore();
            //    return false;
            //}
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            if (RenderingOn)
            {
                ctx.Alpha = Opacity;

                if (lighting < 1.0)
                {
                    ctx.Alpha     = 1;
                    ctx.FillStyle = "Black";
                    ctx.FillRect(0, 0, Width, Height);
                    ctx.Alpha = lighting * Opacity;
                }

                ctx.DrawImage(im, 0, 0);
            }



            ctx.Restore();
            return(true);
        }
コード例 #22
0
ファイル: RaceLevel.cs プロジェクト: Ventajou/Space-Dinosaurs
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0)
                    {
                        TimeLeft = 0;
                    }
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0)
                    {
                        context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    }
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth   = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            bool inside;

            if (factor == 1.0)
            {
                inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2);
            }
            else
            {
                hw     = Width / 2;
                qw     = hw * factor;
                hh     = Height / 2;
                qh     = hh * factor;
                inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2);
            }

            if (!inside)
            {
                return(false);
            }

            double   edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            ctx.BeginPath();
            ctx.MoveTo(x0, y0);
            ctx.LineTo(x1, y1);
            ctx.LineTo(x2, y2);
            ctx.ClosePath();
            ctx.Clip();

            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;

            if (denom == 0)
            {
                ctx.Restore();
                return(false);
            }
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            ctx.DrawImage(im, 0, 0);

            ctx.Restore();

            if (factor != 1.0)
            {
                ctx.BeginPath();
                ctx.MoveTo(hw - qw, hh - qh);
                ctx.LineTo(hw + qw, hh - qh);
                ctx.LineTo(hw + qw, hh + qh);
                ctx.LineTo(hw - qw, hh + qh);
                ctx.ClosePath();
                ctx.StrokeStyle = "yellow";
                ctx.Stroke();
            }

            return(true);
        }